|
@@ -0,0 +1,436 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller\diagnosis;
|
|
|
+
|
|
|
+use app\admin\model\diagnosis\DiagnosisApply;
|
|
|
+use app\admin\model\diagnosis\DiagnosisCate;
|
|
|
+use app\admin\model\diagnosis\DiagnosisOrder;
|
|
|
+use app\admin\model\diagnosis\DiagnosisService;
|
|
|
+use app\models\user\UserBill;
|
|
|
+use crmeb\basic\BaseModel;
|
|
|
+use crmeb\repositories\OrderRepository;
|
|
|
+use app\admin\model\system\{
|
|
|
+ SystemAttachment, ShippingTemplates
|
|
|
+};
|
|
|
+use app\admin\model\user\User;
|
|
|
+use app\Request;
|
|
|
+use crmeb\services\{
|
|
|
+ CacheService,
|
|
|
+ ExpressService,
|
|
|
+ SystemConfigService,
|
|
|
+ UtilService
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+ * 订单
|
|
|
+ * Class StoreOrderController
|
|
|
+ * @package app\api\controller\order
|
|
|
+ */
|
|
|
+class DiagnosisOrderController
|
|
|
+{
|
|
|
+
|
|
|
+
|
|
|
+ * 计算订单
|
|
|
+ * @param Request $request
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function confirm(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['cate', []],
|
|
|
+ ['service_id', []],
|
|
|
+ ['type'],
|
|
|
+ ['time'],
|
|
|
+ ['name'],
|
|
|
+ ['sex'],
|
|
|
+ ['age'],
|
|
|
+ ['phone'],
|
|
|
+ ['hospital'],
|
|
|
+ ['urgent_phone'],
|
|
|
+ ['transfer_address'],
|
|
|
+ ['remarks'],
|
|
|
+ ]);
|
|
|
+ $price = 0;
|
|
|
+ $commission = 0;
|
|
|
+ foreach ($data['cate'] as $item){
|
|
|
+ $cate = DiagnosisCate::where('id', $item)->find();
|
|
|
+ $price += $cate['price'];
|
|
|
+ $commission += $cate['reward'];
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($data['service_id']){
|
|
|
+ foreach ($data['service_id'] as $item){
|
|
|
+ $cate = DiagnosisService::where('id', $item)->find();
|
|
|
+ $price += $cate['price'];
|
|
|
+ $commission += $cate['reward'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $order['cate_id'] = implode(',', $data['cate']);
|
|
|
+ $order['ot_price'] = $price;
|
|
|
+ $order['pay_price'] = $price;
|
|
|
+ $order['commission'] = $commission;
|
|
|
+ $order['type'] = $data['type'];
|
|
|
+ if (strtotime($data['time']) < time()){
|
|
|
+ return app('json')->fail('选择正确的时间');
|
|
|
+ }
|
|
|
+ $order['attr'] = [
|
|
|
+ 'uid' => $request->uid(),
|
|
|
+ 'time' => strtotime($data['time']),
|
|
|
+ 'service_id' => implode(',', $data['service_id']),
|
|
|
+ 'name' => $data['name'],
|
|
|
+ 'sex' => $data['sex'],
|
|
|
+ 'age' => $data['age'],
|
|
|
+ 'phone' => $data['phone'],
|
|
|
+ 'hospital' => $data['hospital'],
|
|
|
+ 'urgent_phone' => $data['urgent_phone'],
|
|
|
+ 'transfer_address' => $data['transfer_address'],
|
|
|
+ 'remarks' => $data['remarks'],
|
|
|
+ ];
|
|
|
+ list($msec, $sec) = explode(' ', microtime());
|
|
|
+ $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
|
|
|
+ $orderId = $request->uid() . $msectime . mt_rand(10000, 99999);
|
|
|
+ $order['cache'] = $orderId;
|
|
|
+ cache($order['cache'], $order, 300);
|
|
|
+ return app('json')->successful($order);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 创建订单
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function create(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::postMore([
|
|
|
+ ['cache', ''],
|
|
|
+ ['pay_type' , '']
|
|
|
+ ]);
|
|
|
+ $uid = $request->uid();
|
|
|
+ $order = cache($data['cache']);
|
|
|
+
|
|
|
+ if (!$order) return app('json')->fail('订单已过期');
|
|
|
+ BaseModel::beginTrans();
|
|
|
+ $res = DiagnosisOrder::create_order($order, $data['pay_type'],$uid);
|
|
|
+ if ($order['pay_price'] == 0){
|
|
|
+ $res1 = DiagnosisOrder::yuPay($res['order_id']);
|
|
|
+ if ($res){
|
|
|
+ cache()->delete($data['cache']);
|
|
|
+ BaseModel::checkTrans($res);
|
|
|
+ return app('json')->status('success', '余额支付成功');
|
|
|
+ }else{
|
|
|
+ return app('json')->fail('支付失败');
|
|
|
+ }
|
|
|
+ }else{
|
|
|
+ if ($res['pay_type'] == 1){
|
|
|
+ $res1 = DiagnosisOrder::yuPay($res['order_id']);
|
|
|
+ if ($res){
|
|
|
+ cache()->delete($data['cache']);
|
|
|
+ BaseModel::checkTrans($res);
|
|
|
+ return app('json')->status('success', '余额支付成功');
|
|
|
+ }else{
|
|
|
+ return app('json')->fail('支付失败');
|
|
|
+ }
|
|
|
+ }elseif ($res['pay_type'] ==2){
|
|
|
+ try {
|
|
|
+ $jsConfig = OrderRepository::jsDiaPay($res['order_id']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->status('pay_error', $e->getMessage());
|
|
|
+ }
|
|
|
+ $info['jsConfig'] = $jsConfig;
|
|
|
+ cache()->delete($data['cache']);
|
|
|
+ BaseModel::checkTrans($res);
|
|
|
+ return app('json')->status('wechat_pay', '订单创建成功', $info);
|
|
|
+ }elseif ($res['pay_type'] ==3){
|
|
|
+ try {
|
|
|
+ $jsConfig = OrderRepository::wxDiaPay($res['order_id']);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ return app('json')->status('pay_error', $e->getMessage());
|
|
|
+ }
|
|
|
+ $info['jsConfig'] = $jsConfig;
|
|
|
+ cache()->delete($data['cache']);
|
|
|
+ BaseModel::checkTrans($res);
|
|
|
+ return app('json')->status('wechat_h5_pay', '订单创建成功', $info);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return app('json')->fail('订单生成失败!');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 用户订单
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ */
|
|
|
+ public function order_list(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['status', ''],
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 10]
|
|
|
+ ]);
|
|
|
+ $list = DiagnosisOrder::alias('a')
|
|
|
+ ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks')
|
|
|
+ ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid')
|
|
|
+ ->order('a.id DESC')
|
|
|
+ ->where('a.status', $data['status'])
|
|
|
+ ->where('a.uid', $request->uid())
|
|
|
+ ->page($data['page'], $data['limit'])->select();
|
|
|
+ $list = count($list) > 0 ? $list->toArray() : [];
|
|
|
+ if ($list){
|
|
|
+ foreach ($list as &$item){
|
|
|
+ $item['cate'] = DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name');
|
|
|
+ $item['service'] = DiagnosisService::where('id', 'in', $item['service_id'])->column('name');
|
|
|
+ $item['receiving'] = DiagnosisApply::where('uid', $item['order_receiving'])->find();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return app('json')->successful($list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 订单详情
|
|
|
+ * @param Request $request
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+ public function details(Request $request,$id)
|
|
|
+ {
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $list = DiagnosisOrder::alias('a')
|
|
|
+ ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks')
|
|
|
+ ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid')
|
|
|
+ ->order('a.id DESC')
|
|
|
+ ->where('a.id', $id)
|
|
|
+ ->find()->toArray();
|
|
|
+ $list['cate'] = DiagnosisCate::where('id', 'in', $list['cate_id'])->column('name');
|
|
|
+ $list['service'] = DiagnosisService::where('id', 'in', $list['service_id'])->column('name');
|
|
|
+ $list['receiving'] = DiagnosisApply::where('uid', $list['order_receiving'])->find();
|
|
|
+ return app('json')->successful($list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 接单
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function order_receiving(Request $request,$id)
|
|
|
+ {
|
|
|
+ BaseModel::beginTrans();
|
|
|
+ $user = User::where('uid', $request->uid())->find();
|
|
|
+ if ($user['is_receiver'] != 1) return app('json')->fail('你不是接单员');
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->lock(true)->find();
|
|
|
+ if ($order['status'] > 0) return app('json')->fail('该订单已被接');
|
|
|
+ $order['order_receiving'] = $request->uid();
|
|
|
+ $order['status'] = 1;
|
|
|
+ $res = $order->save();
|
|
|
+ if ($res){
|
|
|
+ BaseModel::commitTrans();
|
|
|
+ return app('json')->success('接单成功');
|
|
|
+ }
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
+ return app('json')->fail('接单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 接单员订单列表
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function receiving_list(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['status', ''],
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 10]
|
|
|
+ ]);
|
|
|
+ $list = DiagnosisOrder::alias('a')
|
|
|
+ ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks')
|
|
|
+ ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid')
|
|
|
+ ->order('a.id DESC')
|
|
|
+ ->where('a.status', $data['status'])
|
|
|
+ ->where('a.order_receiving', $request->uid())
|
|
|
+ ->page($data['page'], $data['limit'])->select();
|
|
|
+ $list = count($list) > 0 ? $list->toArray() : [];
|
|
|
+ if ($list){
|
|
|
+ foreach ($list as &$item){
|
|
|
+ $item['cate'] = DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name');
|
|
|
+ $item['service'] = DiagnosisService::where('id', 'in', $item['service_id'])->column('name');
|
|
|
+ $item['receiving'] = DiagnosisApply::where('uid', $item['order_receiving'])->find();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return app('json')->successful($list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 接单大厅
|
|
|
+ * @param Request $request
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function order_receiving_hall(Request $request)
|
|
|
+ {
|
|
|
+ $data = UtilService::getMore([
|
|
|
+ ['type'],
|
|
|
+ ['page', 1],
|
|
|
+ ['limit', 10],
|
|
|
+ ]);
|
|
|
+ if (!$data['type']) return app('json')->fail('传入类型');
|
|
|
+ $list = DiagnosisOrder::alias('a')
|
|
|
+ ->field('a.*,b.time,b.name,b.sex,b.age,b.phone,b.hospital,b.urgent_phone,b.service_id,b.transfer_address,b.remarks')
|
|
|
+ ->leftJoin('diagnosis_order_attr b', 'a.id = b.oid')
|
|
|
+ ->order('a.id DESC')
|
|
|
+ ->where('a.type', $data['type'])
|
|
|
+ ->where('a.status', 0)
|
|
|
+ ->page($data['page'], $data['limit'])->select();
|
|
|
+ $list = count($list) > 0 ? $list->toArray() : [];
|
|
|
+ return app('json')->successful($list);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 放弃订单
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException、
|
|
|
+ */
|
|
|
+ public function discard_order(Request $request,$id)
|
|
|
+ {
|
|
|
+
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->where('order_receiving', $request->uid())->lock(true)->find();
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+ $order['status'] = 0;
|
|
|
+ $order['order_receiving'] = 0;
|
|
|
+ $res = $order->save();
|
|
|
+
|
|
|
+ if ($res) return app('json')->success('放弃订单成功');
|
|
|
+ return app('json')->fail('放弃订单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 取消订单
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function cancel_order(Request $request,$id)
|
|
|
+ {
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->find();
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+ $order['status'] = -1;
|
|
|
+ $res = $order->save();
|
|
|
+
|
|
|
+ if ($res) return app('json')->success('取消订单成功');
|
|
|
+ return app('json')->fail('取消订单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 提交完成
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function submit(Request $request,$id)
|
|
|
+ {
|
|
|
+ $data = UtilService::postMore([
|
|
|
+ ['images', '']
|
|
|
+ ]);
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->where('order_receiving', $request->uid())->find();
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+ if ($order['status'] <> 1) return app('json')->fail('当前订单状态不对');
|
|
|
+
|
|
|
+ $order['images'] = json_encode($data['images']);
|
|
|
+ $order['status'] = 2;
|
|
|
+ $res = $order->save();
|
|
|
+
|
|
|
+ if ($res) return app('json')->success('提交订单成功');
|
|
|
+ return app('json')->fail('提交订单失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ * 用户确认完成
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function confirmation(Request $request,$id)
|
|
|
+ {
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ BaseModel::beginTrans();
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->lock(true)->find();
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+ if ($order['status'] <> 2) return app('json')->fail('当前订单状态不对');
|
|
|
+
|
|
|
+ $order['status'] = 3;
|
|
|
+ $res1 = $order->save();
|
|
|
+ $user = User::where('uid', $order['order_receiving'])->find();
|
|
|
+ $res2 = UserBill::income('完成订单佣金', $order['order_receiving'], 'now_money', 'brokerage', $order['commission'], '', $user['brokerage_price']+$order['commission'], '完成订单佣金');
|
|
|
+ $res3 = User::where('uid', $order['order_receiving'])->inc('brokerage_price', $order['commission'])->update();
|
|
|
+ if ($res1 && $res2 && $res3){
|
|
|
+ BaseModel::commitTrans();
|
|
|
+ return app('json')->success('成功');
|
|
|
+ }
|
|
|
+ BaseModel::rollbackTrans();
|
|
|
+ return app('json')->fail('失败');
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 申请售后
|
|
|
+ * @param Request $request
|
|
|
+ * @param $id
|
|
|
+ * @return mixed
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ */
|
|
|
+ public function after_sales(Request $request,$id)
|
|
|
+ {
|
|
|
+ $data = UtilService::postMore([
|
|
|
+ ['after_remarks'],
|
|
|
+ ['after_images']
|
|
|
+ ]);
|
|
|
+ if (!$id) return app('json')->fail('传入订单id!');
|
|
|
+ $order = DiagnosisOrder::where('id', $id)->where('uid', $request->uid())->lock(true)->find();
|
|
|
+ if (!$order) return app('json')->fail('订单不存在!');
|
|
|
+ if ($order['status'] <> 3) return app('json')->fail('订单未完成');
|
|
|
+ $order['after_remarks'] = $data['after_remarks'];
|
|
|
+ $order['after_images'] = json_encode($data['after_images']);
|
|
|
+ $order['after_sales'] = 1;
|
|
|
+ $res = $order->save();
|
|
|
+ if ($res) return app('json')->success('提交成功');
|
|
|
+ return app('json')->fail('提交失败');
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|