Sfoglia il codice sorgente

师傅端-预约上门时间【可更新用户地址和预约时间,需要要日志记录】

whitefang 1 anno fa
parent
commit
acff4e8e4a

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

@@ -15,6 +15,7 @@
 namespace app\adminapi\logic\works;
 
 
+use app\common\model\dict\DictData;
 use app\common\model\works\ServiceWork;
 use app\common\logic\BaseLogic;
 use app\common\model\works\ServiceWorkLog;
@@ -63,4 +64,45 @@ class ServiceWorkLogic extends BaseLogic
             return false;
         }
     }
+
+    /**
+     * 预约成功,等待上门
+     * @return false|void
+     */
+    public static function appointWork($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('工单不存在');
+            }
+
+            if($work->work_status != 2){
+                throw new Exception('请勿重复点击');
+            }
+
+            //验证更改的预约时间必须是在领单时间内的半小内修改,否则不允许修改
+            if(strtotime($work->appointment_time) != strtotime($params['appointment_time']) && (time()-$work->receive_time)>1800){
+                throw new Exception('距离领单时间已超过半小时,无法修改预约时间,请联系客服');
+            }
+
+            $work->work_status = 3;//待上门
+            $work->appointment_time = strtotime($params['appointment_time']);
+            $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()).'联系了客户,确认了于'.$params['appointment_time'].$params['address'].'预约上门',
+            ];
+            ServiceWorkLogLogic::add($work_log);
+            Db::commit();
+        }
+        catch (\Exception $e) {
+            self::setError($e->getMessage());
+            return false;
+        }
+    }
 }

+ 7 - 2
app/common/model/works/ServiceWork.php

@@ -34,13 +34,13 @@ class ServiceWork extends BaseModel
         return $this->belongsTo(MasterWorker::class, 'master_worker_id', 'id');
     }
 
-    public function getWorkStatusAttr($value,$data)
+    public function getWorkStatusTextAttr($value,$data)
     {
          $status = [0=>'待派单',1=>'待领单',2=>'待联系',3=>'待上门',4=>'已上门',5=>'待结算',6=>'完成服务'];
         return $status[$data['work_status']];
     }
 
-    public function getServiceStatusAttr($value,$data)
+    public function getServiceStatusTextAttr($value,$data)
     {
         $status = [0=>'已下单',1=>'服务中',2=>'部分完成',3=>'已完成',4=>'已取消'];
         return $status[$data['service_status']];
@@ -50,5 +50,10 @@ class ServiceWork extends BaseModel
     {
         return !empty($data['appointment_time'])?date('Y-m-d H:i:s',$data['appointment_time']):'';
     }
+
+    public function getReceiveTimeAttr($value,$data)
+    {
+        return !empty($data['receive_time'])?date('Y-m-d H:i:s',$data['receive_time']):'';
+    }
     
 }

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

@@ -39,6 +39,23 @@ class WorksController extends BaseApiController
         return $this->success('领取成功', [], 1, 1);
     }
 
+    /**
+     * 预约上门
+     * @return \think\response\Json
+     */
+    public function appointWork()
+    {
+        $params = (new ServiceWorkValidate())->post()->goCheck('appoint', [
+            'user_id' => $this->userId,
+            'user_info' => $this->userInfo
+        ]);
+        $result = ServiceWorkLogic::appointWork($params);
+        if (false === $result) {
+            return $this->fail(ServiceWorkLogic::getError());
+        }
+        return $this->success('预约成功,等待上门', [], 1, 1);
+    }
+
     /**
      * 投诉工单列表
      *

+ 2 - 1
app/workerapi/lists/ServiceWorkLists.php

@@ -67,7 +67,8 @@ class ServiceWorkLists extends BaseWorkerDataLists
         }
 
         $list = ServiceWork::where($where)
-            ->field(['work_sn', 'address', 'title', 'work_status', 'service_status', 'appointment_time'])
+            ->field(['work_sn', 'address', 'title', 'work_status', 'service_status', 'appointment_time','receive_time'])
+            ->append(['work_status_text','service_status_text'])
             ->limit($this->limitOffset, $this->limitLength)
             ->order(['id' => 'desc'])
             ->select()

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

@@ -32,7 +32,7 @@ class ServiceWorkValidate extends BaseValidate
         'service_status' => 'require',
         'dispatch_time' => 'require',
         'receive_time' => 'require',
-        'appointment_time' => 'require',
+        'appointment_time' => 'require|dateFormat:Y-m-d H:i:s',
         'finished_time' => 'require',
         'master_worker_id' => 'require',
     ];
@@ -72,4 +72,13 @@ class ServiceWorkValidate extends BaseValidate
         return $this->only(['work_sn']);
     }
 
+    /**
+     * 预约上门场景
+     * @return ServiceWorkValidate
+     */
+    public function sceneAppoint()
+    {
+        return $this->only(['work_sn','address','appointment_time']);
+    }
+
 }