From 270c19d5773a3a6acba6625cde9aba464db40d70 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Sun, 18 May 2025 14:48:26 +0800 Subject: [PATCH] =?UTF-8?q?feat(api):=20=E4=BC=98=E5=8C=96=E4=BA=BA?= =?UTF-8?q?=E5=91=98=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修复了返回数据中的笔误,将 `$result` 更改为 `$res` -增加了用户角色和部门信息的查询 - 使用 `array_unique` 去除了重复的角色和部门 ID - 将角色名称和部门名称拼接成字符串,便于展示 --- .../api/controller/apiController/Personnel.php | 2 +- .../api/apiService/PersonnelService.php | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index add513ac..55f10784 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -39,7 +39,7 @@ class Personnel extends BaseApiService if(!$res){ return fail('账户信息有误'); } - return success($result); + return success($res); } /** diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index 659cc20f..1baf1e1d 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -12,8 +12,10 @@ namespace app\service\api\apiService; use app\model\campus_person_role\CampusPersonRole; +use app\model\departments\Departments; use app\model\member\Member; use app\model\personnel\Personnel; +use app\model\sys\SysRole; use app\service\core\member\CoreMemberService; use core\base\BaseApiService; use core\exception\ApiException; @@ -43,16 +45,26 @@ class PersonnelService extends BaseApiService //查询部门信息 $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); - $role_id = array_column($campus_person_role, 'role_id'); - $dept_id = array_column($campus_person_role, 'dept_id'); + $role_id = array_unique(array_column($campus_person_role, 'role_id')); + $dept_id = array_unique(array_column($campus_person_role, 'dept_id')); + //查询用户角色 + $role_name_arr = SysRole::whereIn('role_id',$role_id)->column('role_name'); + $role_name_str = implode(',',$role_name_arr);// + + //查询部门 + $department_name_arr = Departments::whereIn('id',$dept_id)->column('department_name'); + $department_name_str = implode(',',$department_name_arr); if($res){ $res = $res->toArray(); + $res['role_name_str'] = $role_name_str; + $res['department_name_str'] = $department_name_str; + }else{ $res = []; - return $res; } + return $res; }