diff --git a/backend/application/api/controller/Message.php b/backend/application/api/controller/Message.php index 9dd2169..406d00a 100644 --- a/backend/application/api/controller/Message.php +++ b/backend/application/api/controller/Message.php @@ -29,10 +29,14 @@ class Message extends Api } //总未读数(兼容旧字段)+ 分类未读数(前端tab角标用) $unreadCount = MessageService::where($where + ['is_read' => CommonService::STATUS_OFF])->count(); + //where() 走的是 Query 对象,select() 返回普通数组而非 Collection,需兼容处理 $unreadList = MessageService::where(['to_user_id' => $user_id, 'is_read' => CommonService::STATUS_OFF]) ->field('message_type, count(*) as total') ->group('message_type') - ->select()->toArray(); + ->select(); + $unreadList = is_object($unreadList) && method_exists($unreadList, 'toArray') + ? $unreadList->toArray() + : (array)$unreadList; $unreadMap = [ MessageService::TYPE_SYSTEM => 0, MessageService::TYPE_NOTICE => 0,