From 8982010423599c48d270ea6b43339bc0ec837f9d Mon Sep 17 00:00:00 2001 From: ASUS <515617283@qq.com> Date: Fri, 21 Nov 2025 17:03:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=8A=E5=A4=A9=EF=BC=8C=E5=9F=BA=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/chat/controller/GroupController.php | 25 ++++++-------- extend/chat/model/Base.php | 39 +++++++++++---------- extend/chat/model/Business.php | 45 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 33 deletions(-) create mode 100644 extend/chat/model/Business.php diff --git a/app/chat/controller/GroupController.php b/app/chat/controller/GroupController.php index a90b08c..d7de37c 100644 --- a/app/chat/controller/GroupController.php +++ b/app/chat/controller/GroupController.php @@ -317,38 +317,33 @@ class GroupController extends ApiController } /** - * 设置群免打扰 (废弃) + * 设置群免打扰 */ public function setDoNotDisturb(Request $request): Response { $groupId = $request->post('group_id'); $status = $request->post('status'); // 0=关闭,1=开启 - if (!$groupId) { return $this->error('缺少group_id'); } - // 验证是否在群内 $isMember = Db::name('chat_group_member')->where([ 'group_id' => $groupId, 'user_id' => $this->uid, 'quit_time' => null, 'is_kicked' => 0 - ])->exists(); + ])->find(); if (!$isMember) { return $this->error('不在群内'); } - - // 生成会话ID - $sessionId = Session::generateSessionId(2, $uid, $groupId); - - // 更新免打扰状态 - ChatDoNotDisturb::updateOrCreate( - ['user_id' => $uid, 'session_id' => $sessionId], - ['status' => $status, 'updated_at' => time()] - ); - - return json(['code' => 200, 'msg' => $status ? '开启免打扰成功' : '关闭免打扰成功']); + $res = Db::name('chat_group_member')->where([ + 'group_id' => $groupId, + 'user_id' => $this->uid, + ])->update(['is_dist' => $status]); + if($res) { + return $this->success(); + } + return $this->error(); } /** diff --git a/extend/chat/model/Base.php b/extend/chat/model/Base.php index 4329f31..71eb320 100644 --- a/extend/chat/model/Base.php +++ b/extend/chat/model/Base.php @@ -129,11 +129,12 @@ namespace extend\chat\model; // 回馈 Gateway::sendToClient($client_id, self::sendGormat($message, $list_arr)); - $str_uid = self::getUid(self::$user_info['uid'], self::$user_info['user_type']); // 上线后立马发送没有发送的消息 - $send_data = Redis::get('nosuccessful:message:sent:' . $str_uid); + $send_data = Business::getRedisMessage(self::$user_info['uid'], self::$user_info['user_type']); if($send_data) { - Gateway::sendToClient($client_id, $send_data); + foreach ($send_data as $k => $v) { + Gateway::sendToClient($client_id, $v); + } } } @@ -241,8 +242,8 @@ namespace extend\chat\model; Gateway::sendToUid($str_uid, self::sendReceive($notice_data)); return; }else { - // 不在线的存下来等上线了发 - Redis::set('nosuccessful:message:sent:' . $str_uid, json_encode($notice_data)); + // 存消息 + Business::setRedisMessage($message['to_id'], $message['to_user_type'], $notice_data); } }elseif ($message['chat_type'] == 2) { @@ -258,19 +259,21 @@ namespace extend\chat\model; if($grep['user_id'] != self::$user_info['uid']) { $user_type = $grep['role']==1?2:1; $str_uid = self::getUid($grep['user_id'], $user_type); - // 群成员是否在线,在线发 不在线存起来等上线了发 - if(Gateway::isUidOnline($str_uid)) { - Gateway::sendToUid($str_uid, self::sendReceive($notice_data)); - return; - }else { - // 不在线的存下来等上线了发 - Redis::set('nosuccessful:message:sent:' . $str_uid, json_encode($notice_data)); - } - // 加入未读计数 - if(!Db::name('chat_unread_count')->where(['user_id' => $grep['user_id']])->find()) { - Db::name('chat_unread_count')->where(['user_id' => $grep['user_id'], 'session_id' => $session_id])->update(['count' => 1, 'updated_time' => d()]); - }else { - Db::name('chat_unread_count')->where(['user_id' => $grep['user_id'], 'session_id' => $session_id])->inc('count')->update(['updated_time' => d()]); + // 群成员是否在线,在线发 不在线存起来等上线了发 免打扰也不发消息 + if($grep['is_dist'] == 0) { + if(Gateway::isUidOnline($str_uid)) { + Gateway::sendToUid($str_uid, self::sendReceive($notice_data)); + return; + }else { + // 存消息 + Business::setRedisMessage($grep['user_id'], $user_type, $notice_data); + } + // 加入未读计数 + if(!Db::name('chat_unread_count')->where(['user_id' => $grep['user_id']])->find()) { + Db::name('chat_unread_count')->where(['user_id' => $grep['user_id'], 'session_id' => $session_id])->update(['count' => 1, 'updated_time' => d()]); + }else { + Db::name('chat_unread_count')->where(['user_id' => $grep['user_id'], 'session_id' => $session_id])->inc('count')->update(['updated_time' => d()]); + } } } } diff --git a/extend/chat/model/Business.php b/extend/chat/model/Business.php new file mode 100644 index 0000000..96ee158 --- /dev/null +++ b/extend/chat/model/Business.php @@ -0,0 +1,45 @@ + $v) { + $data[] = json_decode(Redis::get($v), true); + Redis::del($v); + } + Redis::del($set_str); + } + return $data; + } +} \ No newline at end of file