代码提交

This commit is contained in:
wong
2025-10-23 09:34:43 +08:00
parent 35b38e8542
commit c2dce8344b
3 changed files with 22 additions and 13 deletions

View File

@@ -19,7 +19,7 @@ class MessageController extends BaseController
$friends = Db::table('s2_wechat_friend')
->where(['accountId' => $accountId, 'isDeleted' => 0])
->column('id,nickname,avatar');
->column('id,nickname,avatar,conRemark,labels,groupId,wechatAccountId,wechatId');
// 构建好友子查询
@@ -30,13 +30,13 @@ class MessageController extends BaseController
// 使用 UNION 合并群聊和好友消息,然后统一排序和分页
$unionQuery = "
(SELECT m.id, m.content, m.wechatFriendId, m.wechatChatroomId, m.createTime, m.wechatTime, 2 as msgType, wc.nickname, wc.chatroomAvatar as avatar
(SELECT m.id, m.content, m.wechatFriendId, m.wechatChatroomId, m.createTime, m.wechatTime, 2 as msgType, wc.nickname, wc.chatroomAvatar as avatar,wc.chatroomId
FROM s2_wechat_chatroom wc
LEFT JOIN s2_wechat_message m ON wc.id = m.wechatChatroomId
WHERE wc.accountId = {$accountId} AND m.type = 2 AND wc.isDeleted = 0
GROUP BY m.wechatChatroomId)
UNION ALL
(SELECT m.id, m.content, m.wechatFriendId, m.wechatChatroomId, m.createTime, m.wechatTime, 1 as msgType, 1 as nickname, 1 avatar
(SELECT m.id, m.content, m.wechatFriendId, m.wechatChatroomId, m.createTime, m.wechatTime, 1 as msgType, 1 as nickname, 1 avatar, 1 as chatroomId
FROM s2_wechat_message m
WHERE m.type = 1 AND m.wechatFriendId IN {$friendSubQuery}
GROUP BY m.wechatFriendId)
@@ -87,21 +87,29 @@ class MessageController extends BaseController
if (!empty($v['wechatFriendId'])) {
$v['nickname'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['nickname'] : '';
$v['avatar'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['avatar'] : '';
$vunreadCount = isset($friendUnreadMap[$v['wechatFriendId']]) ? (int)$friendUnreadMap[$v['wechatFriendId']] : 0;
$v['conRemark'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['conRemark'] : '';
$v['groupId'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['groupId'] : '';
$v['wechatAccountId'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['wechatAccountId'] : '';
$v['wechatId'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['wechatId'] : '';
$v['labels'] = !empty($friends[$v['wechatFriendId']]) ? json_decode($friends[$v['wechatFriendId']]['labels'],true) : [];
$unreadCount = isset($friendUnreadMap[$v['wechatFriendId']]) ? (int)$friendUnreadMap[$v['wechatFriendId']] : 0;
unset($v['chatroomId']);
}
if (!empty($v['wechatChatroomId'])) {
$vunreadCount = isset($chatroomUnreadMap[$v['wechatChatroomId']]) ? (int)$chatroomUnreadMap[$v['wechatChatroomId']] : 0;
$v['conRemark'] = '';
$unreadCount = isset($chatroomUnreadMap[$v['wechatChatroomId']]) ? (int)$chatroomUnreadMap[$v['wechatChatroomId']] : 0;
}
$v['id'] = !empty($v['wechatFriendId']) ? $v['wechatFriendId'] : $v['wechatChatroomId'];
$v['config'] = [
'vunreadCount' => $vunreadCount,
'top' => false,
'unreadCount' => $unreadCount,
'chat' => true,
'msgTime' => $v['wechatTime'],
];
$v['createTime'] = $createTime;
$v['wechatTime'] = $wechatTime;
$v['lastUpdateTime'] = $wechatTime;
unset($v['wechatFriendId'],$v['wechatChatroomId']);
}