Prechádzať zdrojové kódy

师傅端-确认报价并上门

whitefang 1 rok pred
rodič
commit
7fc53828b1

+ 107 - 0
app/adminapi/logic/works/ServiceWorkLogic.php

@@ -16,6 +16,7 @@ namespace app\adminapi\logic\works;
 
 
 use app\common\model\dict\DictData;
+use app\common\model\recharge\RechargeOrder;
 use app\common\model\works\ServiceWork;
 use app\common\logic\BaseLogic;
 use app\common\model\works\ServiceWorkLog;
@@ -105,4 +106,110 @@ class ServiceWorkLogic extends BaseLogic
             return false;
         }
     }
+
+    /**
+     * 师傅确认上门
+     * @param $params
+     * @return false|void
+     */
+    public static function confirmDoor($params)
+    {
+        Db::startTrans();
+        try {
+            $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
+            if($work->isEmpty()){
+                throw new Exception('工单不存在');
+            }
+
+            $order = RechargeOrder::where(['sn'=>$params['order_sn'],'work_id'=>$work['id']])->findOrEmpty();
+            if($order->isEmpty()){
+                throw new Exception('订单不存在');
+            }
+
+            if($work->work_status != 3){
+                throw new Exception('请勿重复点击');
+            }
+
+            $work->work_status = 4;//已上门
+            $work->save();
+
+            //添加变更日志
+            $work_log = [
+                'work_id'=>$work->id,
+                'master_worker_id'=>$work->master_worker_id,
+                'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'已上门',
+            ];
+            ServiceWorkLogLogic::add($work_log);
+            Db::commit();
+        }
+        catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
+    /**
+     * 师傅确认报价单
+     * @param $params
+     * @return false|void
+     */
+    public static function confirmPrice($params)
+    {
+        Db::startTrans();
+        try {
+            $work = ServiceWork::where(['master_worker_id'=>$params['user_id'],'work_sn'=>$params['work_sn']])->findOrEmpty();
+            if($work->isEmpty()){
+                throw new Exception('工单不存在');
+            }
+            //搜索待支付订单
+            $paid_order = RechargeOrder::where(['work_id'=>$work['id'],'pay_status'=>1])->findOrEmpty()->toArray();
+            if(empty($paid_order)){
+                throw new Exception('订单错误');
+            }
+
+            if($work->work_status != 3 || $work->user_confirm_status !=1 ){
+                throw new Exception('请勿重复操作');
+            }
+
+            //定金存在尾款结算功能,全款直接提交
+            if($paid_order['payment_type']==1){
+                $un_order = RechargeOrder::where(['work_id'=>$work['id'],'pay_status'=>0])->findOrEmpty();
+                if($un_order->isEmpty()){
+                    //新增待支付尾款
+                    $order_data = [
+                        'order_type'=>$paid_order['order_type'],
+                        'sn'=>generate_sn(\app\common\model\orders\RechargeOrder::class, 'sn'),
+                        'work_id'=>$paid_order['work_id'],
+                        'user_id'=>$paid_order['user_id'],
+                        'payment_type'=>2,
+                        'order_total'=>$params['amount'],
+                        'order_amount'=>$params['amount'],
+                        'order_terminal'=>$paid_order['order_terminal']
+                    ];
+                    RechargeOrder::create($order_data);
+                }
+
+                //修改尾款信息
+                $un_order->order_total = $params['amount'];
+                $un_order->order_amount = $params['amount'];
+                $un_order->save();
+            }
+
+            $work->user_confirm_status = 1;//待确认报价
+            $work->save();
+
+            //添加变更日志
+            $work_log = [
+                'work_id'=>$work->id,
+                'master_worker_id'=>$work->master_worker_id,
+                'opera_log'=>'编号['.$params['user_info']['worker_number'].']'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'提交了报价单',
+            ];
+            ServiceWorkLogLogic::add($work_log);
+            Db::commit();
+        }
+        catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 17 - 0
app/api/controller/ServiceOrderController.php

@@ -70,4 +70,21 @@ class ServiceOrderController extends BaseApiController
         }
         return $this->success('取消成功', [], 1, 1);
     }
+
+    /**
+     * 确认报价订单
+     * @return \think\response\Json
+     */
+    public function confirmOrder()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('price', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceOrderLogic::confirmOrder($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->success('已确认报价,师傅即将开始服务', [], 1, 1);
+    }
 }

+ 42 - 0
app/api/logic/ServiceOrderLogic.php

