代码提交
This commit is contained in:
@@ -449,7 +449,7 @@ class MessageController extends BaseController
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -86,19 +86,20 @@ class DataProcessing extends BaseController
|
||||
$msg = '好友转移成功';
|
||||
break;
|
||||
case 'CmdNewMessage':
|
||||
if(empty($friendMessage) || empty($chatroomMessage)){
|
||||
if(empty($friendMessage) && empty($chatroomMessage)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
}
|
||||
|
||||
if(is_array($friendMessage) || is_array($chatroomMessage)){
|
||||
return ResponseHelper::error('参数缺失');
|
||||
if(is_array($friendMessage) && is_array($chatroomMessage)){
|
||||
return ResponseHelper::error('数据类型错误');
|
||||
}
|
||||
|
||||
|
||||
$messageController = new MessageController();
|
||||
if (!empty($friendMessage)){
|
||||
$res = $messageController->saveMessage($friendMessage);
|
||||
$res = $messageController->saveMessage($friendMessage[0]);
|
||||
}else{
|
||||
$res = $messageController->saveChatroomMessage($friendMessage);
|
||||
$res = $messageController->saveChatroomMessage($chatroomMessage[0]);
|
||||
}
|
||||
if (!empty($res)){
|
||||
$msg = '消息记录成功';
|
||||
|
||||
@@ -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']);
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user