Ver Fonte

修改自动派单2次以上,标记异常工单

dongxiaoqin há 11 meses atrás
pai
commit
bca86003ce

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

@@ -974,7 +974,6 @@ class ServiceWorkLogic extends BaseLogic
             $work->dispatch_time = 0;
             $work->first_contact_time = 0;
             $work->estimated_finish_time = 0;
-            $work->exec_time = 0;
             $work->save();
 
             $work_log = [

+ 13 - 15
app/common/command/AutomaticDispatch.php

@@ -10,6 +10,7 @@ use app\adminapi\service\WeCallService;
 use app\common\model\works\ServiceWork;
 use app\common\model\goods_time\GoodsTime;
 use app\common\model\master_worker\MasterWorker;
+use app\common\model\works\ServiceWorkAnomalous;
 use app\common\model\master_worker\MasterWorkerTeam;
 use app\common\model\works\ServiceWorkAllocateWorkerLog;
 use app\workerapi\logic\ServiceWorkerAllocateWorkerLogic;
@@ -51,7 +52,7 @@ class AutomaticDispatch extends Command
         //执行外呼任务
         $h = date('H');
         if ($h >= 8 && $h <= 22) {
-            $this->startTask();
+            //$this->startTask();
         }
     }
 
@@ -68,14 +69,11 @@ class AutomaticDispatch extends Command
         $endTime = strtotime(date('Y-m-d 23:59:59'));
        
         // 获取当前时间的前五分钟时间戳
-        $fiveMinutesAgo = time() - 120; // 300 秒 = 2 分钟
         $list = ServiceWork::where('work_status',0)
             ->where('service_status',0)
             ->where('refund_approval',0)
             ->where('work_pay_status',1)
-            ->where(function ($query) use ($fiveMinutesAgo) {
-                $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
-            })
+            ->where('exec_num','<', 2)
             ->where('appointment_time','between', [$startTime, $endTime])
             ->field('id,category_type,goods_category_id,service_area_id,lon,lat,province,city,title,appointment_time,address,mobile,work_sn')
             ->order('create_time','asc')
@@ -86,8 +84,6 @@ class AutomaticDispatch extends Command
             return ;
         }
 
-        $isExec = 1;//是否派单成功
- 
         foreach($list as $item) {     
             try {
                 //优先平台工程师派单
@@ -96,7 +92,15 @@ class AutomaticDispatch extends Command
                     //门店负责人派单
                     $res = $this->teamWorker($item);
                     if ($res === false) {
-                        $isExec = 0;
+                        ServiceWork::where('id',$item['id'])
+                            ->update([
+                                'exec_num' => 2,
+                            ]);
+                        ServiceWorkAnomalous::create([
+                            'work_id' => $item['id'],
+                            'reason_type' => 2,
+                            'reason' => '自动派单:找不到工程师',
+                        ]);
                     }
                 }
 
@@ -104,12 +108,6 @@ class AutomaticDispatch extends Command
                 print_r($e->getMessage());
                 Log::write('自动派单异常:'.$e->getMessage());
             }
-
-            if ($isExec == 0) {
-                ServiceWork::where('id',$item['id'])->update([
-                    'exec_time' => time(),
-                ]);
-            }
         }
     }
 
@@ -353,7 +351,7 @@ class AutomaticDispatch extends Command
                 'work_status'=>1,
                 'estimated_finish_time' => $estimated_finish_time,
                 'dispatch_time'=>time(),
-                'exec_time' => time(),
+                'exec_num' => Db::raw('exec_num + 1'),
             ]);
             MasterWorker::setWorktotal('inc',$masterWorkerId);
             $work_log = [

+ 11 - 3
app/common/command/CancelDispatch.php

@@ -7,6 +7,7 @@ use think\console\Output;
 use think\console\Command;
 use app\common\model\works\ServiceWork;
 use app\common\model\master_worker\MasterWorkerTeam;
+use app\common\model\works\ServiceWorkAnomalous;
 
 class CancelDispatch extends Command
 {
@@ -30,7 +31,7 @@ class CancelDispatch extends Command
         $list = ServiceWork::where('work_status',1)
                 ->where('dispatch_time','<',strtotime('-10 minutes'))
                 ->where('dispatch_time','>=',strtotime('-1 days'))
-                ->field('id,tenant_id,master_worker_id,appointment_time')
+                ->field('id,tenant_id,master_worker_id,appointment_time,exec_num')
                 ->limit(100)
                 ->select()
                 ->toArray();
@@ -43,12 +44,19 @@ class CancelDispatch extends Command
                             'dispatch_time' => 0,
                             'first_contact_time' => 0,
                             'estimated_finish_time' => 0,
-                            'exec_time' => 0,
                         ]);
             if ($item['tenant_id'] > 0) {
                 $updateData = date("H",strtotime($item['appointment_time'])) < 12 ? ['am_order' => Db::raw('am_order - 1')] : ['pm_order' => Db::raw('pm_order - 1')];
                 MasterWorkerTeam::where('master_worker_id',$item['master_worker_id'])->where('tenant_id',$item['tenant_id'])->update($updateData);
-                
+            }
+
+            //自动派单2次后,标记工单异常
+            if ($item['exec_num'] >= 2) {
+                ServiceWorkAnomalous::create([
+                    'work_id' => $item['id'],
+                    'reason_type' => 2,
+                    'reason' => '自动派单:2次无人接单',
+                ]);
             }
         }