hrjy 2 years ago
parent
commit
d6d244e09b

+ 33 - 1
app/admin/controller/diagnosis/DiagnosisOrder.php

@@ -36,9 +36,16 @@ class DiagnosisOrder extends AuthController
      */
     public function index()
     {
+        $count['djd'] = \app\admin\model\diagnosis\DiagnosisOrder::where('status', 0)->count();
+        $count['yjd'] = \app\admin\model\diagnosis\DiagnosisOrder::where('status', 1)->count();
+        $count['dqd'] = \app\admin\model\diagnosis\DiagnosisOrder::where('status', 2)->count();
+        $count['ywc'] = \app\admin\model\diagnosis\DiagnosisOrder::where('status', 3)->count();
+        $count['sh'] = \app\admin\model\diagnosis\DiagnosisOrder::where('after_sales', 1)->count();
+        $count['qx'] = \app\admin\model\diagnosis\DiagnosisOrder::where('status', -1)->count();
+
         $this->assign([
             'year' => get_month(),
-
+            'count' => $count
         ]);
         return $this->fetch();
     }
@@ -52,8 +59,10 @@ class DiagnosisOrder extends AuthController
             ['name', ''],
             ['order_id', ''],
             ['type', ''],
+            ['pay_type', ''],
             ['rece', ''],
             ['data', ''],
+            ['status', ''],
         ]);
 
         return Json::successlayui(model::list($where));
@@ -192,6 +201,26 @@ class DiagnosisOrder extends AuthController
         }
     }
 
+    /**
+     * 完成
+     * @param $id
+     * @return void
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function sales($id)
+    {
+        $order = model::find($id);
+        $order['after_sales'] = 2;
+        $res = $order->save();
+        if ($res){
+            return Json::success('成功!');
+        }else{
+            return Json::fail('失败');
+        }
+    }
+
 
     /**
      * 设置单个产品上架|下架
@@ -222,6 +251,7 @@ class DiagnosisOrder extends AuthController
         $order = model::find($id);
         if ($order['images']){
             $order['images'] = json_decode($order['images']);
+            $order['after_images'] = json_decode($order['after_images']);
         }
         $user = User::where('uid', $order['uid'])->find();//订单用户
         $re = User::where('uid', $order['order_receiving'])->find();//接单员
@@ -307,4 +337,6 @@ class DiagnosisOrder extends AuthController
         }
     }
 
+
+
 }

+ 0 - 7
app/admin/controller/wechat/index.php

@@ -1,7 +0,0 @@
-<?php
-/**
- * Created by PhpStorm.
- * User: Administrator
- * Date: 2018/4/18 0018
- * Time: 上午 10:44
- */

+ 130 - 17
app/admin/model/diagnosis/DiagnosisOrder.php

@@ -11,6 +11,8 @@ namespace app\admin\model\diagnosis;
 use app\admin\model\store\StoreProduct;
 use app\admin\model\system\SystemAdmin;
 use app\models\article\ArticleContent;
+use app\models\user\User;
+use app\models\user\UserBill;
 use crmeb\traits\ModelTrait;
 use crmeb\basic\BaseModel;
 use think\model\concern\SoftDelete;
@@ -44,7 +46,32 @@ class DiagnosisOrder extends BaseModel
         if ($where['name'])$model->where('a.uid|b.nickname' , 'like', '%'.$where['name'].'%');
         if ($where['order_id'])$model->where('a.order_id' , 'like', '%'.$where['order_id'].'%');
         if ($where['rece'])$model->where('a.order_receiving|c.nickname' , 'like', '%'.$where['rece'].'%');
