From 92d455184a445ee9896d6b4b99961d8fd935e411 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 11:40: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=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E7=9A=84=E5=A5=BD=E5=8F=8B=E6=95=B0=E9=A2=84=E8=A7=88=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../device/GetDeviceListV1Controller.php | 55 +++++++++++++++---- 1 file changed, 44 insertions(+), 11 deletions(-) diff --git a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php index 8ecaed27..8baf0f02 100644 --- a/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php +++ b/Server/application/cunkebao/controller/device/GetDeviceListV1Controller.php @@ -6,6 +6,7 @@ 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\WechatCustomer as WechatCustomerModel; use app\common\model\WechatFriendShip as WechatFriendShipModel; use app\cunkebao\controller\BaseController; use library\ResponseHelper; @@ -92,6 +93,46 @@ class GetDeviceListV1Controller extends BaseController return $query->paginate($this->request->param('limit/d', 10), false, ['page' => $this->request->param('page/d', 1)]); } + /** + * 获取设备最新登录微信的 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'); + } + + /** + * 获取设备绑定的客服信息 + * + * @param string $wechatId + * @return int + * @throws \Exception + */ + protected function getWechatCustomerInfo(string $wechatId): int + { + $curstomer = WechatCustomerModel::field('friendShip') + ->where( + [ + 'companyId' => $this->getUserInfo('companyId'), + 'wechatId' => $wechatId + ] + ) + ->find(); + + return $curstomer->friendShip->totalFriend ?? 0; + } + /** * 统计微信好友 * @@ -103,19 +144,11 @@ class GetDeviceListV1Controller extends BaseController $resultSets = []; foreach ($list->items() as $item) { - $sections = $item->toArray(); + $wechatId = $this->getDeviceLatestWechatLogin($item->id); - if ($item->wechatId) { - $sections['totalFriend'] = WechatFriendShipModel::where( - [ - 'ownerWechatId' => $item->wechatId, - 'companyId' => $this->getUserInfo('companyId') - ] - ) - ->count(); - } + $item->totalFriend = $wechatId ? $this->getWechatCustomerInfo($wechatId) : 0; - array_push($resultSets, $sections); + array_push($resultSets, $item->toArray()); } return $resultSets;