From 24fc116d9b136b89eafafac50b113cc1082cc0f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Sat, 10 May 2025 11:04:00 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=81=E5=9F=9F=E6=93=8D=E7=9B=98=E6=89=8B?= =?UTF-8?q?=20-=20=E8=B0=83=E6=95=B4=E5=BE=AE=E4=BF=A1=E5=8F=B7=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E8=BF=94=E5=9B=9E=E5=AD=97=E6=AE=B5=EF=BC=8C=E8=B0=83?= =?UTF-8?q?=E6=95=B4=E6=B7=BB=E5=8A=A0=E5=A5=BD=E5=8F=8B=E8=BF=9B=E5=BA=A6?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/wechat-accounts/page.tsx | 39 +++++++++++++++++-- .../GetWechatsOnDevicesV1Controller.php | 21 +++++----- 2 files changed, 47 insertions(+), 13 deletions(-) diff --git a/Cunkebao/app/wechat-accounts/page.tsx b/Cunkebao/app/wechat-accounts/page.tsx index c831b383..e814b928 100644 --- a/Cunkebao/app/wechat-accounts/page.tsx +++ b/Cunkebao/app/wechat-accounts/page.tsx @@ -20,9 +20,23 @@ import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from " import { toast } from "@/components/ui/use-toast" import { Progress } from "@/components/ui/progress" import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" -import { fetchWechatAccountList, refreshWechatAccounts, transferWechatFriends, transformWechatAccount } from "@/api/wechat-accounts" +import { fetchWechatAccountList, refreshWechatAccounts, transferWechatFriends } from "@/api/wechat-accounts" import { WechatAccount } from "@/types/wechat-account" +// 定义接口以匹配新的数据结构 +interface WechatAccountResponse { + id: number + wechatId: string + nickname: string + avatar: string + times: number + addedCount: number + wechatStatus: number + totalFriend: number + deviceMemo: string + activeTime: string +} + export default function WechatAccountsPage() { const router = useRouter() const [accounts, setAccounts] = useState([]) @@ -49,7 +63,23 @@ export default function WechatAccountsPage() { if (response && response.code === 200 && response.data) { // 转换数据格式 - const wechatAccounts = response.data.list.map(transformWechatAccount); + const wechatAccounts = response.data.list.map((item: any) => { + const account: WechatAccount = { + id: item.id.toString(), + wechatId: item.wechatId, + nickname: item.nickname, + avatar: item.avatar, + remainingAdds: item.times - item.addedCount, + todayAdded: item.addedCount, + status: item.wechatStatus === 1 ? "normal" as const : "abnormal" as const, + friendCount: item.totalFriend, + deviceName: item.deviceMemo, + lastActive: item.activeTime, + maxDailyAdds: item.times, + deviceId: item.id.toString(), + }; + return account; + }); setAccounts(wechatAccounts); setTotalAccounts(response.data.total); } else { @@ -279,7 +309,10 @@ export default function WechatAccountsPage() { {account.todayAdded}/{account.maxDailyAdds} - +
所属设备:{account.deviceName || '未知设备'}
diff --git a/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php b/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php index 81cce9c1..3554d3aa 100644 --- a/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php +++ b/Server/application/cunkebao/controller/wechat/GetWechatsOnDevicesV1Controller.php @@ -18,16 +18,14 @@ use library\ResponseHelper; class GetWechatsOnDevicesV1Controller extends BaseController { /** - * TODO 计算今日可添加好友数量 + * 计算今日可添加好友数量 * * @param string $wechatId * @return int */ protected function getCanAddFriendCount(string $wechatId): int { - $canAddFriendCount = 20; // 最多限制 20 次 - - return $canAddFriendCount < 0 ? 0 : $canAddFriendCount; + return 20; // 最多限制 20 次 } /** @@ -71,7 +69,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController */ protected function getWhereOnDevice(string $wechatId): string { - return DeviceModel::alias('d') + return (string)DeviceModel::alias('d') ->where( [ 'l.wechatId' => $wechatId, @@ -79,7 +77,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController ] ) ->join('device_wechat_login l', 'd.id = l.deviceId') - ->value('d.imei'); + ->value('d.memo'); } /** @@ -150,7 +148,7 @@ class GetWechatsOnDevicesV1Controller extends BaseController } /** - * 获取设备最新活跃时间 + * TODO 获取设备最新活跃时间 * * @param string $wechatId * @return string @@ -191,9 +189,12 @@ class GetWechatsOnDevicesV1Controller extends BaseController protected function getOnlineWechatList(array $where): \think\Paginator { $query = WechatAccountModel::alias('w') - ->field([ - 'w.id', 'w.wechatId', 'w.nickname', 'w.avatar', 'w.s2_wechatAccountId' - ]) + ->field( + [ + 'w.id', 'w.nickname', 'w.avatar', + 'CASE WHEN w.alias IS NULL OR w.alias = "" THEN w.wechatId ELSE w.alias END AS wechatId', + ] + ) ->order('w.id desc'); foreach ($where as $key => $value) {