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