Quellcode durchsuchen

绑定工程师-加单

whitefang vor 1 Jahr
Ursprung
Commit
d0aa281c8a

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

@@ -313,4 +313,21 @@ class ServiceOrderController extends BaseApiController
         return $this->data($result);
     }
 
+    /**
+     *  绑定工程师-设置为加单
+     * @return \think\response\Json
+    */
+    public function bindWorkerAndWork()
+    {
+        $params = (new ServiceOrderValidate())->post()->goCheck('bindWorkerAndWork', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceOrderLogic::bindWorkerAndWork($params);
+        if (false === $result) {
+            return $this->fail(ServiceOrderLogic::getError());
+        }
+        return $this->success('绑定成功', [], 1, 1);
+    }
+
 }

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

@@ -1094,4 +1094,39 @@ class ServiceOrderLogic extends BaseLogic
         ];
     }
 
+    /**
+     * 绑定工程师-设置为加单
+     * * @param array $params
+     * * @return array|false
+     */
+    public static function bindWorkerAndWork(array $params)
+    {
+        Db::startTrans();
+        try {
+            $order = RechargeOrder::where(['id'=>$params['order_id'],'user_id'=>$params['user_id']])->findOrEmpty();
+            if($order->isEmpty()){
+                throw new Exception('订单不存在');
+            }
+            $work = ServiceWork::where(['id'=>$order['work_id']])->findOrEmpty();
+            if($work->isEmpty()){
+                throw new Exception('工单不存在');
+            }
+            if($work['work_status']!=WorkEnum::WORK_STATUS_WAIT_SERVICE){
+                throw new Exception('工单状态不正确,无法绑定');
+            }
+            $worker = MasterWorker::where('id',$params['worker_id'])->findOrEmpty();
+            if($worker->isEmpty()){
+                throw new Exception('工程师不存在');
+            }
+            $work->master_worker_id = $params['worker_id'];
+            $work->work_status = WorkEnum::WORK_STATUS_WAIT_WORKER;
+            $work->work_type = 2;//加单状态
+            $work->save();
+            Db::commit();
+        } catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
+
 }

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

@@ -24,6 +24,7 @@ class ServiceOrderValidate extends BaseValidate
         'contact_people' => 'require',
         'lon' => 'require',
         'lat' => 'require',
+        'worker_id'=>'require'
     ];
 
 
@@ -39,6 +40,7 @@ class ServiceOrderValidate extends BaseValidate
         'contact_people.require' => '联系人不存在',
         'lon.require' => '经度不存在',
         'lat.require' => '纬度不存在',
+        'worker_id.require' => '工程师不存在',
     ];
 
 
@@ -113,4 +115,9 @@ class ServiceOrderValidate extends BaseValidate
         return $this->only(['sn','appointment_time']);
     }
 
+    public function sceneBindWorkerAndWork()
+    {
+        return $this->only(['order_id','worker_id']);
+    }
+
 }

+ 3 - 0
app/common/enum/WorkEnum.php

@@ -8,4 +8,7 @@ class WorkEnum
     const UN_PAY_STATUS = 0;
     const IS_PAY_STATUS = 1;
     const EN_PAY_STATUS = 2;
+
+    const WORK_STATUS_WAIT_SERVICE = 0;//待派单
+    const WORK_STATUS_WAIT_WORKER = 1;//待领单
 }