allocatr/application/common/command/CheckSmsPlantCommand.php
2025-06-02 18:40:17 +08:00

38 lines
1.3 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\SendMailLogic;
use app\admin\model\OrderDispatch;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class CheckSmsPlantCommand extends Command
{
protected function configure()
{
$this->setName('check:dispatch-sms-plant')
->setDescription('dispatch已预约任务短信提醒每小时执行一次');
}
protected function execute(Input $input, Output $output){
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s'); //两小时通知
$afterTwoHours = date('Y-m-d H:i:s', strtotime('+2 hours'));
$Model->where('status','=',OrderDispatch::STATUS_PLANIT)
->where('plan_time','between',[$now,$afterTwoHours])
->where('notice_num','<',3)
->chunk(100, function ($list){
$ids = [];
foreach ($list as $item) {
$ids[] = $item->id;
SendMailLogic::sendToWorker($item->worker_tel);
}
if(!empty($ids)){
OrderDispatch::whereIn('id',$ids)->update(['notice_num'=>3,'notice_time'=>date('Y-m-d H:i:s')]);
}
});
$output->info('OVER');
}
}