From 696919950d3fb3d9c0e70822bf8da38273e9a527 Mon Sep 17 00:00:00 2001 From: xman <1946321327@qq.com> Date: Fri, 6 Jun 2025 15:49:46 +0800 Subject: [PATCH] =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/common/Logic/NoticeLogic.php | 88 +++++++++---------- .../common/command/CheckOrdeRecordCommand.php | 54 +++++++----- .../command/CheckOrderDispatchGotCommand.php | 9 +- .../common/command/CheckSmsPlantCommand.php | 10 ++- .../command/CheckTTSOverTimeCommand.php | 51 +++++++---- .../common/command/CheckTTSPlantCommand.php | 39 +++++--- .../common/command/CheckTTSTaskCommand.php | 20 ++++- 7 files changed, 170 insertions(+), 101 deletions(-) diff --git a/application/common/Logic/NoticeLogic.php b/application/common/Logic/NoticeLogic.php index 8f95ad4..d56aaf8 100644 --- a/application/common/Logic/NoticeLogic.php +++ b/application/common/Logic/NoticeLogic.php @@ -25,56 +25,54 @@ class NoticeLogic public function callIt($log) { - try { - $dispatch = OrderDispatch::get($log->dispatch_id); - //1=派单,2=提前通知,3=超时通知 - $ttsCode = null; - $dispatch->tts_check_time = date('Y-m-d H:i:s',time()+5*60); - if($log->type == 1) - { - $dispatch->tts_notice = 1; - if($dispatch->type == 1){ - $ttsCode = self::TTS_DISPATCH1; - $dispatch->save(); - }else{ - $ttsCode = self::TTS_DISPATCH2; - } - }elseif($log->type == 2) - { - $dispatch->tts_notice = 2; - $ttsCode = self::TTS_GOGOGO; - }elseif($log->type == 3){ - $dispatch->tts_notice = 3; - $ttsCode = self::TTS_OVER_FINISHED; - } - if(empty($ttsCode)){ - $log->status = -1; - $log->content = 'TTSID为空'; - $log->save(); - return; - } - $status = config('alibaba_dyvms.status'); - - if($status){ - $reponse = DyvmsService::getInstance()->call($dispatch->worker_tel, $ttsCode, md5(time())); - - if($reponse->statusCode == 200 && $reponse->body->code == 'OK'){ - $log->status = 1; - $log->callId = $reponse->body->callId; - $log->save(); - }else{ - $log->status = -1; - $log->content = $reponse->body->message; - $log->save(); - } + $dispatch = OrderDispatch::get($log->dispatch_id); + //1=派单,2=提前通知,3=超时通知 + $ttsCode = null; + $dispatch->tts_check_time = date('Y-m-d H:i:s',time()+5*60); + if($log->type == 1) + { + $dispatch->tts_notice = 1; + if($dispatch->type == 1){ + $ttsCode = self::TTS_DISPATCH1; + $dispatch->save(); }else{ - throw new Exception('语音通知服务未开启'); + $ttsCode = self::TTS_DISPATCH2; } - }catch (Exception $exception){ + }elseif($log->type == 2) + { + $dispatch->tts_notice = 2; + $ttsCode = self::TTS_GOGOGO; + }elseif($log->type == 3){ + $dispatch->tts_notice = 3; + $ttsCode = self::TTS_OVER_FINISHED; + } + if(empty($ttsCode)){ $log->status = -1; - $log->content = $exception->getMessage(); + $log->content = 'TTSID为空'; $log->save(); + return; + } + + $status = config('alibaba_dyvms.status'); + + if($status){ + $reponse = DyvmsService::getInstance()->call($dispatch->worker_tel, $ttsCode, md5(time())); + + if($reponse->statusCode == 200 && $reponse->body->code == 'OK'){ + $log->status = 1; + $log->callId = $reponse->body->callId; + $log->save(); + }else{ + $log->status = -1; + $log->content = $reponse->body->message; + $log->save(); + } + }else{ + $log->status = -1; + $log->content = 'TTSID为空'; + $log->save(); + //throw new Exception('语音通知服务未开启'); } } diff --git a/application/common/command/CheckOrdeRecordCommand.php b/application/common/command/CheckOrdeRecordCommand.php index b9b31fd..272d18f 100644 --- a/application/common/command/CheckOrdeRecordCommand.php +++ b/application/common/command/CheckOrdeRecordCommand.php @@ -11,13 +11,16 @@ 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('dispatch跟进记录通知,每天9点1分执行'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -29,32 +32,41 @@ class CheckOrdeRecordCommand extends Command ->chunk(100, function ($list) { $ids = []; $dispatchIds = []; - foreach ($list as $item) { - $ids[] = $item->id; - $dispatchIds[] = $item->dispatch_id; + try { + foreach ($list as $item) { + $ids[] = $item->id; + $dispatchIds[] = $item->dispatch_id; - $existDispatchIds = []; + $existDispatchIds = []; - //修改状态 - if($item->need_notice == 1){ //需要通知 - if(in_array($item->dispatch_id,$existDispatchIds)){ - continue; + //修改状态 + 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; } - $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()) + ]); } - 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; + }); $output->info('OVER'); diff --git a/application/common/command/CheckOrderDispatchGotCommand.php b/application/common/command/CheckOrderDispatchGotCommand.php index ac10b22..6aa3477 100644 --- a/application/common/command/CheckOrderDispatchGotCommand.php +++ b/application/common/command/CheckOrderDispatchGotCommand.php @@ -9,15 +9,17 @@ use app\common\Logic\OrderLogic; use think\console\Command; use think\console\Input; use think\console\Output; +use think\Db; use think\Exception; use think\Hook; class CheckOrderDispatchGotCommand extends Command { + protected $title = '【自动派单未接单检测,五分钟未接单,重派派单】/【自动派单上门时间已到,未完成上门】,每分钟执行一次'; protected function configure() { $this->setName('check:dispatch-toget') - ->setDescription('【自动派单未接单检测,五分钟未接单,重派派单】/【自动派单上门时间已到,未完成上门】,每分钟执行一次'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -72,6 +74,11 @@ class CheckOrderDispatchGotCommand extends Command echo 'arrive_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()) + ]); echo $exception->getMessage(). PHP_EOL; } } diff --git a/application/common/command/CheckSmsPlantCommand.php b/application/common/command/CheckSmsPlantCommand.php index 87e2563..6db9914 100644 --- a/application/common/command/CheckSmsPlantCommand.php +++ b/application/common/command/CheckSmsPlantCommand.php @@ -7,14 +7,16 @@ 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('dispatch已预约任务短信提醒,每5分钟执行一次'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -34,6 +36,12 @@ class CheckSmsPlantCommand extends Command }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()) + ]); } echo '短信发送完成:'.$item->id.PHP_EOL; } diff --git a/application/common/command/CheckTTSOverTimeCommand.php b/application/common/command/CheckTTSOverTimeCommand.php index b0f0eb7..9928c09 100644 --- a/application/common/command/CheckTTSOverTimeCommand.php +++ b/application/common/command/CheckTTSOverTimeCommand.php @@ -11,13 +11,18 @@ 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('dispatch超时未完成任务语音通知,每5分钟执行一次'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -31,24 +36,34 @@ class CheckTTSOverTimeCommand extends Command ->chunk(100, function ($list) { $ids = []; $logs = []; - 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; + 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'); } diff --git a/application/common/command/CheckTTSPlantCommand.php b/application/common/command/CheckTTSPlantCommand.php index f4b797b..17382af 100644 --- a/application/common/command/CheckTTSPlantCommand.php +++ b/application/common/command/CheckTTSPlantCommand.php @@ -11,13 +11,17 @@ 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('dispatch已预约任务语音提醒,每5分钟执行一次'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -33,18 +37,27 @@ class CheckTTSPlantCommand extends Command $ids = []; $logs = []; foreach ($list as $item) { - $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); + + 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')]); diff --git a/application/common/command/CheckTTSTaskCommand.php b/application/common/command/CheckTTSTaskCommand.php index 56a3ab0..ce9e858 100644 --- a/application/common/command/CheckTTSTaskCommand.php +++ b/application/common/command/CheckTTSTaskCommand.php @@ -11,13 +11,17 @@ use app\common\Logic\NoticeLogic; use think\console\Command; use think\console\Input; use think\console\Output; +use think\Db; +use think\Exception; class CheckTTSTaskCommand extends Command { + protected $title = 'dispatch语音发送任务,每1分钟执行一次'; + protected function configure() { $this->setName('check:dispatch-tts-task') - ->setDescription('语音发送任务,每1分钟执行一次'); + ->setDescription($this->title); } protected function execute(Input $input, Output $output){ @@ -26,7 +30,19 @@ class CheckTTSTaskCommand extends Command $Model->where('status','=',0) ->chunk(100, function ($list)use($ttsService) { foreach ($list as $item) { - $ttsService->callIt($item); + try { + $ttsService->callIt($item); + }catch (Exception $exception){ + $item->status = -1; + $item->content = $exception->getMessage(); + $item->save(); + + 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()) + ]); + } echo $item->id.PHP_EOL; } });