@@ -12,6 +12,7 @@ use app\common\model\master_worker\MasterWorker;
 use app\common\model\orders\RechargeOrder;
 use app\common\model\recharge\OrderGoods;
 use app\common\model\works\ServiceWork;
+use app\workerapi\logic\ServiceWorkLogLogic;
 use think\Exception;
 use think\facade\Db;
 
@@ -212,4 +213,45 @@ class ServiceOrderLogic extends BaseLogic
             return false;
         }
     }
+
+    /**
+     * 用户确认尾款报价单
+     * @param $params
+     * @return false|void
+     */
+    public static function confirmOrder($params)
+    {
+        Db::startTrans();
+        try {
+            $work_id =  \app\common\model\recharge\RechargeOrder::where([
+                'order_type' => 0,
+                'user_id' => $params['user_id'],
+                'sn'=>$params['sn']
+            ])->value('work_id');
+            if(empty($work_id)){
+                throw new Exception('订单不存在');
+            }
+
+            //更新工单状态为已取消
+            $service_work = ServiceWork::find($work_id);
+            if($service_work->user_confirm_status==2){
+                throw new Exception('请勿重复操作');
+            }
+            $service_work->work_status = 5;
+            $service_work->user_confirm_status = 2;
+            $service_work->save();
+
+            $work_log = [
+                'work_id'=>$work_id,
+                'master_worker_id'=>$service_work->master_worker_id,
+                'opera_log'=>'用户'.$params['user_info']['real_name'].'于'.date('y-m-d H:i:s',time()).'于'.date('Y-m-d H:i:s',time()).'确认了报价单',
+            ];
+            ServiceWorkLogLogic::add($work_log);
+            Db::commit();
+        }
+        catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 5 - 0
app/api/validate/ServiceOrderValidate.php

@@ -47,4 +47,9 @@ class ServiceOrderValidate extends BaseValidate
         return $this->only(['sn']);
     }
 
+    public function scenePrice()
+    {
+        return $this->only(['sn']);
+    }
+
 }

+ 1 - 1
app/common/model/works/ServiceWork.php

@@ -36,7 +36,7 @@ class ServiceWork extends BaseModel
 
     public function getWorkStatusTextAttr($value,$data)
     {
-         $status = [0=>'待派单',1=>'待领单',2=>'待联系',3=>'待上门',4=>'已上门',5=>'待结算',6=>'完成服务'];
+         $status = [0=>'待派单',1=>'待领单',2=>'待联系',3=>'待上门',4=>'已上门',5=>'服务中',6=>'待结算',7=>'待评价',8=>'已完结'];
         return $status[$data['work_status']];
     }
 

+ 34 - 0
app/workerapi/controller/WorksController.php

@@ -56,6 +56,40 @@ class WorksController extends BaseApiController
         return $this->success('预约成功,等待上门', [], 1, 1);
     }
 
+    /**
+     * 师傅确认上门
+     * @return \think\response\Json
+     */
+    public function confirmDoor()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('door', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceWorkLogic::confirmDoor($params);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('操作成功,师傅已上门', [], 1, 1);
+    }
+
+    /**
+     * 师傅确认报价单
+     * @return \think\response\Json
+     */
+    public function confirmPrice()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('price', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceWorkLogic::confirmPrice($params);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('操作成功,师傅已填写报价单,等待用户确认中', [], 1, 1);
+    }
+
     /**
      * 投诉工单列表
      *

+ 18 - 1
app/workerapi/validate/ServiceWorkValidate.php

@@ -35,6 +35,8 @@ class ServiceWorkValidate extends BaseValidate
         'appointment_time' => 'require|dateFormat:Y-m-d H:i:s',
         'finished_time' => 'require',
         'master_worker_id' => 'require',
+        'order_sn'=>'require',
+        'amount'=>'require'
     ];
 
 
@@ -60,7 +62,8 @@ class ServiceWorkValidate extends BaseValidate
         'appointment_time' => '预约上门时间',
         'finished_time' => '结单时间',
         'master_worker_id' => '师傅',
-
+        'order_sn'=>'未获取到扫码信息',
+        'amount'=>'报价'
     ];
 
     /**
@@ -81,4 +84,18 @@ class ServiceWorkValidate extends BaseValidate
         return $this->only(['work_sn','address','appointment_time']);
     }
 
+    /**
+     * 确认上门场景
+     * @return ServiceWorkValidate
+     */
+    public function sceneDoor()
+    {
+        return $this->only(['work_sn','order_sn']);
+    }
+
+    public function scenePrice()
+    {
+        return $this->only(['work_sn','amount']);
+    }
+
 }