|
@@ -45,56 +45,52 @@ class AutomaticDispatch extends Command
|
|
|
*/
|
|
*/
|
|
|
protected function autoDispatch()
|
|
protected function autoDispatch()
|
|
|
{
|
|
{
|
|
|
- $size = 30;
|
|
|
|
|
|
|
+ $size = 100;
|
|
|
$startTime = strtotime(date('Y-m-d 00:00:00'));
|
|
$startTime = strtotime(date('Y-m-d 00:00:00'));
|
|
|
$endTime = strtotime(date('Y-m-d 23:59:59'));
|
|
$endTime = strtotime(date('Y-m-d 23:59:59'));
|
|
|
- while(true) {
|
|
|
|
|
-
|
|
|
|
|
- // 获取当前时间的前五分钟时间戳
|
|
|
|
|
- $fiveMinutesAgo = time() - 120; // 300 秒 = 2 分钟
|
|
|
|
|
- $list = ServiceWork::where('work_status',0)
|
|
|
|
|
- ->where('service_status',0)
|
|
|
|
|
- ->where('work_pay_status',1)
|
|
|
|
|
- ->where(function ($query) use ($fiveMinutesAgo) {
|
|
|
|
|
- $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
|
|
|
|
|
- })
|
|
|
|
|
- ->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')
|
|
|
|
|
- ->order('create_time','asc')
|
|
|
|
|
- ->limit($size)
|
|
|
|
|
- ->select()
|
|
|
|
|
- ->toArray();
|
|
|
|
|
- if (!$list) {
|
|
|
|
|
- sleep(5);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 获取当前时间的前五分钟时间戳
|
|
|
|
|
+ $fiveMinutesAgo = time() - 120; // 300 秒 = 2 分钟
|
|
|
|
|
+ $list = ServiceWork::where('work_status',0)
|
|
|
|
|
+ ->where('service_status',0)
|
|
|
|
|
+ ->where('work_pay_status',1)
|
|
|
|
|
+ ->where(function ($query) use ($fiveMinutesAgo) {
|
|
|
|
|
+ $query->where('exec_time', 0)->whereOr('exec_time', '<', $fiveMinutesAgo);
|
|
|
|
|
+ })
|
|
|
|
|
+ ->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')
|
|
|
|
|
+ ->order('create_time','asc')
|
|
|
|
|
+ ->limit($size)
|
|
|
|
|
+ ->select()
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
+ if (!$list) {
|
|
|
|
|
+ return ;
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- $isExec = 1;//是否派单成功
|
|
|
|
|
|
|
+ $isExec = 1;//是否派单成功
|
|
|
|
|
|
|
|
- foreach($list as $item) {
|
|
|
|
|
- try {
|
|
|
|
|
- //优先平台工程师派单
|
|
|
|
|
- $res = $this->platformWorker($item);
|
|
|
|
|
|
|
+ foreach($list as $item) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ //优先平台工程师派单
|
|
|
|
|
+ $res = $this->platformWorker($item);
|
|
|
|
|
+ if ($res === false) {
|
|
|
|
|
+ //门店负责人派单
|
|
|
|
|
+ $res = $this->teamWorker($item);
|
|
|
if ($res === false) {
|
|
if ($res === false) {
|
|
|
- //门店负责人派单
|
|
|
|
|
- $res = $this->teamWorker($item);
|
|
|
|
|
- if ($res === false) {
|
|
|
|
|
- $isExec = 0;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ $isExec = 0;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
- } catch (\Exception $e) {
|
|
|
|
|
- print_r($e->getMessage());
|
|
|
|
|
- Log::write('自动派单异常:'.$e->getMessage());
|
|
|
|
|
- sleep(5);
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if ($isExec == 0) {
|
|
|
|
|
- ServiceWork::where('id',$item['id'])->update([
|
|
|
|
|
- 'exec_time' => time(),
|
|
|
|
|
- ]);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ print_r($e->getMessage());
|
|
|
|
|
+ Log::write('自动派单异常:'.$e->getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ if ($isExec == 0) {
|
|
|
|
|
+ ServiceWork::where('id',$item['id'])->update([
|
|
|
|
|
+ 'exec_time' => time(),
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -144,7 +140,6 @@ class AutomaticDispatch extends Command
|
|
|
->limit(100)
|
|
->limit(100)
|
|
|
->select()
|
|
->select()
|
|
|
->toArray();
|
|
->toArray();
|
|
|
-
|
|
|
|
|
$queue = [];
|
|
$queue = [];
|
|
|
foreach($worker as $key => $value) {
|
|
foreach($worker as $key => $value) {
|
|
|
//过滤已接过此单的师傅
|
|
//过滤已接过此单的师傅
|
|
@@ -152,8 +147,7 @@ class AutomaticDispatch extends Command
|
|
|
if ($exists) {
|
|
if ($exists) {
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
//计算地理效率得分
|
|
//计算地理效率得分
|
|
|
$realDistance = ceil($value['real_distance'] / 1000);
|
|
$realDistance = ceil($value['real_distance'] / 1000);
|
|
|
$travelTime = $realDistance * 2;//预计每公里行驶2分钟
|
|
$travelTime = $realDistance * 2;//预计每公里行驶2分钟
|