-        if ($where['type'])$model->where('type' , $where['type']);
+        if ($where['type'])$model->where('a.type' , $where['type']);
+        if ($where['pay_type']) $model->where('a.pay_type', $where['pay_type']);
+        if ($where['status'] == 0 && $where['status'] != ''){
+
+            $model->where('a.status', 0);
+
+        }elseif ($where['status'] == 1){
+
+            $model->where('a.status', 1);
+
+        }elseif ($where['status'] == 2){
+
+            $model->where('a.status', 2);
+
+        }elseif ($where['status'] == 3){
+
+            $model->where('a.status', 3);
+
+        }elseif ($where['status'] == 4){
+
+            $model->where('a.after_sales', 1);
+
+        }elseif ($where['status'] == 5){
+
+            $model->where('a.status', -1);
+        }
         if (isset($where['data']) && $where['data'] !== '') {
             $model = self::getModelTime($where, $model,   'create_time');
         }
@@ -59,28 +86,38 @@ class DiagnosisOrder extends BaseModel
         $list = $model->select()->toArray();
         foreach ($list as &$item)
         {
-            if ($item['paid'] == 0) $item['paid'] = '未支付';
+            if ($item['paid'] == 0){
+                $item['paid'] = '未支付';
+                $item['status'] = '未支付';
+            } else{
+                if ($item['status'] == 0){
+                    $item['status'] = '待接单';
+                }elseif ($item['status'] == 1){
+                    $item['status'] = '已接单';
+                }elseif ($item['status'] == 2){
+                    $item['status'] = '待确认';
+                }elseif ($item['status'] == 3){
+                    if ($item['after_sales'] == 1){
+                        $item['status'] = '申请售后';
+                    }else{
+                        $item['status'] = '已完成';
+                    }
+
+                }elseif ($item['status'] == -1){
+                    if ($item['refund_status'] == 0){
+                        $item['status'] = '待退款';
+                    }elseif ($item['refund_status'] == 1){
+                        $item['status'] = '已退款';
+                    }
+
+                }
+            }
             if ($item['paid'] == 1) $item['paid'] = '已支付';
             if ($item['pay_type'] == 1) $item['pay_type'] = '余额';
             if ($item['pay_type'] == 2) $item['pay_type'] = '微信';
             if ($item['pay_type'] == 3) $item['pay_type'] = '支付宝';
             $item['cate'] = implode(',',DiagnosisCate::where('id', 'in', $item['cate_id'])->column('name'));
-            if ($item['status'] == 0){
-                $item['status'] = '待接单';
-            }elseif ($item['status'] == 1){
-                $item['status'] = '已接单';
-            }elseif ($item['status'] == 2){
-                $item['status'] = '已完成';
-            }elseif ($item['status'] == -1){
-                $item['status'] = '已过期';
-            }elseif ($item['status'] == -2){
-                if ($item['refund_status'] == 0){
-                    $item['status'] = '待退款';
-                }elseif ($item['refund_status'] == 1){
-                    $item['status'] = '已退款';
-                }
 
-            }
             if ($item['type'] == 1){
                 $item['type'] = '陪诊';
             }elseif ($item['type'] == 2){
@@ -91,4 +128,80 @@ class DiagnosisOrder extends BaseModel
         return $data;
 
     }
+
+
+    /**
+     * 生成订单
+     * @param $order
+     * @param $pay_type
+     * @param $uid
+     * @return DiagnosisOrder|\think\Model
+     */
+    public static function create_order($order, $pay_type, $uid)
+    {
+
+        $res1 = self::create([
+            'cate_id' => $order['cate_id'],
+            'order_id' => self::getNewOrderId(),
+            'uid' => $uid,
+            'ot_price' => $order['ot_price'],
+            'pay_price' => $order['pay_price'],
+            'commission' => $order['commission'],
+            'pay_type' => $pay_type,
+            'type' => $order['type'],
+        ]);
+        $order['attr']['oid'] = $res1['id'];
+        $res2 = DiagnosisOrderAttr::create($order['attr']);
+
+        return $res1;
+    }
+
+    /**
+     * 生成订单唯一id
+     * @param $uid 用户uid
+     * @return string
+     */
+    public static function getNewOrderId()
+    {
+        do {
+            list($msec, $sec) = explode(' ', microtime());
+            $msectime = number_format((floatval($msec) + floatval($sec)) * 1000, 0, '', '');
+            $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
+        } while (self::be(['order_id' => $orderId]));// $orderId = 'wx' . $msectime . mt_rand(10000, 99999);
+        return $orderId;
+    }
+
+
+    public static function yuPay($orderId)
+    {
+        $order = self::where('order_id', $orderId)->find();
+        if ($order['pay_price'] == 0){
+            $res = self::paySuccess($orderId);
+        }else{
+            if (!$order)return self::setErrorInfo('订单不存在!');
+            $user = User::where('uid', $order['uid'])->find();
+            if ($user['now_money'] < $order['pay_price'])  return self::setErrorInfo('余额不足!', true);
+
+            $res = User::where('uid', $order['uid'])->dec('now_money', $order['pay_price'])->update();
+            if ($res){
+                $res = self::paySuccess($orderId);
+            }else{
+                return  false;
+            }
+        }
+        return $res;
+    }
+
+
+
+    public static function paySuccess($orderId, $paytype = 'weixin', $formId = '')
+    {
+        $order = self::where('order_id', $orderId)->find();
+        if (!$order)return self::setErrorInfo('订单不存在!');
+        if ($order['paid'] == 1) return self::setErrorInfo('订单已支付!');
+        self::where('order_id', $orderId)->update(['paid' => 1, 'pay_time' => time()]);
+        $now_money = User::where('uid', $order['uid'])->value('now_money');
+        UserBill::expend('创建订单', $order['uid'], 'now_money', 'pay_money', $order['pay_price'], $order['id'], $now_money, '支付' . floatval($order['pay_price']) . '元创建订单');
+        return true;
+    }
 }

