好友添加记录
This commit is contained in:
@@ -166,4 +166,160 @@ class WechatFriendController extends BaseController
|
||||
|
||||
return ResponseHelper::success(['id' => $friendId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取添加好友任务记录列表(全新功能)
|
||||
* 返回当前账号的所有添加好友任务记录,无论是否通过都展示
|
||||
* 包含:添加者头像、昵称、微信号、添加状态、添加时间、通过时间等信息
|
||||
* @return \think\response\Json
|
||||
*/
|
||||
public function getAddTaskList()
|
||||
{
|
||||
$page = $this->request->param('page', 1);
|
||||
$limit = $this->request->param('limit', 10);
|
||||
$status = $this->request->param('status', ''); // 可选:筛选状态 0执行中,1执行成功,2执行失败
|
||||
$accountId = $this->getUserInfo('s2_accountId');
|
||||
|
||||
if (empty($accountId)) {
|
||||
return ResponseHelper::error('请先登录');
|
||||
}
|
||||
|
||||
// 直接使用operatorAccountId查询添加好友任务记录
|
||||
$query = Db::table('s2_friend_task')
|
||||
->where('operatorAccountId', $accountId)
|
||||
->order('createTime desc');
|
||||
|
||||
// 如果指定了状态筛选
|
||||
if ($status !== '' && $status !== null) {
|
||||
$query->where('status', $status);
|
||||
}
|
||||
|
||||
$total = $query->count();
|
||||
$tasks = $query->page($page, $limit)->select();
|
||||
|
||||
// 提取所有任务的phone和wechatId,用于查询好友信息(获取通过时间)
|
||||
$taskPhones = [];
|
||||
$taskWechatIds = [];
|
||||
foreach ($tasks as $task) {
|
||||
if (!empty($task['phone'])) {
|
||||
$taskPhones[] = $task['phone'];
|
||||
}
|
||||
if (!empty($task['wechatId'])) {
|
||||
$taskWechatIds[] = $task['wechatId'];
|
||||
}
|
||||
}
|
||||
|
||||
// 查询好友信息,获取通过时间
|
||||
$friendPassTimeMap = [];
|
||||
if (!empty($taskPhones) || !empty($taskWechatIds)) {
|
||||
// 分别通过phone和wechatId查询,确保都能匹配到
|
||||
$friendsByPhone = [];
|
||||
$friendsByWechatId = [];
|
||||
|
||||
if (!empty($taskPhones)) {
|
||||
$friendsByPhone = Db::table('s2_wechat_friend')
|
||||
->where('accountId', $accountId)
|
||||
->where('isDeleted', 0)
|
||||
->where('phone', 'in', $taskPhones)
|
||||
->field('phone,wechatId,passTime,nickname')
|
||||
->select();
|
||||
}
|
||||
|
||||
if (!empty($taskWechatIds)) {
|
||||
$friendsByWechatId = Db::table('s2_wechat_friend')
|
||||
->where('accountId', $accountId)
|
||||
->where('isDeleted', 0)
|
||||
->where('wechatId', 'in', $taskWechatIds)
|
||||
->field('phone,wechatId,passTime,nickname')
|
||||
->select();
|
||||
}
|
||||
|
||||
// 合并结果并构建映射表(优先使用phone作为key)
|
||||
$allFriends = array_merge($friendsByPhone, $friendsByWechatId);
|
||||
foreach ($allFriends as $friend) {
|
||||
// 使用phone作为key(如果存在)
|
||||
if (!empty($friend['phone'])) {
|
||||
$friendPassTimeMap[$friend['phone']] = [
|
||||
'passTime' => $friend['passTime'] ?? 0,
|
||||
'nickname' => $friend['nickname'] ?? '',
|
||||
];
|
||||
}
|
||||
// 同时使用wechatId作为key(如果存在且phone为空)
|
||||
if (!empty($friend['wechatId']) && empty($friend['phone'])) {
|
||||
$friendPassTimeMap[$friend['wechatId']] = [
|
||||
'passTime' => $friend['passTime'] ?? 0,
|
||||
'nickname' => $friend['nickname'] ?? '',
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 处理任务数据
|
||||
$list = [];
|
||||
foreach ($tasks as $task) {
|
||||
$taskKey = !empty($task['phone']) ? $task['phone'] : ($task['wechatId'] ?? '');
|
||||
$friendInfo = isset($friendPassTimeMap[$taskKey]) ? $friendPassTimeMap[$taskKey] : null;
|
||||
|
||||
$item = [
|
||||
'taskId' => $task['id'] ?? 0,
|
||||
'phone' => $task['phone'] ?? '',
|
||||
'wechatId' => $task['wechatId'] ?? '',
|
||||
// 添加者信息
|
||||
'adder' => [
|
||||
'avatar' => $task['wechatAvatar'] ?? '', // 添加者头像
|
||||
'nickname' => $task['wechatNickname'] ?? '', // 添加者昵称
|
||||
'username' => $task['accountUsername'] ?? '', // 添加者微信号
|
||||
'accountNickname' => $task['accountNickname'] ?? '', // 账号昵称
|
||||
'accountRealName' => $task['accountRealName'] ?? '', // 账号真实姓名
|
||||
],
|
||||
// 添加状态
|
||||
'status' => [
|
||||
'code' => $task['status'] ?? 0, // 状态码:0执行中,1执行成功,2执行失败
|
||||
'text' => $this->getTaskStatusText($task['status'] ?? 0), // 状态文本
|
||||
],
|
||||
// 时间信息
|
||||
'time' => [
|
||||
'addTime' => !empty($task['createTime']) ? date('Y-m-d H:i:s', $task['createTime']) : '', // 添加时间
|
||||
'addTimeStamp' => $task['createTime'] ?? 0, // 添加时间戳
|
||||
'updateTime' => !empty($task['updateTime']) ? date('Y-m-d H:i:s', $task['updateTime']) : '', // 更新时间
|
||||
'updateTimeStamp' => $task['updateTime'] ?? 0, // 更新时间戳
|
||||
'passTime' => !empty($friendInfo['passTime']) ? date('Y-m-d H:i:s', $friendInfo['passTime']) : '', // 通过时间
|
||||
'passTimeStamp' => $friendInfo['passTime'] ?? 0, // 通过时间戳
|
||||
],
|
||||
// 好友信息(如果已通过)
|
||||
'friend' => [
|
||||
'nickname' => $friendInfo['nickname'] ?? '', // 好友昵称
|
||||
'isPassed' => !empty($friendInfo['passTime']), // 是否已通过
|
||||
],
|
||||
// 其他信息
|
||||
'other' => [
|
||||
'msgContent' => $task['msgContent'] ?? '', // 验证消息
|
||||
'remark' => $task['remark'] ?? '', // 备注
|
||||
'from' => $task['from'] ?? '', // 来源
|
||||
'labels' => !empty($task['labels']) ? explode(',', $task['labels']) : [], // 标签
|
||||
]
|
||||
];
|
||||
|
||||
$list[] = $item;
|
||||
}
|
||||
|
||||
return ResponseHelper::success(['list' => $list, 'total' => $total]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 获取任务状态文本
|
||||
* @param int $status 状态码
|
||||
* @return string 状态文本
|
||||
*/
|
||||
private function getTaskStatusText($status)
|
||||
{
|
||||
$statusMap = [
|
||||
0 => '执行中',
|
||||
1 => '执行成功',
|
||||
2 => '执行失败',
|
||||
];
|
||||
|
||||
return isset($statusMap[$status]) ? $statusMap[$status] : '未知状态';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user