diff --git a/Cunkebao/app/wechat-accounts/[id]/page.tsx b/Cunkebao/app/wechat-accounts/[id]/page.tsx index 7569aa58..f00f9182 100644 --- a/Cunkebao/app/wechat-accounts/[id]/page.tsx +++ b/Cunkebao/app/wechat-accounts/[id]/page.tsx @@ -398,17 +398,17 @@ export default function WechatAccountDetailPage() { setIsFetchingFriends(true); setHasFriendLoadError(false); - const data = await api.get>(`/v1/wechats/${id}/friends?page=${page}&limit=30`, true); + const response = await api.get>(`/v1/wechats/${id}/friends?page=${page}&limit=30${searchQuery ? `&search=${encodeURIComponent(searchQuery)}` : ''}`, true); - if (data && data.code === 200) { + if (response && response.code === 200 && response.data) { // 更新总数计数 if (isNewSearch || friendsTotal === 0) { - setFriendsTotal(data.data.total || 0); + setFriendsTotal(response.data.total || 0); } - const newFriends = data.data.list.map((friend) => ({ + const newFriends = response.data.list.map((friend) => ({ id: friend.id.toString(), - avatar: friend.avatar, + avatar: friend.avatar || '/placeholder.svg', nickname: friend.nickname, wechatId: friend.wechatId, remark: friend.memo || '', @@ -433,13 +433,12 @@ export default function WechatAccountDetailPage() { setFriendsPage(page); // 判断是否还有更多数据 - setHasMoreFriends(page * 30 < data.data.total); - + setHasMoreFriends(page * 30 < response.data.total); } else { setHasFriendLoadError(true); toast({ title: "获取好友列表失败", - description: data?.msg || "请稍后再试", + description: response?.msg || "请稍后再试", variant: "destructive" }); } @@ -454,7 +453,7 @@ export default function WechatAccountDetailPage() { } finally { setIsFetchingFriends(false); } - }, [account, id, friendsTotal]); + }, [account, id, friendsTotal, searchQuery]); // 处理搜索 const handleSearch = useCallback(() => { diff --git a/Server/application/cunkebao/controller/TrafficPool.php b/Server/application/cunkebao/controller/TrafficPool.php deleted file mode 100644 index b5099d6c..00000000 --- a/Server/application/cunkebao/controller/TrafficPool.php +++ /dev/null @@ -1,67 +0,0 @@ - 400, - 'msg' => '缺少必要参数' - ]); - } - - // 批量处理数据 - $successCount = 0; - $failCount = 0; - - foreach ($data['mobile'] as $index => $mobile) { - // 导入到流量池 - $poolData[] = [ - 'mobile' => $mobile, - 'from' => $data['from'][$index] ?? '', - 'createTime' => time() - ]; - - // 导入到流量来源 - $sourceData[] = [ - 'mobile' => $mobile, - 'sceneId' => $data['sceneId'], - 'createTime' => time() - ]; - } - - return json([ - 'code' => 200, - 'msg' => '导入完成', - 'data' => [ - 'success' => $successCount, - 'fail' => $failCount - ] - ]); - - } catch (\Exception $e) { - return json([ - 'code' => 500, - 'msg' => '导入失败:' . $e->getMessage() - ]); - } - } -} \ No newline at end of file diff --git a/Server/application/cunkebao/controller/traffic/TrafficPool.php b/Server/application/cunkebao/controller/traffic/TrafficPool.php new file mode 100644 index 00000000..50b6ab6e --- /dev/null +++ b/Server/application/cunkebao/controller/traffic/TrafficPool.php @@ -0,0 +1,13 @@ +where('companyId', $companyId); - } - - // 提取设备ID - $records = $query->select(); - $deviceIds = []; - - foreach ($records as $record) { - if (!empty($record['deviceId'])) { - $deviceIds[] = $record['deviceId']; - } - } - - return $deviceIds; - } - - /** - * 添加设备微信登录记录 - * @param int $deviceId 设备ID - * @param string $wechatId 微信ID - * @param int $companyId 公司/租户ID - * @return int 新增记录ID - */ - public static function addRecord($deviceId, $wechatId, $companyId) - { - // 检查是否已存在相同记录 - $exists = self::where('deviceId', $deviceId) - ->where('wechatId', $wechatId) - ->where('companyId', $companyId) - ->find(); - - if ($exists) { - return $exists['id']; - } - - // 创建新记录 - $model = new self(); - $model->deviceId = $deviceId; - $model->wechatId = $wechatId; - $model->companyId = $companyId; - $model->save(); - - return $model->id; - } - - /** - * 删除设备微信登录记录 - * @param int $deviceId 设备ID - * @param string $wechatId 微信ID,为null时删除设备所有记录 - * @param int $companyId 公司/租户ID,为null时不限公司 - * @return bool 删除结果 - */ - public static function removeRecord($deviceId, $wechatId = null, $companyId = null) - { - $query = self::where('deviceId', $deviceId); - - if ($wechatId !== null) { - $query->where('wechatId', $wechatId); - } - - if ($companyId !== null) { - $query->where('companyId', $companyId); - } - - return $query->delete(); - } - - /** - * 关联Device模型 - * @return \think\model\relation\BelongsTo - */ - public function device() - { - return $this->belongsTo('Device', 'deviceId'); - } - - /** - * 获取设备关联的微信账号信息 - * @param int $deviceId 设备ID - * @param int $companyId 公司/租户ID - * @return array 微信账号信息列表 - */ - public static function getDeviceRelatedAccounts($deviceId, $companyId = null) - { - // 获取设备关联的微信ID列表 - $wechatIds = self::getDeviceWechatIds($deviceId, $companyId); - if (empty($wechatIds)) { - return []; - } - - // 查询微信账号信息 - $accounts = \think\Db::name('wechat_account') - ->alias('wa') - ->field([ - 'wa.id', - 'wa.wechatId', - 'wa.accountNickname', - 'wa.nickname', - 'wa.accountUserName', - 'wa.avatar', - 'wa.gender', - 'wa.wechatAlive', - 'wa.status', - 'wa.totalFriend', - 'wa.createTime', - 'wa.updateTime' - ]) - ->whereIn('wa.wechatId', $wechatIds) - ->where('wa.isDeleted', 0) - ->select(); - - // 处理结果数据 - $result = []; - foreach ($accounts as $account) { - // 计算最后活跃时间 - $lastActive = date('Y-m-d H:i:s', max($account['updateTime'], $account['createTime'])); - - // 格式化数据 - $result[] = [ - 'id' => $account['id'], - 'wechatId' => $account['wechatId'], - 'nickname' => $account['accountNickname'] ?: $account['nickname'] ?: '未命名微信', - 'accountUserName' => $account['accountUserName'], - 'avatar' => $account['avatar'], - 'gender' => intval($account['gender']), - 'status' => intval($account['status']), - 'statusText' => intval($account['status']) === 1 ? '可加友' : '已停用', - 'wechatAlive' => intval($account['wechatAlive']), - 'wechatAliveText' => intval($account['wechatAlive']) === 1 ? '正常' : '异常', - 'totalFriend' => intval($account['totalFriend']), - 'lastActive' => $lastActive - ]; - } - - return $result; - } -} \ No newline at end of file diff --git a/Server/application/cunkebao/model/TrafficPool.php b/Server/application/cunkebao/model/TrafficPool.php deleted file mode 100644 index 4e50da16..00000000 --- a/Server/application/cunkebao/model/TrafficPool.php +++ /dev/null @@ -1,11 +0,0 @@ -where('deleteTime', 0) // 只查询未删除的记录 - ->order($order) - ->paginate($limit, false, [ - 'page' => $page - ]); - } -} \ No newline at end of file diff --git a/Server/application/cunkebao/model/WechatAccount.php b/Server/application/cunkebao/model/WechatAccount.php deleted file mode 100644 index b8a68ca2..00000000 --- a/Server/application/cunkebao/model/WechatAccount.php +++ /dev/null @@ -1,57 +0,0 @@ - 1, - 'wechatAlive' => 1, - 'isDeleted' => 0 - ]; - - // 合并额外条件 - if (!empty($where)) { - $condition = array_merge($condition, $where); - } - - return self::where($condition)->count(); - } - - /** - * 获取有登录微信的设备数量 - * - * @param array $where 额外的查询条件 - * @return int 设备数量 - */ - public static function getDeviceWithWechatCount($where = []) - { - $condition = [ - 'deviceAlive' => 1, - 'isDeleted' => 0 - ]; - - // 合并额外条件 - if (!empty($where)) { - $condition = array_merge($condition, $where); - } - - return self::where($condition)->count(); - } -} \ No newline at end of file