diff --git a/app/chat/controller/MessageController.php b/app/chat/controller/MessageController.php index 1f9b214..79ef13a 100644 --- a/app/chat/controller/MessageController.php +++ b/app/chat/controller/MessageController.php @@ -188,4 +188,34 @@ class MessageController extends ApiController return $this->success(['list' => ChatMessage::getconverlist($this->uid, $this->user_type)]); } } + + /** + * 删除会话列表 + */ + public function getSessionListDel(Request $request): Response + { + $session_id = $request->post('session_id'); + if(empty($session_id)) { + return $this->error('参数不完整'); + } + $list_json = Redis::get('usermsg:list:' . $this->user_type . ':' . $this->uid); + if($list_json) { + $list_arr = json_decode($list_json, true); + foreach ($list_arr as $k => $list) { + if($list['session_id'] == $session_id) { + unset($list_arr[$k]); + } + } + if(count($list_arr) >= 1) { + Redis::setEx('usermsg:list:' . $this->user_type . ':' . $this->uid, 30 * 86400, json_encode($list_arr)); + }else { + Redis::del('usermsg:list:' . $this->user_type . ':' . $this->uid); + } + } + return $this->success(); + } + + + + } diff --git a/app/chat/model/ChatMessage.php b/app/chat/model/ChatMessage.php index eb7dab8..4d684f3 100644 --- a/app/chat/model/ChatMessage.php +++ b/app/chat/model/ChatMessage.php @@ -42,7 +42,7 @@ class ChatMessage extends BaseModel } $data[$i]['unread_count'] = $unreadCount; - if($session['session_id']) { + if(!empty($session['session_id'])) { // 最后一条消息 $lastMsg = Db::name('chat_message') ->where('session_id', $session['session_id'])