+ 65 - 2
app/admin/view/diagnosis/diagnosis_order/index.php

@@ -68,7 +68,31 @@
 <!--                                        </div>-->
 <!--                                    </div>-->
                                 </div>
+
                                 <div class="layui-col-lg12" id="app1">
+                                    <div class="layui-col-lg12">
+                                        <label class="layui-form-label">支付方式:</label>
+                                        <div class="layui-input-block" v-cloak="">
+                                            <button class="layui-btn layui-btn-sm"
+                                                    :class="{'layui-btn-primary':where.pay_type!=item.value}"
+                                                    @click="where.pay_type = item.value" type="button"
+                                                    v-for="item in payType">{{item.name}}
+                                                <span v-if="item.count!=undefined" class="layui-badge layui-bg-gray">{{item.count}}</span>
+                                            </button>
+                                        </div>
+                                    </div>
+                                    <div class="layui-col-lg12">
+                                        <label class="layui-form-label">订单状态:</label>
+                                        <div class="layui-input-block" v-cloak="">
+                                            <button class="layui-btn layui-btn-sm"
+                                                    :class="{'layui-btn-primary':where.status!==item.value}"
+                                                    @click="where.status = item.value" type="button"
+                                                    v-for="item in orderStatus">{{item.name}}
+                                                <span v-if="item.count!=undefined"
+                                                      :class="item.class!=undefined ? 'layui-badge': 'layui-badge layui-bg-gray' ">{{item.count}}</span>
+                                            </button>
+                                        </div>
+                                    </div>
                                     <div class="layui-col-lg12">
                                         <label class="layui-form-label">创建时间:</label>
                                         <div class="layui-input-block" data-type="data" v-cloak="">
@@ -85,6 +109,7 @@
                                             </button>
                                         </div>
                                     </div>
+
                                     <div class="layui-inline">
                                     <button @click="excel" type="button"
                                             class="layui-btn layui-btn-warm layui-btn-sm export" type="button">
@@ -139,7 +164,7 @@
                         <ul class="layui-nav-child layui-anim layui-anim-upbit">
                             <li>
                                 <a href="javascript:void(0);" lay-event='wc'>
-                                    <i class="fa fa-file-text"></i> 完成
+                                    <i class="fa fa-file-text"></i> 订单完成
                                 </a>
                             </li>
                             <li>
@@ -147,13 +172,20 @@
                                     <i class="fa fa-edit"></i> 删除
                                 </a>
                             </li>
