'serialize' ]; /** * 更改所有未读消息为已读 * @param int $room_id 房间ID * @date 2022-08-16 */ public function updateAllUnreadMessage($room_id) { $where = [ ['room_id', '=', $room_id], ['to_user_id', '=', $this->userId] ]; return $this->where($where)->save([ 'is_read' => 1 ]); } /** * 获取聊天记录 * @param int $room_id 房间ID * @param int $start_time 聊天记录的起始时间 * @param int|string $cur_first_message_id 最上面一条的ID * @date 2022-08-08 */ public function listChatRoomMessage($room_id, $start_time, $cur_first_message_id = '') { $where = [ ['room_id', '=', $room_id], ['create_time', '>=', $start_time] ]; if (!empty($cur_first_message_id)) { // 在最上面一条消息之前的 $where[] = ['id', '<', $cur_first_message_id]; } $data_list = $this->where($where) ->field('id,room_id,user_id,to_user_id,type,content,attach_data,create_time') ->order('id desc')->limit(1) ->paginate(['list_rows' => 14, 'page' => 1], false) ->toArray(); return $data_list; } }