新版流量池提交
This commit is contained in:
@@ -31,74 +31,74 @@ class MessageController extends BaseController
|
||||
}
|
||||
|
||||
// 直接查询好友ID列表
|
||||
$ids = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id');
|
||||
$friendIds = empty($ids) ? [0] : $ids; // 避免 IN 查询为空
|
||||
$ids = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id');
|
||||
$friendIds = empty($ids) ? [0] : $ids; // 避免 IN 查询为空
|
||||
|
||||
// 直接查询好友信息
|
||||
$friends = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id,nickname,avatar,conRemark,labels,groupId,wechatAccountId,wechatId,extendFields,phone,region,isTop');
|
||||
$friends = Db::table('s2_wechat_friend')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id,nickname,avatar,conRemark,labels,groupId,wechatAccountId,wechatId,extendFields,phone,region,isTop');
|
||||
|
||||
// 直接查询群聊信息
|
||||
$chatrooms = Db::table('s2_wechat_chatroom')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id,nickname,chatroomAvatar,chatroomId,isTop');
|
||||
$chatrooms = Db::table('s2_wechat_chatroom')
|
||||
->where(['accountId' => $accountId, 'isDeleted' => 0])
|
||||
->column('id,nickname,chatroomAvatar,chatroomId,isTop');
|
||||
|
||||
// 获取群聊ID列表
|
||||
$chatroomIds = array_keys($chatrooms);
|
||||
if (empty($chatroomIds)) {
|
||||
$chatroomIds = [0];
|
||||
}
|
||||
|
||||
// 1. 查询群聊最新消息
|
||||
$chatroomMessages = [];
|
||||
if (!empty($chatroomIds) && $chatroomIds[0] != 0) {
|
||||
$chatroomIdsStr = implode(',', array_map('intval', $chatroomIds));
|
||||
$chatroomLatestQuery = "
|
||||
SELECT wc.id as chatroomId, m.id, m.content, m.wechatChatroomId, m.createTime, m.wechatTime, m.wechatAccountId,
|
||||
wc.nickname, wc.chatroomAvatar as avatar, wc.chatroomId, wc.isTop, 2 as msgType
|
||||
FROM s2_wechat_chatroom wc
|
||||
INNER JOIN (
|
||||
SELECT wechatChatroomId, MAX(wechatTime) as maxTime, MAX(id) as maxId
|
||||
FROM s2_wechat_message
|
||||
WHERE type = 2 AND wechatChatroomId IN ({$chatroomIdsStr})
|
||||
GROUP BY wechatChatroomId
|
||||
) latest ON wc.id = latest.wechatChatroomId
|
||||
INNER JOIN s2_wechat_message m ON m.wechatChatroomId = latest.wechatChatroomId
|
||||
AND m.wechatTime = latest.maxTime AND m.id = latest.maxId
|
||||
WHERE wc.accountId = {$accountId} AND wc.isDeleted = 0
|
||||
";
|
||||
$chatroomMessages = Db::query($chatroomLatestQuery);
|
||||
}
|
||||
// 获取群聊ID列表
|
||||
$chatroomIds = array_keys($chatrooms);
|
||||
if (empty($chatroomIds)) {
|
||||
$chatroomIds = [0];
|
||||
}
|
||||
|
||||
// 1. 查询群聊最新消息
|
||||
$chatroomMessages = [];
|
||||
if (!empty($chatroomIds) && $chatroomIds[0] != 0) {
|
||||
$chatroomIdsStr = implode(',', array_map('intval', $chatroomIds));
|
||||
$chatroomLatestQuery = "
|
||||
SELECT wc.id as chatroomId, m.id, m.content, m.wechatChatroomId, m.createTime, m.wechatTime, m.wechatAccountId,
|
||||
wc.nickname, wc.chatroomAvatar as avatar, wc.chatroomId, wc.isTop, 2 as msgType
|
||||
FROM s2_wechat_chatroom wc
|
||||
INNER JOIN (
|
||||
SELECT wechatChatroomId, MAX(wechatTime) as maxTime, MAX(id) as maxId
|
||||
FROM s2_wechat_message
|
||||
WHERE type = 2 AND wechatChatroomId IN ({$chatroomIdsStr})
|
||||
GROUP BY wechatChatroomId
|
||||
) latest ON wc.id = latest.wechatChatroomId
|
||||
INNER JOIN s2_wechat_message m ON m.wechatChatroomId = latest.wechatChatroomId
|
||||
AND m.wechatTime = latest.maxTime AND m.id = latest.maxId
|
||||
WHERE wc.accountId = {$accountId} AND wc.isDeleted = 0
|
||||
";
|
||||
$chatroomMessages = Db::query($chatroomLatestQuery);
|
||||
}
|
||||
|
||||
// 2. 查询好友最新消息
|
||||
$friendMessages = [];
|
||||
if (!empty($friendIds) && $friendIds[0] != 0) {
|
||||
$friendIdsStr = implode(',', array_map('intval', $friendIds));
|
||||
$friendLatestQuery = "
|
||||
SELECT m.wechatFriendId, m.id, m.content, m.createTime, m.wechatTime,
|
||||
f.wechatAccountId, 1 as msgType, 0 as isTop
|
||||
FROM s2_wechat_message m
|
||||
INNER JOIN (
|
||||
SELECT wechatFriendId, MAX(wechatTime) as maxTime, MAX(id) as maxId
|
||||
FROM s2_wechat_message
|
||||
WHERE type = 1 AND wechatFriendId IN ({$friendIdsStr})
|
||||
GROUP BY wechatFriendId
|
||||
) latest ON m.wechatFriendId = latest.wechatFriendId
|
||||
AND m.wechatTime = latest.maxTime AND m.id = latest.maxId
|
||||
INNER JOIN s2_wechat_friend f ON f.id = m.wechatFriendId
|
||||
WHERE m.type = 1 AND m.wechatFriendId IN ({$friendIdsStr})
|
||||
";
|
||||
$friendMessages = Db::query($friendLatestQuery);
|
||||
}
|
||||
// 2. 查询好友最新消息
|
||||
$friendMessages = [];
|
||||
if (!empty($friendIds) && $friendIds[0] != 0) {
|
||||
$friendIdsStr = implode(',', array_map('intval', $friendIds));
|
||||
$friendLatestQuery = "
|
||||
SELECT m.wechatFriendId, m.id, m.content, m.createTime, m.wechatTime,
|
||||
f.wechatAccountId, 1 as msgType, 0 as isTop
|
||||
FROM s2_wechat_message m
|
||||
INNER JOIN (
|
||||
SELECT wechatFriendId, MAX(wechatTime) as maxTime, MAX(id) as maxId
|
||||
FROM s2_wechat_message
|
||||
WHERE type = 1 AND wechatFriendId IN ({$friendIdsStr})
|
||||
GROUP BY wechatFriendId
|
||||
) latest ON m.wechatFriendId = latest.wechatFriendId
|
||||
AND m.wechatTime = latest.maxTime AND m.id = latest.maxId
|
||||
INNER JOIN s2_wechat_friend f ON f.id = m.wechatFriendId
|
||||
WHERE m.type = 1 AND m.wechatFriendId IN ({$friendIdsStr})
|
||||
";
|
||||
$friendMessages = Db::query($friendLatestQuery);
|
||||
}
|
||||
|
||||
// 合并结果并排序
|
||||
$allMessages = array_merge($chatroomMessages, $friendMessages);
|
||||
usort($allMessages, function ($a, $b) {
|
||||
return $b['wechatTime'] <=> $a['wechatTime'];
|
||||
});
|
||||
// 合并结果并排序
|
||||
$allMessages = array_merge($chatroomMessages, $friendMessages);
|
||||
usort($allMessages, function ($a, $b) {
|
||||
return $b['wechatTime'] <=> $a['wechatTime'];
|
||||
});
|
||||
|
||||
// 计算总数
|
||||
$totalCount = count($allMessages);
|
||||
|
||||
Reference in New Issue
Block a user