From 0e6b885095ff354c61e5dd4a78c271369617f85e Mon Sep 17 00:00:00 2001 From: wong <106998207@qq.com> Date: Mon, 29 Sep 2025 11:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=88=E6=81=AF=E4=B8=AD=E5=BF=83=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Server/application/chukebao/config/route.php | 6 + .../chukebao/controller/NoticeController.php | 113 ++++++++++++++++++ .../controller/WechatGroupController.php | 7 +- .../application/command/KfNoticeCommand.php | 3 +- 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 Server/application/chukebao/controller/NoticeController.php diff --git a/Server/application/chukebao/config/route.php b/Server/application/chukebao/config/route.php index 2c1e4487..fb155171 100644 --- a/Server/application/chukebao/config/route.php +++ b/Server/application/chukebao/config/route.php @@ -140,6 +140,12 @@ Route::group('v1/', function () { }); + //自动问候 + Route::group('notice/', function () { + Route::get('list', 'app\chukebao\controller\NoticeController@getList'); + Route::get('readMessage', 'app\chukebao\controller\NoticeController@readMessage'); + Route::get('readAll', 'app\chukebao\controller\NoticeController@readAll'); + }); }); diff --git a/Server/application/chukebao/controller/NoticeController.php b/Server/application/chukebao/controller/NoticeController.php new file mode 100644 index 00000000..d7216c7f --- /dev/null +++ b/Server/application/chukebao/controller/NoticeController.php @@ -0,0 +1,113 @@ +request->param('page', 1); + $limit = $this->request->param('limit', 10); + $keyword = $this->request->param('keyword', ''); + $accountId = $this->getUserInfo('s2_accountId'); + $userId = $this->getUserInfo('id'); + $companyId = $this->getUserInfo('companyId'); + + if (empty($accountId)) { + return ResponseHelper::error('请先登录'); + } + $query = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId]) + ->order('id desc'); + if (!empty($keyword)) { + $query->where('title|message', 'like', '%' . $keyword . '%'); + } + $total = $query->count(); + $list = $query->page($page, $limit)->order('isRead ASC,id DESC')->select()->toArray(); + + + foreach ($list as $k => &$v) { + + if ($v['type'] == 1) { + $friendId = ToDo::where(['id' => $v['bindId']])->value('friendId'); + } elseif ($v['type'] == 2) { + $friendId = FollowUp::where(['id' => $v['bindId']])->value('friendId'); + } + + if (!empty($friendId)) { + $friend = Db::table('s2_wechat_friend')->where(['id' => $friendId])->field('nickname,avatar')->find(); + } else { + $friend = ['nickname' => '', 'avatar' => '']; + } + + $v['friendData'] = $friend; + } + unset($v); + return ResponseHelper::success(['list' => $list, 'total' => $total]); + } + + + public function readMessage() + { + $id = $this->request->param('id', ''); + $userId = $this->getUserInfo('id'); + $companyId = $this->getUserInfo('companyId'); + + if (empty($id)) { + return ResponseHelper::error('参数缺失'); + } + Db::startTrans(); + try { + $notice = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $id, 'isRead' => 0])->find(); + if (empty($notice)) { + return ResponseHelper::error('该消息不存在或标记已读'); + } + $notice->isRead = 1; + $notice->readTime = time(); + $notice->save(); + if ($notice->type == 1) { + ToDo::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $notice->bindId])->update(['isProcess' => 1, 'updateTime' => time()]); + } elseif ($notice->type == 2) { + FollowUp::where(['userId' => $userId, 'companyId' => $companyId, 'id' => $notice->bindId])->update(['isProcess' => 1, 'updateTime' => time()]); + } + Db::commit(); + return ResponseHelper::success(' ', '处理成功'); + } catch (\Exception $e) { + Db::rollback(); + return ResponseHelper::error('处理失败:' . $e->getMessage()); + } + } + + + public function readAll() + { + $userId = $this->getUserInfo('id'); + $companyId = $this->getUserInfo('companyId'); + + Db::startTrans(); + try { + $noticeData = NoticeModel::where(['userId' => $userId, 'companyId' => $companyId, 'isRead' => 0])->select()->toArray(); + if (empty($noticeData)) { + return ResponseHelper::error('暂未有新消息'); + } + FollowUp::where(['userId' => $userId, 'companyId' => $companyId, 'isProcess' => 0])->update(['isProcess' => 1, 'updateTime' => time()]); + ToDo::where(['userId' => $userId, 'companyId' => $companyId, 'isProcess' => 0])->update(['isProcess' => 1, 'updateTime' => time()]); + Db::commit(); + return ResponseHelper::success(' ', '全部已读'); + } catch (\Exception $e) { + Db::rollback(); + return ResponseHelper::error('处理失败:' . $e->getMessage()); + } + } + +} \ No newline at end of file diff --git a/Server/application/chukebao/controller/WechatGroupController.php b/Server/application/chukebao/controller/WechatGroupController.php index 5e0241d9..0ee08b91 100644 --- a/Server/application/chukebao/controller/WechatGroupController.php +++ b/Server/application/chukebao/controller/WechatGroupController.php @@ -14,7 +14,12 @@ class WechatGroupController extends BaseController $userId = $this->getUserInfo('id'); $companyId = $this->getUserInfo('companyId'); - $query = Db::table('s2_wechat_group')->where(['accountId' => $accountId])->whereIn('groupType',[1,2])->order('sortIndex desc,id desc'); + $query = Db::table('s2_wechat_group') + ->where(function ($query) use ($accountId,$companyId) { + $query->where('accountId', $accountId)->whereOr('departmentId', $companyId); + }) + ->whereIn('groupType',[1,2]) + ->order('groupType desc,sortIndex desc,id desc'); $list = $query->select(); $total = $query->count(); diff --git a/Server/application/command/KfNoticeCommand.php b/Server/application/command/KfNoticeCommand.php index f116473b..cfc30601 100644 --- a/Server/application/command/KfNoticeCommand.php +++ b/Server/application/command/KfNoticeCommand.php @@ -30,7 +30,6 @@ class KfNoticeCommand extends Command protected function execute(Input $input, Output $output) { $output->writeln('开始处理消息通知任务...'); - $where = [ ['isRemind', '=', 0], ['reminderTime', '<=', time()], @@ -41,6 +40,7 @@ class KfNoticeCommand extends Command $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') + ->where('isRemind',0) ->select(); if (!empty($followUp)) { foreach ($followUp as $k => $v) { @@ -81,6 +81,7 @@ class KfNoticeCommand extends Command $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') + ->where('isRemind',0) ->select(); if (!empty($toDo)) { foreach ($toDo as $k => $v) {