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