53 lines
2.0 KiB
PHP
53 lines
2.0 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;
|
||
use think\Db;
|
||
use think\Exception;
|
||
|
||
class CheckSmsPlantCommand extends Command
|
||
{
|
||
protected $title = 'dispatch预约任务短信提醒,每5分钟执行一次';
|
||
protected function configure()
|
||
{
|
||
$this->setName('check:dispatch-sms-plant')
|
||
->setDescription($this->title);
|
||
}
|
||
|
||
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->whereIn('status',[OrderDispatch::STATUS_PLANIT,OrderDispatch::STATUS_OVERTIME])
|
||
->where('plan_time','between',[$now,$afterTwoHours])
|
||
->where('notice_num','<',3)
|
||
->chunk(100, function ($list){
|
||
$ids = [];
|
||
foreach ($list as $item) {
|
||
$ids[] = $item->id;
|
||
try {
|
||
SendMailLogic::sendToWorker($item->worker_tel);
|
||
echo '短信发送完成:'.$item->id.PHP_EOL;
|
||
}catch (Exception $exception){
|
||
|
||
echo '短信发送失败:'.$exception->getMessage().PHP_EOL;
|
||
|
||
Db::name('debug_log')->insert([
|
||
'title' => $this->title,
|
||
'content' => '错误内容:'.$exception->getMessage().',错误行:'. $exception->getLine().',错误文件:'. $exception->getFile(),
|
||
'create_time' => date('Y-m-d H:i:s', time())
|
||
]);
|
||
}
|
||
}
|
||
if(!empty($ids)){
|
||
OrderDispatch::whereIn('id',$ids)->update(['notice_num'=>3,'notice_time'=>date('Y-m-d H:i:s')]);
|
||
}
|
||
});
|
||
$output->info('OVER');
|
||
}
|
||
} |