From 6ab9305667984b05f8543065b64ea21c73786fdc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9F=B3=E6=B8=85=E7=88=BD?= Date: Wed, 23 Apr 2025 12:10:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B6=85=E7=AE=A1=E5=90=8E=E5=8F=B0=20-=20?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E8=AF=A6=E6=83=85=E9=A1=B9=E7=9B=AE=E6=A6=82?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/superadmin/config/route.php | 1 + .../GetCompanyDetailForProfileController.php | 112 ++++++++++++++++++ 2 files changed, 113 insertions(+) create mode 100644 Server/application/superadmin/controller/company/GetCompanyDetailForProfileController.php diff --git a/Server/application/superadmin/config/route.php b/Server/application/superadmin/config/route.php index 485573c2..e4514efd 100644 --- a/Server/application/superadmin/config/route.php +++ b/Server/application/superadmin/config/route.php @@ -40,5 +40,6 @@ Route::group('', function () { Route::post('delete', 'app\superadmin\controller\company\DeleteCompanyController@index'); Route::get('list', 'app\superadmin\controller\company\GetCompanyListController@index'); Route::get('detail/:id', 'app\superadmin\controller\company\GetCompanyDetailForUpdateController@index'); + Route::get('profile/:id', 'app\superadmin\controller\company\GetCompanyDetailForProfileController@index'); }); })->middleware(['app\superadmin\middleware\AdminAuth']); \ No newline at end of file diff --git a/Server/application/superadmin/controller/company/GetCompanyDetailForProfileController.php b/Server/application/superadmin/controller/company/GetCompanyDetailForProfileController.php new file mode 100644 index 00000000..7c51ecfa --- /dev/null +++ b/Server/application/superadmin/controller/company/GetCompanyDetailForProfileController.php @@ -0,0 +1,112 @@ +column('wechatId'); + + return array_unique($wechatId); + } + + /** + * 统计微信好友数量 + * + * @param int $companyId + * @return int + */ + protected function getFriendCountByCompanyId(int $companyId): int + { + $wechatIds = $this->getDeveiceWechats($companyId); + + return WechatFriendModel::whereIn('ownerWechatId', $wechatIds)->count(); + } + + /** + * 根据 CompanyId 获取设备数量 + * + * @param int $companyId + * @return int + */ + protected function getDeviceCountByCompanyId(int $companyId): int + { + return DeviceModel::where('companyId', $companyId)->count(); + } + + /** + * 根据 CompanyId 获取子账号数量 + * + * @param int $companyId + * @return int + */ + protected function getUsersCountByCompanyId(int $companyId): int + { + return UserModel::where('companyId', $companyId)->count(); + } + + /** + * 获取项目详情 + * + * @param int $id + * @return CompanyModel + * @throws \Exception + */ + protected function getCompanyDetail(int $id): array + { + $detail = CompanyModel::alias('c') + ->field([ + 'c.id', 'c.name', 'c.memo', 'c.companyId', 'c.createTime', + 'u.account', 'u.phone' + ]) + ->leftJoin('users u', 'c.companyId = u.companyId and u.isAdmin = 1') + ->find($id); + + if (!$detail) { + throw new \Exception('项目不存在', 404); + } + + return $detail->toArray(); + } + + /** + * 获取项目详情 + * + * @param int $id + * @return \think\response\Json + */ + public function index($id) + { + try { + $data = $this->getCompanyDetail($id); + + $userCount = $this->getUsersCountByCompanyId($id); + $deviceCount = $this->getDeviceCountByCompanyId($id); + $friendCount = $this->getFriendCountByCompanyId($id); + + return ResponseHelper::success( + array_merge($data, compact('deviceCount', 'friendCount', 'userCount')) + ); + } catch (\Exception $e) { + return ResponseHelper::error($e->getMessage(), $e->getCode()); + } + } +} \ No newline at end of file