69 lines
2.5 KiB
PHP
69 lines
2.5 KiB
PHP
<?php
|
||
|
||
namespace app\common\command;
|
||
|
||
use app\admin\model\Message;
|
||
use app\admin\model\OrderDispatch;
|
||
use app\admin\model\OrderDispatchRecord;
|
||
|
||
use app\admin\model\TtsLog;
|
||
use app\common\Logic\NoticeLogic;
|
||
use think\console\Command;
|
||
use think\console\Input;
|
||
use think\console\Output;
|
||
use think\Db;
|
||
use think\Exception;
|
||
|
||
class CheckTTSPlantCommand extends Command
|
||
{
|
||
protected $title = 'dispatch预约任务语音提醒,每5分钟执行一次';
|
||
|
||
protected function configure()
|
||
{
|
||
$this->setName('check:dispatch-tts-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('+1 hours'));
|
||
|
||
$Model->where('status','=',OrderDispatch::STATUS_PLANIT)
|
||
->where('type','=',2)
|
||
->where('plan_time','between',[$now,$afterTwoHours])
|
||
->where('tts_notice','<',2)
|
||
->chunk(100, function ($list) {
|
||
$ids = [];
|
||
$logs = [];
|
||
foreach ($list as $item) {
|
||
|
||
try {
|
||
$ids[] = $item->id;
|
||
//修改状态
|
||
$logs[] = [
|
||
'dispatch_id' => $item->id,
|
||
'order_id'=>$item->order_id,
|
||
'type' => 2,
|
||
'outid' => md5(time().rand(1000,9999).rand(1000,9999)),
|
||
'create_time' => date('Y-m-d H:i:s'),
|
||
'status' => 0,
|
||
'update_time' => date('Y-m-d H:i:s')
|
||
];
|
||
(new TtsLog())->insertAll($logs);
|
||
}catch (Exception $exception){
|
||
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)){
|
||
$count = OrderDispatch::whereIn('id',$ids)->update(['tts_notice'=>2,'tts_check_time'=>date('Y-m-d H:i:s')]);
|
||
echo $count.PHP_EOL;
|
||
}
|
||
});
|
||
$output->info('OVER');
|
||
}
|
||
} |