50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?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');
|
||
}
|
||
|
||
|
||
} |