消息新增ai类型字段
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace app\chukebao\controller;
|
namespace app\chukebao\controller;
|
||||||
|
|
||||||
|
use app\chukebao\model\FriendSettings;
|
||||||
use library\ResponseHelper;
|
use library\ResponseHelper;
|
||||||
use think\Db;
|
use think\Db;
|
||||||
|
|
||||||
@@ -98,6 +99,10 @@ class MessageController extends BaseController
|
|||||||
->column('COUNT(*) AS cnt', 'wechatChatroomId');
|
->column('COUNT(*) AS cnt', 'wechatChatroomId');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$aiTypeData = [];
|
||||||
|
if (!empty($friendIds)) {
|
||||||
|
$aiTypeData = FriendSettings::where('friendId', 'in', $friendIds)->column('friendId,type');
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($list as $k => &$v) {
|
foreach ($list as $k => &$v) {
|
||||||
|
|
||||||
@@ -106,6 +111,7 @@ class MessageController extends BaseController
|
|||||||
|
|
||||||
|
|
||||||
$unreadCount = 0;
|
$unreadCount = 0;
|
||||||
|
$v['aiType'] = 0;
|
||||||
if (!empty($v['wechatFriendId'])) {
|
if (!empty($v['wechatFriendId'])) {
|
||||||
$v['nickname'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['nickname'] : '';
|
$v['nickname'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['nickname'] : '';
|
||||||
$v['avatar'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['avatar'] : '';
|
$v['avatar'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['avatar'] : '';
|
||||||
@@ -115,6 +121,7 @@ class MessageController extends BaseController
|
|||||||
$v['wechatId'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['wechatId'] : '';
|
$v['wechatId'] = !empty($friends[$v['wechatFriendId']]) ? $friends[$v['wechatFriendId']]['wechatId'] : '';
|
||||||
$v['labels'] = !empty($friends[$v['wechatFriendId']]) ? json_decode($friends[$v['wechatFriendId']]['labels'], true) : [];
|
$v['labels'] = !empty($friends[$v['wechatFriendId']]) ? json_decode($friends[$v['wechatFriendId']]['labels'], true) : [];
|
||||||
$unreadCount = isset($friendUnreadMap[$v['wechatFriendId']]) ? (int)$friendUnreadMap[$v['wechatFriendId']] : 0;
|
$unreadCount = isset($friendUnreadMap[$v['wechatFriendId']]) ? (int)$friendUnreadMap[$v['wechatFriendId']] : 0;
|
||||||
|
$v['aiType'] = isset($aiTypeData[$v['wechatFriendId']]) ? $aiTypeData[$v['wechatFriendId']] : 0;
|
||||||
unset($v['chatroomId']);
|
unset($v['chatroomId']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -24,50 +24,50 @@ class WechatFriendController extends BaseController
|
|||||||
$list = $query->page($page, $limit)->select();
|
$list = $query->page($page, $limit)->select();
|
||||||
|
|
||||||
|
|
||||||
/* // 提取所有好友ID
|
// 提取所有好友ID
|
||||||
$friendIds = array_column($list, 'id');
|
$friendIds = array_column($list, 'id');
|
||||||
|
|
||||||
// 一次性查询所有好友的未读消息数量
|
/* // 一次性查询所有好友的未读消息数量
|
||||||
$unreadCounts = [];
|
$unreadCounts = [];
|
||||||
if (!empty($friendIds)) {
|
if (!empty($friendIds)) {
|
||||||
$unreadResults = Db::table('s2_wechat_message')
|
$unreadResults = Db::table('s2_wechat_message')
|
||||||
->field('wechatFriendId, COUNT(*) as count')
|
->field('wechatFriendId, COUNT(*) as count')
|
||||||
->where('wechatFriendId', 'in', $friendIds)
|
->where('wechatFriendId', 'in', $friendIds)
|
||||||
->where('isRead', 0)
|
->where('isRead', 0)
|
||||||
->group('wechatFriendId')
|
->group('wechatFriendId')
|
||||||
->select();
|
->select();
|
||||||
if (!empty($unreadResults)) {
|
if (!empty($unreadResults)) {
|
||||||
foreach ($unreadResults as $result) {
|
foreach ($unreadResults as $result) {
|
||||||
$unreadCounts[$result['wechatFriendId']] = $result['count'];
|
$unreadCounts[$result['wechatFriendId']] = $result['count'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 一次性查询所有好友的最新消息
|
// 一次性查询所有好友的最新消息
|
||||||
$latestMessages = [];
|
$latestMessages = [];
|
||||||
if (!empty($friendIds)) {
|
if (!empty($friendIds)) {
|
||||||
// 使用子查询获取每个好友的最新消息ID
|
// 使用子查询获取每个好友的最新消息ID
|
||||||
$subQuery = Db::table('s2_wechat_message')
|
$subQuery = Db::table('s2_wechat_message')
|
||||||
->field('MAX(id) as max_id, wechatFriendId')
|
->field('MAX(id) as max_id, wechatFriendId')
|
||||||
->where('wechatFriendId', 'in', $friendIds)
|
->where('wechatFriendId', 'in', $friendIds)
|
||||||
->group('wechatFriendId')
|
->group('wechatFriendId')
|
||||||
->buildSql();
|
->buildSql();
|
||||||
|
|
||||||
if (!empty($subQuery)) {
|
if (!empty($subQuery)) {
|
||||||
// 查询最新消息的详细信息
|
// 查询最新消息的详细信息
|
||||||
$messageResults = Db::table('s2_wechat_message')
|
$messageResults = Db::table('s2_wechat_message')
|
||||||
->alias('m')
|
->alias('m')
|
||||||
->join([$subQuery => 'sub'], 'm.id = sub.max_id')
|
->join([$subQuery => 'sub'], 'm.id = sub.max_id')
|
||||||
->field('m.*, sub.wechatFriendId')
|
->field('m.*, sub.wechatFriendId')
|
||||||
->select();
|
->select();
|
||||||
|
|
||||||
if (!empty($messageResults)) {
|
if (!empty($messageResults)) {
|
||||||
foreach ($messageResults as $message) {
|
foreach ($messageResults as $message) {
|
||||||
$latestMessages[$message['wechatFriendId']] = $message;
|
$latestMessages[$message['wechatFriendId']] = $message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
|
||||||
$aiTypeData = [];
|
$aiTypeData = [];
|
||||||
|
|||||||
Reference in New Issue
Block a user