allocatr/application/common/command/CheckOrderDispatchGotCommand.php
2025-07-03 11:34:42 +08:00

153 lines
5.7 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\common\command;
use app\admin\controller\AutoDispatchLogic;
use app\admin\model\Order;
use app\admin\model\OrderDispatch;
use app\common\Logic\OrderLogic;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
use think\Hook;
class CheckOrderDispatchGotCommand extends Command
{
protected $title = '【自动派单未接单检测,五分钟未接单,重派派单】/【自动派接单五分钟未预约,重新派单】/【自动派单上门时间已到,未完成上门】,每分钟执行一次';
protected function configure()
{
$this->setName('check:dispatch-toget')
->setDescription($this->title);
}
protected function execute(Input $input, Output $output){
$this->_toget();
$this->_toplan();
$this->_toarrive();
$this->_tofinished();
$output->info('OVER');
}
//未接单检测
private function _toget(){
try {
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s', time() - 5 * 60); //创建三十分名以上未接的任务
$OrderLogic = new OrderLogic();
$Model->where('status', OrderDispatch::STATUS_TOGET)
->where('type', 2)
->where('worker_id','!=',1059)
->where('create_time', '<=', $now)
->chunk(100, function ($list) use ($OrderLogic) {
foreach ($list as $item) {
try {
//取消旧单
$OrderLogic->noWorkerCanGetIt($item,null,true);
//自动重派新单
$order = Order::get($item->order_id);
AutoDispatchLogic::autoDispatch($order,null,true);
echo 'succ:' . $item->id . PHP_EOL;
} catch (Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
}
}
});
}catch (Exception $exception){
echo $exception->getMessage(). PHP_EOL;
Db::name('debug_log')->insert([
'title' => $this->title,
'content' => '未接,错误内容:'.$exception->getMessage().',错误行:'. $exception->getLine().',错误文件:'. $exception->getFile(),
'create_time' => date('Y-m-d H:i:s', time())
]);
}
}
//未预约
private function _toplan(){
try {
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s', time() - 5 * 60); //创建三十分名以上未接的任务
$OrderLogic = new OrderLogic();
$Model->where('status', OrderDispatch::STATUS_GOTIT)
->where('type', 2)
->where('got_time', '<=', $now)
->chunk(100, function ($list) use ($OrderLogic) {
foreach ($list as $item) {
try {
//取消旧单
$OrderLogic->noWorkerCanGetIt($item,null,true);
//自动重派新单
$order = Order::get($item->order_id);
AutoDispatchLogic::autoDispatch($order,null,true);
echo 'succ:' . $item->id . PHP_EOL;
} catch (Exception $exception) {
echo $exception->getMessage() . PHP_EOL;
}
}
});
}catch (Exception $exception){
echo $exception->getMessage(). PHP_EOL;
Db::name('debug_log')->insert([
'title' => $this->title,
'content' => '未预约,错误内容:'.$exception->getMessage().',错误行:'. $exception->getLine().',错误文件:'. $exception->getFile(),
'create_time' => date('Y-m-d H:i:s', time())
]);
}
}
//预约时间过了未上门检测
private function _toarrive(){
try {
//自动派单,改为待跟进
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s');
$count = $Model->whereIn('status', [OrderDispatch::STATUS_PLANIT,OrderDispatch::STATUS_OVERTIME])
->where('type', 2)
->where('follow', 1)
->where('plan_time', '<=', $now)
->update(['follow'=>0]);
echo 'arrive_count:'. $count. PHP_EOL;
}catch (Exception $exception){
echo $exception->getMessage(). PHP_EOL;
Db::name('debug_log')->insert([
'title' => $this->title,
'content' => '超时,错误内容:'.$exception->getMessage().',错误行:'. $exception->getLine().',错误文件:'. $exception->getFile(),
'create_time' => date('Y-m-d H:i:s', time())
]);
}
}
private function _tofinished(): void
{
//https://f1jo9ghdket.feishu.cn/wiki/PCK8wtWnSihQrukCRq1c3nCynyd
//5.自动订单派单完之后不需要进入待跟进状态当师傅确认上门之后10分钟之内没有更新进度首次更新进度则需要进入待跟进状态需要人为跟进。
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s', time() -600); //创建三十分名以
$count = $Model->where('status', OrderDispatch::STATUS_CLOCK)
->where('type', 2)
->where('follow', 1)
->whereNull('estimated_finish_time')
->where('arrive_time', '<=', $now)
->update(['follow'=>0]);
echo '已上门未更新:'. $count. PHP_EOL;
}
}