allocatr/application/common/command/CheckOrderDispatchGotCommand.php
2025-06-02 19:05:57 +08:00

50 lines
1.5 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\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\Exception;
use think\Hook;
class CheckOrderDispatchGotCommand extends Command
{
protected function configure()
{
$this->setName('check:dispatch-toget')
->setDescription('自动派单未接单检测,五分钟未接单重派派单5分钟执行一次');
}
protected function execute(Input $input, Output $output){
$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('create_time','<=',$now)
->chunk(100, function ($list) use ($OrderLogic){
foreach ($list as $item) {
try {
//取消旧单
$OrderLogic->noWorkerCanGetIt($item);
//自动重派新单
$order = Order::get($item->order_id);
$orderService = new \app\admin\controller\Order();
$orderService->autoDispatch($order);
}catch (Exception $exception){
}
}
});
$output->info('OVER');
}
}