From 5102f02083db6a452f7031012b48c1b644080e41 Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Mon, 29 Sep 2025 09:44:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E6=8F=90=E9=86=92=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../chukebao/model/NoticeModel.php | 16 +++ Server/application/command.php | 1 + .../application/command/KfNoticeCommand.php | 117 ++++++++++++++++++ Server/crontab_tasks.md | 7 ++ 4 files changed, 141 insertions(+) create mode 100644 Server/application/chukebao/model/NoticeModel.php create mode 100644 Server/application/command/KfNoticeCommand.php diff --git a/Server/application/chukebao/model/NoticeModel.php b/Server/application/chukebao/model/NoticeModel.php new file mode 100644 index 00000000..5a920f2b --- /dev/null +++ b/Server/application/chukebao/model/NoticeModel.php @@ -0,0 +1,16 @@ + 'app\command\WorkbenchGroupPushCommand', // 工作台群推送任务 'workbench:groupCreate' => 'app\command\WorkbenchGroupCreateCommand', // 工作台群创建任务 'workbench:import-contact' => 'app\command\WorkbenchImportContactCommand', // 工作台通讯录导入任务 + 'kf:notice' => 'app\command\KfNoticeCommand', // 客服端消息通知 ]; diff --git a/Server/application/command/KfNoticeCommand.php b/Server/application/command/KfNoticeCommand.php new file mode 100644 index 00000000..f116473b --- /dev/null +++ b/Server/application/command/KfNoticeCommand.php @@ -0,0 +1,117 @@ +setName('kfNotice:run') + ->setDescription('消息通知'); + } + + protected function execute(Input $input, Output $output) + { + $output->writeln('开始处理消息通知任务...'); + + $where = [ + ['isRemind', '=', 0], + ['reminderTime', '<=', time()], + ]; + $notice = []; + Db::startTrans(); + try { + $followUp = FollowUp::where($where)->alias('a') + ->field('a.*,f.nickname,f.avatar,f.alias,f.wechatId') + ->join(['s2_wechat_friend f'], 'a.friendId = f.id') + ->select(); + if (!empty($followUp)) { + foreach ($followUp as $k => $v) { + switch ($v['type']) { + case 1: + $title = '电话回访'; + break; + case 2: + $title = '发送消息'; + break; + case 3: + $title = '安排会议'; + break; + case 4: + $title = '发送邮件'; + break; + default: + $title = '其他'; + break; + } + + $wechatId = !empty($v['alias']) ? $v['alias'] : $v['wechatId']; + $nickname = $v['nickname'] . '(' . $wechatId . ')'; + $message = $nickname . ':' . $v['description']; + $notice[] = [ + 'type' => 2, + 'userId' => $v['userId'], + 'companyId' => $v['companyId'], + 'bindId' => $v['id'], + 'title' => $title, + 'message' => $message, + 'createTime' => $v['reminderTime'], + ]; + } + FollowUp::where($where)->update(['isRemind' => 1]); + } + + $toDo = ToDo::where($where)->alias('a') + ->field('a.*,f.nickname,f.avatar,f.alias,f.wechatId') + ->join(['s2_wechat_friend f'], 'a.friendId = f.id') + ->select(); + if (!empty($toDo)) { + foreach ($toDo as $k => $v) { + + $wechatId = !empty($v['alias']) ? $v['alias'] : $v['wechatId']; + $nickname = $v['nickname'] . '(' . $wechatId . ')'; + $message = $nickname . ':' . $v['description']; + + + $notice[] = [ + 'type' => 1, + 'userId' => $v['userId'], + 'companyId' => $v['companyId'], + 'bindId' => $v['id'], + 'title' => $v['title'], + 'message' => $message, + 'createTime' => $v['reminderTime'], + ]; + } + FollowUp::where($where)->update(['isRemind' => 1]); + } + + $noticeModel = new NoticeModel(); + $noticeModel->insertAll($notice); + Db::commit(); + return true; + } catch (\Exception $e) { + Db::rollback(); + return false; + } + + } + +} \ No newline at end of file diff --git a/Server/crontab_tasks.md b/Server/crontab_tasks.md index 2c965eee..f5849517 100644 --- a/Server/crontab_tasks.md +++ b/Server/crontab_tasks.md @@ -78,6 +78,13 @@ # 预防性切换好友 */2 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think switch:friends >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/switch_friends.log 2>&1 +# 消息提醒 +*/1 * * * * cd /www/wwwroot/mckb_quwanzhi_com/Server && php think kf:notice >> /www/wwwroot/mckb_quwanzhi_com/Server/runtime/log/kf_notice.log 2>&1 + + + + + ```