|
|
@@ -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;
|
|
|
@@ -53,6 +54,46 @@ class AutomaticDispatch extends Command
|
|
|
if ($h >= 8 && $h <= 22) {
|
|
|
$this->startTask();
|
|
|
}
|
|
|
+
|
|
|
+ //异常工单:上门时间超过两小时状态未变更已上门
|
|
|
+ $this->workAnomalous();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 异常工单:上门时间超过两小时状态未变更已上门
|
|
|
+ */
|
|
|
+ protected function workAnomalous()
|
|
|
+ {
|
|
|
+ $size = 100;
|
|
|
+ $startTime = time() - 7200; // 当前时间减去7200秒(2小时)
|
|
|
+ $list = ServiceWork::alias("a")
|
|
|
+ ->leftJoin('service_work_anomalous b','a.id = b.work_id')
|
|
|
+ ->where('a.work_status',3)
|
|
|
+ ->where('a.service_status','<',2)
|
|
|
+ ->where('a.refund_approval',0)
|
|
|
+ ->where('a.work_pay_status',1)
|
|
|
+ ->where('a.appointment_time','<=', $startTime)
|
|
|
+ ->whereNull('b.id')
|
|
|
+ ->field('a.id,a.appointment_time,b.id as anomalous_id')
|
|
|
+ ->order('a.create_time','asc')
|
|
|
+ ->limit($size)
|
|
|
+ ->select()
|
|
|
+ ->toArray();
|
|
|
+ if (!$list) {
|
|
|
+ return ;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach($list as $item) {
|
|
|
+ try {
|
|
|
+ ServiceWorkAnomalous::create([
|
|
|
+ 'work_id' => $item['id'],
|
|
|
+ 'reason_type' => 3,
|
|
|
+ 'reason' => '上门时间超过两小时状态未变更已上门',
|
|
|
+ ]);
|
|
|
+ } catch (\Exception $e) {
|
|
|
+ Log::write('异常工单:'.$e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -67,15 +108,11 @@ class AutomaticDispatch extends Command
|
|
|
$startTime = strtotime(date('Y-m-d 00:00:00'));
|
|
|
$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 +123,6 @@ class AutomaticDispatch extends Command
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
- $isExec = 1;//是否派单成功
|
|
|
-
|
|
|
foreach($list as $item) {
|
|
|
try {
|
|
|
//优先平台工程师派单
|
|
|
@@ -96,20 +131,21 @@ 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' => '自动派单:找不到工程师',
|
|
|
+ ]);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
- print_r($e->getMessage());
|
|
|
Log::write('自动派单异常:'.$e->getMessage());
|
|
|
}
|
|
|
-
|
|
|
- if ($isExec == 0) {
|
|
|
- ServiceWork::where('id',$item['id'])->update([
|
|
|
- 'exec_time' => time(),
|
|
|
- ]);
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -353,7 +389,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 = [
|