-                            {{# if(d.status == '待退款' && d.refund_status == 0){ }}
+                            {{# if(d.status == '待退款' || d.status == '已退款' || d.after_sales == 1){ }}
                             <li>
                                 <a href="javascript:void(0);" onclick="$eb.createModalFrame('编辑','{:Url('refund')}?id={{d.id}}',{h:950,w:800})">
                                     <i class="fa fa-edit"></i> 退款
                                 </a>
                             </li>
                             {{# } ;}}
+                            {{# if(d.after_sales == 1){ }}
+                            <li>
+                                <a href="javascript:void(0);" lay-event='sales'>
+                                    <i class="fa fa-edit"></i> 售后完成
+                                </a>
+                            </li>
+                            {{# } ;}}
                         </ul>
                         <button type="button" class="layui-btn layui-btn-xs layui-btn-normal" onclick="$eb.createModalFrame('编辑','{:Url('info')}?id={{d.id}}',{h:950,w:800})">
                             详情
@@ -227,6 +259,21 @@
                     });
                 },code)
                 break;
+            case 'sales':
+                var url=layList.U({c:'diagnosis.diagnosis_order',a:'sales',q:{id:data.id}});
+                var code = {title:"操作提示",text:"确定售后完成吗?",type:'info',confirm:'是的'};
+                $eb.$swal('delete',function(){
+                    $eb.axios.get(url).then(function(res){
+                        if(res.status == 200 && res.data.code == 200) {
+                            $eb.$swal('success',res.data.msg);
+                            location.reload();
+                        }else
+                            return Promise.reject(res.data.msg || '失败')
+                    }).catch(function(err){
+                        $eb.$swal('error',err);
+                    });
+                },code)
+                break;
             case 'wc':
                 var url=layList.U({c:'diagnosis.diagnosis_order',a:'wc',q:{id:data.id}});
                 var code = {title:"操作提示",text:"确定完成吗?",type:'info',confirm:'是的'};
@@ -296,6 +343,7 @@
             });
         }
     });
+    var orderCount =<?=json_encode($count)?>;
 
     require(['vue'], function (Vue) {
         new Vue({
@@ -311,6 +359,21 @@
                     {name: '本月', value: 'month'},
                     {name: '本年', value: 'year'},
                 ],
+                payType: [
+                    {name: '全部', value: ''},
+                    {name: '余额支付', value: 1},
+                    {name: '微信支付', value: 2},
+                    {name: '支付宝支付', value: 3},
+                ],
+                orderStatus: [
+                    {name: '全部', value: ''},
+                    {name: '待接单', value: 0, count: orderCount.djd},
+                    {name: '已接单', value: 1, count: orderCount.yjd},
+                    {name: '待确定', value: 2, count: orderCount.dqd},
+                    {name: '已完成', value: 3, count: orderCount.ywc},
+                    {name: '申请售后', value: 4, count: orderCount.sh, class: true},
+                    {name: '取消订单', value: 5, count: orderCount.qx, class: true},
+                ],
                 where: {
                     data: '',
                     status: status,

+ 27 - 3
app/admin/view/diagnosis/diagnosis_order/info.php

@@ -75,7 +75,7 @@
                 </div>
             </div>
         </div>
-        {if $order.status == 2}
+        {if $order.status >= 2}
         <div class="col-sm-12">
             <div class="panel panel-default">
                 <div class="panel-heading">
@@ -92,7 +92,7 @@
             </div>
         </div>
         {/if}
-        {if $order.status == -2 && $order.refund_status == 1}
+        {if $order.status == -1 || $order.refund_status == 1 || $order.refund_price > 0}
         <div class="col-sm-12">
             <div class="panel panel-default">
                 <div class="panel-heading">
@@ -100,7 +100,31 @@
                 </div>
                 <div class="panel-body">
                     <div class="row show-grid">
-                        <div class="col-xs-6" >退款:{$order.refund_price}</div>
+                        <div class="col-xs-6" >已退款:{$order.refund_price}</div>
+                    </div>
+                </div>
+            </div>
+        </div>
+        {/if}
+
+        {if $order.after_sales > 0}
+        <div class="col-sm-12">
+            <div class="panel panel-default">
+                <div class="panel-heading">
+                    申请售后
+                </div>
+                <div class="panel-body">
+                    <div class="row show-grid">
+                        <div class="col-xs-6" >售后理由:{$order.after_remarks}</div>
+                        {if $order.after_sales == 1}
+                        <div class="col-xs-6" >售后状态:申请售后</div>
+                        {/if}
+                        {if $order.after_sales == 2}
+                        <div class="col-xs-6" >售后状态:完成售后</div>
+                        {/if}
+                        {foreach ($order.after_images as  $k => $v)}
+                        <div class="col-xs-12" >售后图片<img src="{$v}" width="520px" height="320px"></div>
+                        {/foreach}
                     </div>
                 </div>
             </div>

+ 63 - 0
app/api/controller/diagnosis/DiagnosisCateController.php

@@ -0,0 +1,63 @@
+<?php
+
+namespace app\api\controller\diagnosis;
+
+use app\admin\model\diagnosis\DiagnosisCate;
+use app\admin\model\diagnosis\DiagnosisService;
+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 DiagnosisCateController
+{
+
+    /**
+     * 陪诊代办类型
+     * @param Request $request
+     * @return mixed
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
+     */
+    public function type(Request $request)
+    {
+        $data = UtilService::getMore([
+            ['type']
+        ]);
+        $list = DiagnosisCate::where('type', $data['type'])->select()->toArray();
+        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 service(Request $request)
+    {
+        $list = DiagnosisService::select()->toArray();
+        return app('json')->successful($list);
+    }
+
+
+
+
+
+}

+ 436 - 0
app/api/controller/diagnosis/DiagnosisOrderController.php

@@ -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']); //创建订单jspay
+                } 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']); //创建订单jspay
+                } 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('提交失败');
+    }
+
+
+
+
+
+
+
+
+}

+ 53 - 0
crmeb/repositories/OrderRepository.php

@@ -2,6 +2,7 @@
 
 namespace crmeb\repositories;
 
+use app\admin\model\diagnosis\DiagnosisOrder;
 use app\models\store\StoreOrder;
 use app\models\user\User;
 use app\models\user\WechatUser;
@@ -41,6 +42,58 @@ class OrderRepository
         return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'product', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
     }
 
+
+    /**
+     * TODO 小程序JS支付
+     * @param $orderId
+     * @param string $field
+     * @return array|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function jsDiaPay($orderId, $field = 'order_id')
+    {
+        if (is_string($orderId))
+            $orderInfo = DiagnosisOrder::where($field, $orderId)->find();
+        else
+            $orderInfo = $orderId;
+        if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
+        if ($orderInfo['paid']) exception('支付已支付!');
+        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        $openid = WechatUser::getOpenId($orderInfo['uid']);
+        $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
+        $site_name = sys_config('site_name');
+        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        return MiniProgramService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'diagnosis', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
+    }
+
+    /**
+     * 微信公众号JS支付
+     * @param $orderId
+     * @param string $field
+     * @return array|string
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\ModelNotFoundException
+     * @throws \think\exception\DbException
+     */
+    public static function wxDiaPay($orderId, $field = 'order_id')
+    {
+        if (is_string($orderId))
+            $orderInfo = DiagnosisOrder::where($field, $orderId)->find();
+        else
+            $orderInfo = $orderId;
+        if (!$orderInfo || !isset($orderInfo['paid'])) exception('支付订单不存在!');
+        if ($orderInfo['paid']) exception('支付已支付!');
+        if ($orderInfo['pay_price'] <= 0) exception('该支付无需支付!');
+        $openid = WechatUser::uidToOpenid($orderInfo['uid'], 'openid');
+        $bodyContent = StoreOrder::getProductTitle($orderInfo['cart_id']);
+        $site_name = sys_config('site_name');
+        if (!$bodyContent && !$site_name) exception('支付参数缺少:请前往后台设置->系统设置-> 填写 网站名称');
+        return WechatService::jsPay($openid, $orderInfo['order_id'], $orderInfo['pay_price'], 'diagnosis', StoreOrder::getSubstrUTf8($site_name . ' - ' . $bodyContent, 30));
+    }
+
+
     /**
      * 微信公众号JS支付
      * @param $orderId

+ 16 - 0
crmeb/repositories/PaymentRepositories.php

@@ -2,6 +2,7 @@
 
 namespace crmeb\repositories;
 
+use app\admin\model\diagnosis\DiagnosisOrder;
 use app\models\store\StoreOrder;
 use app\models\user\UserRecharge;
 
@@ -58,6 +59,21 @@ class PaymentRepositories
         }
     }
 
+    /**
+     * 订单支付成功之后
+     * @param string|null $order_id 订单id
+     * @return bool
+     */
+    public static function wechatDiagnosis(string $order_id = null)
+    {
+        try {
+            if (DiagnosisOrder::be(['order_id' => $order_id, 'paid' => 1])) return true;
+            return DiagnosisOrder::paySuccess($order_id);
+        } catch (\Exception $e) {
+            return false;
+        }
+    }
+
     /**
      * 充值成功后
      * @param string|null $order_id 订单id

+ 18 - 0
route/api/route.php

@@ -164,6 +164,21 @@ Route::group(function () {
     Route::get('user/level/task/:id', 'user.UserLevelController/task')->name('userLevelTask');//获取等级任务
     //首页获取未支付订单
     Route::get('order/nopay', 'order.StoreOrderController/get_noPay')->name('getNoPay');//获取未支付订单
+    //陪诊订单计算
+    Route::get('diagnosis/confirm', 'diagnosis.DiagnosisOrderController/confirm')->name('confirm');//计算订单
+    Route::post('diagnosis/create', 'diagnosis.DiagnosisOrderController/create')->name('create');//创建订单
+    Route::get('diagnosis/order_list', 'diagnosis.DiagnosisOrderController/order_list')->name('order_list');//用户订单
+    Route::post('diagnosis/cancel_order/:id', 'diagnosis.DiagnosisOrderController/cancel_order')->name('cancel_order');//取消订单
+    Route::get('diagnosis/details/:id', 'diagnosis.DiagnosisOrderController/details')->name('details');//订单详情
+    Route::post('diagnosis/order_receiving/:id', 'diagnosis.DiagnosisOrderController/order_receiving')->name('order_receiving');//接单
+    Route::get('diagnosis/receiving_list', 'diagnosis.DiagnosisOrderController/receiving_list')->name('receiving_list');//接单员订单列表
+    Route::get('diagnosis/order_receiving_hall', 'diagnosis.DiagnosisOrderController/order_receiving_hall')->name('order_receiving_hall');//接单大厅
+    Route::post('diagnosis/discard_orde/:id', 'diagnosis.DiagnosisOrderController/discard_order')->name('discard_order');//放弃订单
+    Route::post('diagnosis/submit/:id', 'diagnosis.DiagnosisOrderController/submit')->name('submit');//提交完成
+    Route::post('diagnosis/confirmation/:id', 'diagnosis.DiagnosisOrderController/confirmation')->name('confirmation');//确认完成
+    Route::post('diagnosis/after_sales/:id', 'diagnosis.DiagnosisOrderController/after_sales')->name('after_sales');//申请售后
+
+
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, true);
 //未授权接口
 Route::group(function () {
@@ -232,6 +247,9 @@ Route::group(function () {
     //获取城市列表
     Route::get('city_list', 'PublicController/city_list')->name('cityList');
 
+    Route::get('diagnosis/cate', 'diagnosis.DiagnosisCateController/type')->name('type');// 陪诊代办分类
+    Route::get('diagnosis/service', 'diagnosis.DiagnosisCateController/service')->name('service'); // 陪诊服务
+
 
 })->middleware(\app\http\middleware\AllowOriginMiddleware::class)->middleware(\app\http\middleware\AuthTokenMiddleware::class, false);