数据为空时的安全写法。
This commit is contained in:
@@ -29,10 +29,14 @@ class Message extends Api
|
|||||||
}
|
}
|
||||||
//总未读数(兼容旧字段)+ 分类未读数(前端tab角标用)
|
//总未读数(兼容旧字段)+ 分类未读数(前端tab角标用)
|
||||||
$unreadCount = MessageService::where($where + ['is_read' => CommonService::STATUS_OFF])->count();
|
$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])
|
$unreadList = MessageService::where(['to_user_id' => $user_id, 'is_read' => CommonService::STATUS_OFF])
|
||||||
->field('message_type, count(*) as total')
|
->field('message_type, count(*) as total')
|
||||||
->group('message_type')
|
->group('message_type')
|
||||||
->select()->toArray();
|
->select();
|
||||||
|
$unreadList = is_object($unreadList) && method_exists($unreadList, 'toArray')
|
||||||
|
? $unreadList->toArray()
|
||||||
|
: (array)$unreadList;
|
||||||
$unreadMap = [
|
$unreadMap = [
|
||||||
MessageService::TYPE_SYSTEM => 0,
|
MessageService::TYPE_SYSTEM => 0,
|
||||||
MessageService::TYPE_NOTICE => 0,
|
MessageService::TYPE_NOTICE => 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user