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

76 lines
2.8 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 CheckOrdeRecordCommand extends Command
{
protected $title = 'dispatch跟进记录通知,每天9点1分执行';
protected function configure()
{
$this->setName('check:dispatch-record-notice')
->setDescription($this->title);
}
protected function execute(Input $input, Output $output){
$Model = new OrderDispatchRecord();
$now = date('Y-m-d H:i:s');
$Model->where('notice_time','<=',$now)
->where('need_notice',1)
->where('status',0)
->chunk(100, function ($list) {
$ids = [];
$dispatchIds = [];
try {
foreach ($list as $item) {
$ids[] = $item->id;
$dispatchIds[] = $item->dispatch_id;
$existDispatchIds = [];
//修改状态
if($item->need_notice == 1){ //需要通知
if(in_array($item->dispatch_id,$existDispatchIds)){
continue;
}
$dispatch = OrderDispatch::get($item->dispatch_id,['orderb']);
Message::create([
'to_id' => $dispatch->admin_id,
'type' => 1,
'title' => '派单任务跟进提示',
'content' => '【订单跟进提示】您有一条待跟进订单,订单编号:'.$dispatch->orderb->order_no.',请及时关注。'
]);
$existDispatchIds[] = $item->dispatch_id;
}
}
OrderDispatchRecord::whereIn('id',$ids)->where('status',0)->update(['status'=>1]);
$count = OrderDispatch::whereIn('id',$dispatchIds)->where('follow',1)->update(['follow'=>0]);
echo 'count:'.$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');
}
}