allocatr/application/common/command/CheckTTSOverTimeCommand.php
2025-06-06 15:49:46 +08:00

70 lines
2.4 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\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 CheckTTSOverTimeCommand extends Command
{
protected $title = 'dispatch超时未完成任务语音通知每5分钟执行一次';
protected function configure()
{
$this->setName('check:dispatch-tts-overtime')
->setDescription($this->title);
}
protected function execute(Input $input, Output $output){
$Model = new OrderDispatch();
$now = date('Y-m-d H:i:s');
$Model->where('status','=',OrderDispatch::STATUS_CLOCK)
->where('type',2)
->where('estimated_finish_time','<',$now)
->where('tts_notice','<',3)
->chunk(100, function ($list) {
$ids = [];
$logs = [];
try {
foreach ($list as $item) {
$ids[] = $item->id;
//修改状态
$logs[] = [
'dispatch_id' => $item->id,
'order_id'=>$item->order_id,
'type' => 3,
'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);
}
if(!empty($ids)){
$count = OrderDispatch::whereIn('id',$ids)->update(['follow'=>0,'tts_notice'=>3,'tts_check_time'=>date('Y-m-d H:i:s')]);
echo $count.PHP_EOL;
}
}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())
]);
}
});
$output->info('OVER');
}
}