From 1171215979e255489cd4cde1bd6b5e627a4be40b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Mon, 19 May 2025 10:40:46 +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=E4=BF=AE=E6=94=B9=E8=AE=BE=E5=A4=87=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E7=9A=84=E8=BF=94=E5=9B=9E=E4=BD=BF=E4=B9=8B=E6=9B=B4=E7=AC=A6?= =?UTF-8?q?=E5=90=88=20RESTful=20=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/GetDeviceDetailV1Controller.php | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php index e42f5a9e..85e9823f 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceDetailV1Controller.php @@ -59,7 +59,6 @@ class GetDeviceDetailV1Controller extends BaseController return 0; } - /** * 获取设备最新登录微信的 wechatId * @@ -80,16 +79,46 @@ class GetDeviceDetailV1Controller extends BaseController } /** - * 获取设备详情 - * @param int $id 设备ID - * @return array|null 设备信息 + * 获取设备绑定的客服信息 + * + * @param int $deviceId + * @return array + * @throws \Exception */ - protected function getDeviceInfo(int $id) + protected function getWechatCustomerInfo(int $deviceId): array + { + $curstomer = WechatCustomerModel::field('activity,friendShip') + ->where( + [ + 'companyId' => $this->getUserInfo('companyId'), + 'wechatId' => $this->getDeviceLatestWechatLogin($deviceId) + ] + ) + ->find(); + + return $curstomer ? [ + 'lastUpdateTime' => $curstomer->activity->lastActivityTime ?? '', + 'thirtyDayMsgCount' => $curstomer->activity->totalMsgCount ?? 0, + 'totalFriend' => $curstomer->friendShip->totalFriend ?? 0, + ] : [ + 'lastUpdateTime' => '', + 'thirtyDayMsgCount' => 0, + 'totalFriend' => 0, + ]; + } + + /** + * 获取设备详情 + * + * @param int $id + * @return array + */ + protected function getDeviceInfo(int $id): array { // 查询设备基础信息与关联的微信账号信息 $device = DeviceModel::alias('d') ->field([ - 'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.updateTime as lastUpdateTime', 'd.extra' + 'd.id', 'd.imei', 'd.memo', 'd.alive', 'd.extra' ]) ->find($id); @@ -97,13 +126,12 @@ class GetDeviceDetailV1Controller extends BaseController throw new \Exception('设备不存在', 404); } - $device['battery'] = $this->parseExtraForBattery($device['extra']); - $device['lastUpdateTime'] = date('Y-m-d H:i:s', $device['lastUpdateTime']); + $device->battery = $this->parseExtraForBattery($device->extra); // 删除冗余字段 - unset($device['extra']); + unset($device->extra); - return $device; + return $device->toArray(); } /** @@ -121,10 +149,10 @@ class GetDeviceDetailV1Controller extends BaseController } return ResponseHelper::success( - $this->getDeviceInfo($id) + $this->getDeviceInfo($id) + $this->getWechatCustomerInfo($id) ); } catch (\Exception $e) { return ResponseHelper::error($e->getMessage(), $e->getCode()); } } -} \ No newline at end of file +} \ No newline at end of file