From 82dc6940f7bd3719b31ae598c2e85817599de26c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Thu, 15 May 2025 18:16:12 +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=AE=BE=E5=A4=87=E5=85=B3=E8=81=94=E5=BE=AE=E4=BF=A1?= =?UTF-8?q?=E7=9A=84=E5=BE=AE=E4=BF=A1=E6=95=B0=E6=8D=AE=E5=86=85=E5=AE=B9?= =?UTF-8?q?=E7=94=B1=E5=8E=9F=E5=85=88=E7=9A=84=E6=A8=A1=E6=8B=9F=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=A1=AB=E5=85=85=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91?= =?UTF-8?q?=EF=BC=8C=E8=B0=83=E6=95=B4=E9=83=A8=E5=88=86=E9=A1=B5=E9=9D=A2?= =?UTF-8?q?=E7=9A=84=E6=95=B0=E6=8D=AE=E5=B1=95=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cunkebao/app/devices/[id]/page.tsx | 4 +- Cunkebao/app/devices/page.tsx | 2 +- Cunkebao/app/traffic-pool/page.tsx | 4 +- Cunkebao/app/wechat-accounts/[id]/page.tsx | 4 +- .../device/GetDeviceDetailV1Controller.php | 68 +++++++++++++++---- .../device/GetDeviceListV1Controller.php | 15 ++-- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/Cunkebao/app/devices/[id]/page.tsx b/Cunkebao/app/devices/[id]/page.tsx index 72ec50a9..e94f9ba9 100644 --- a/Cunkebao/app/devices/[id]/page.tsx +++ b/Cunkebao/app/devices/[id]/page.tsx @@ -891,7 +891,7 @@ export default function DeviceDetailPage() { 好友总数
- {device.totalFriend || 0} + {(device.totalFriend || 0).toLocaleString()}
@@ -900,7 +900,7 @@ export default function DeviceDetailPage() { 消息数量
- {device.thirtyDayMsgCount || 0} + {(device.thirtyDayMsgCount || 0).toLocaleString()}
diff --git a/Cunkebao/app/devices/page.tsx b/Cunkebao/app/devices/page.tsx index 8751f07a..0b2b5310 100644 --- a/Cunkebao/app/devices/page.tsx +++ b/Cunkebao/app/devices/page.tsx @@ -719,7 +719,7 @@ export default function DevicesPage() { IMEI: -
微信号: {device.wechatId || "未绑定"}
+
微信号: {device.wechatId || "未绑定或微信离线"}
好友数: {device.totalFriend}
diff --git a/Cunkebao/app/traffic-pool/page.tsx b/Cunkebao/app/traffic-pool/page.tsx index 62f6fde7..a0571283 100644 --- a/Cunkebao/app/traffic-pool/page.tsx +++ b/Cunkebao/app/traffic-pool/page.tsx @@ -437,11 +437,11 @@ export default function TrafficPoolPage() {
流量池总数
-
{stats.totalCount}
+
{stats.totalCount.toLocaleString()}
今日新增
-
{stats.todayAddCount}
+
{stats.todayAddCount.toLocaleString()}
diff --git a/Cunkebao/app/wechat-accounts/[id]/page.tsx b/Cunkebao/app/wechat-accounts/[id]/page.tsx index 1d24e07e..178a30dd 100644 --- a/Cunkebao/app/wechat-accounts/[id]/page.tsx +++ b/Cunkebao/app/wechat-accounts/[id]/page.tsx @@ -763,7 +763,7 @@ export default function WechatAccountDetailPage() { {accountSummary && ( <> -
{accountSummary.activityLevel.dayTimes}次/天
+
{accountSummary.activityLevel.dayTimes.toLocaleString()}次/天
总聊天数:{accountSummary.activityLevel.allTimes.toLocaleString()}
)} @@ -1010,7 +1010,7 @@ export default function WechatAccountDetailPage() {
- {accountSummary?.restrictions?.length > 0 ? ( + {(accountSummary?.restrictions && accountSummary.restrictions.length > 0) ? ( accountSummary.restrictions.map((record) => (
diff --git a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php index f1889f5e..aa6d62b9 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php @@ -5,8 +5,9 @@ namespace app\cunkebao\controller\device; use app\common\model\Device as DeviceModel; use app\common\model\DeviceTaskconf as DeviceTaskconfModel; use app\common\model\DeviceUser as DeviceUserModel; -use app\common\model\DeviceWechatLogin; +use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel; use app\common\model\User as UserModel; +use app\common\model\WechatCustomer as WechatCustomerModel; use app\common\model\WechatFriendShip as WechatFriendShipModel; use app\cunkebao\controller\BaseController; use Eison\Utils\Helper\ArrHelper; @@ -47,10 +48,10 @@ class GetDeviceDetailV1Controller extends BaseController protected function parseExtraForBattery(string $extra): int { if (!empty($extra)) { - $extra = json_decode($extra, true); + $extra = json_decode($extra); - if (is_array($extra) && isset($extra['battery'])) { - return intval($extra['battery']); + if ($extra && isset($extra->battery)) { + return intval($extra->battery); } } @@ -83,6 +84,25 @@ class GetDeviceDetailV1Controller extends BaseController return ArrHelper::getValue('autoAddFriend,autoReply,momentsSync,aiChat', [], 0); } + /** + * 获取设备最新登录微信的 wechatId + * + * @param int $deviceId + * @return string|null + * @throws \Exception + */ + protected function getDeviceLatestWechatLogin(int $deviceId): ?string + { + return DeviceWechatLoginModel::where( + [ + 'companyId' => $this->getUserInfo('companyId'), + 'deviceId' => $deviceId, + 'alive' => DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE + ] + ) + ->value('wechatId'); + } + /** * 统计设备登录微信的好友 * @@ -92,24 +112,43 @@ class GetDeviceDetailV1Controller extends BaseController */ protected function getTotalFriend(int $deviceId): int { - $companyId = $this->getUserInfo('companyId'); - - $ownerWechatId = DeviceWechatLogin::where(compact('companyId', 'deviceId'))->order('createTime desc')->value('wechatId'); + $ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId); if ($ownerWechatId) { - return WechatFriendShipModel::where(['ownerWechatId' => $ownerWechatId])->count(); + return WechatFriendShipModel::where( + [ + 'companyId' => $this->getUserInfo('companyId'), + 'ownerWechatId' => $ownerWechatId + ] + ) + ->count(); } return 0; } /** - * TODO 获取设备绑定微信的消息总数 + * 获取设备绑定微信的消息总数 * + * @param int $deviceId * @return int */ - protected function getThirtyDayMsgCount(): int + protected function getThirtyDayMsgCount(int $deviceId): int { + $ownerWechatId = $this->getDeviceLatestWechatLogin($deviceId); + + if ($ownerWechatId) { + $activity = (string)WechatCustomerModel::where( + [ + 'wechatId' => $ownerWechatId, + 'companyId' => $this->getUserInfo('companyId') + ] + ) + ->value('activity'); + + return json_decode($activity)->totalMsgCount ?? 0; + } + return 0; } @@ -134,7 +173,7 @@ class GetDeviceDetailV1Controller extends BaseController $device['battery'] = $this->parseExtraForBattery($device['extra']); $device['features'] = $this->getTaskConfig($id); $device['totalFriend'] = $this->getTotalFriend($id); - $device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount(); + $device['thirtyDayMsgCount'] = $this->getThirtyDayMsgCount($id); // 设备最后活跃时间为设备状态更新时间 $device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']); @@ -147,6 +186,7 @@ class GetDeviceDetailV1Controller extends BaseController /** * 获取设备详情 + * * @return \think\response\Json */ public function index() @@ -158,9 +198,9 @@ class GetDeviceDetailV1Controller extends BaseController $this->checkUserDevicePermission($id); } - $resultSet = $this->getDeviceInfo($id); - - return ResponseHelper::success($resultSet); + return ResponseHelper::success( + $this->getDeviceInfo($id) + ); } catch (\Exception $e) { return ResponseHelper::error($e->getMessage(), $e->getCode()); } diff --git a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php index 5862262e..8ecaed27 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php @@ -4,6 +4,7 @@ namespace app\cunkebao\controller\device; use app\common\model\Device as DeviceModel; use app\common\model\DeviceUser as DeviceUserModel; +use app\common\model\DeviceWechatLogin as DeviceWechatLoginModel; use app\common\model\User as UserModel; use app\common\model\WechatFriendShip as WechatFriendShipModel; use app\cunkebao\controller\BaseController; @@ -73,10 +74,10 @@ class GetDeviceListV1Controller extends BaseController ->field([ 'd.id', 'd.imei', 'd.memo', 'd.alive', 'l.wechatId', - 'wa.nickname', 'wa.alias', '0 totalFriend' + 'a.nickname', 'a.alias', '0 totalFriend' ]) - ->leftJoin('device_wechat_login l', 'd.id = l.deviceId') - ->leftJoin('wechat_account wa', 'l.wechatId = wa.wechatId') + ->leftJoin('device_wechat_login l', 'd.id = l.deviceId and l.alive =' . DeviceWechatLoginModel::ALIVE_WECHAT_ACTIVE) + ->leftJoin('wechat_account a', 'l.wechatId = a.wechatId') ->order('d.id desc'); foreach ($where as $key => $value) { @@ -105,7 +106,13 @@ class GetDeviceListV1Controller extends BaseController $sections = $item->toArray(); if ($item->wechatId) { - $sections['totalFriend'] = WechatFriendShipModel::where(['ownerWechatId' => $item->wechatId])->count(); + $sections['totalFriend'] = WechatFriendShipModel::where( + [ + 'ownerWechatId' => $item->wechatId, + 'companyId' => $this->getUserInfo('companyId') + ] + ) + ->count(); } array_push($resultSets, $sections);