0) { $query->where('id', '<', $lastId); } return $query->order('id', 'desc') ->limit($limit) ->select() ->toArray(); } /** * 获取会话未读消息 */ public static function getUnreadBySessionId($sessionId, $senderType, $limit = 50) { return self::where('session_id', $sessionId) ->where('sender_type', '<>', $senderType) ->where('status', '<', self::STATUS_READ) ->order('id', 'asc') ->limit($limit) ->select() ->toArray(); } /** * 检查消息ID是否存在(幂等性) */ public static function existsByMsgId($msgId) { return self::where('msg_id', $msgId)->count() > 0; } }