接单成功

This commit is contained in:
xman 2025-06-02 19:05:57 +08:00
parent 5f8a2feac1
commit 17d9f68255
2 changed files with 26 additions and 31 deletions

View File

@ -93,32 +93,20 @@ class OrderLogic
* @return void
*/
public function noWorkerCanGetIt(OrderDispatch $dispatch)
{
$maxNoticeNum = 3;
if($dispatch->notice > $maxNoticeNum){ //超过三次,直接取消
Db::startTrans();
try {
$dispatch->notice_num ++;
$dispatch->notice_time = date('Y-m-d H:i:s');
$remark = '师傅超时未接单,任务取消';
$this->cancelOrderDispatch($dispatch,null,$remark);
Db::commit();
}catch (Exception $exception){
Db::rollback();
$remark = '任务取消异常,请联系技术人员:'.$exception->getMessage();
$dispatch->notice_num ++;
$dispatch->remark = $remark;
$dispatch->notice_time = date('Y-m-d H:i:s');
$dispatch->save();
}
}else{ //未超过最大值,则通知短信通知
{//超过三次,直接取消
Db::startTrans();
try {
$remark = '师傅超时未接单,任务取消';
$this->cancelOrderDispatch($dispatch,null,$remark);
$dispatch->notice_num ++;
$dispatch->notice_time = date('Y-m-d H:i:s');
Db::commit();
}catch (Exception $exception){
Db::rollback();
$remark = '任务取消异常,请联系技术人员:'.$exception->getMessage();
$dispatch->remark = $remark;
$dispatch->save();
//发送短信通知师傅 todo...
$smsLogic = new NoticeLogic();
}
}

View File

@ -8,6 +8,7 @@ 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
@ -15,25 +16,31 @@ class CheckOrderDispatchGotCommand extends Command
protected function configure()
{
$this->setName('check:dispatch-toget')
->setDescription('dispatch未接单通知,每五分钟检测一次');
->setDescription('自动派单未接单检测,五分钟未接单重派派单5分钟执行一次');
}
protected function execute(Input $input, Output $output){
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s',time()-30*60); //创建三十分名以上未接的任务
$now2 = date('Y-m-d H:i:s',time()-30*600); //上次通知在30分钟以前
$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)
->where('notice_time','<=',$now2)
->chunk(100, function ($list) use ($OrderLogic){
foreach ($list as $item) {
$OrderLogic->noWorkerCanGetIt($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');