From 45c4c23c166335a1120599bbb67a2db400dadf7d Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 22 May 2025 12:01:21 +0800 Subject: [PATCH 1/5] =?UTF-8?q?feat(PersonnelService):=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=91=98=E5=B7=A5=E4=BF=A1=E6=81=AF=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3=E8=BF=94=E5=9B=9E=E6=A0=A1=E5=8C=BA=E5=92=8C?= =?UTF-8?q?=E9=83=A8=E9=97=A8=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在查询员工信息时,增加了对用户角色校区部门信息的查询 - 将原有的单一部门查询改为校区+部门的组合查询 - 优化了数据处理逻辑,去重并整理校区和部门信息 - 新增 cameus_dept_arr 字段,包含校区 ID、校区名称和对应的部门信息 --- .../api/apiService/PersonnelService.php | 54 +++++++++++++++++-- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index be3833b4..e7e686d7 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -53,8 +53,14 @@ class PersonnelService extends BaseApiService } $data = $model->field($field)->find();//员工信息 - //查询部门信息 - $campus_person_role = CampusPersonRole::where('person_id',$where['id'])->select()->toArray(); + //查询用户角色校区部门信息 + $campus_person_role = CampusPersonRole::where('person_id',$where['id']) + ->with([ + 'campus' => function ($query) {}, + 'sysRole' => function ($query) {}, + 'departments' => function ($query) {} + ]) + ->select()->toArray(); $role_id = array_unique(array_column($campus_person_role, 'role_id')); $dept_id = array_unique(array_column($campus_person_role, 'dept_id')); //查询用户角色 @@ -68,10 +74,47 @@ class PersonnelService extends BaseApiService $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); + //校区部门 + // 初始化新的校区-部门合并数组 和 部门名称字符串 + $cameus_dept_arr = []; + $department_name_arr = []; + foreach ($campus_person_role as $v) { + $campusId = $v['campus_id']; + $deptId = $v['dept_id']; + $deptName = $v['dept_id_name']; + + // 收集部门名称 + $department_name_arr[] = $deptName; + + // 构建校区+部门结构 + if (!isset($cameus_dept_arr[$campusId])) { + $cameus_dept_arr[$campusId] = [ + 'campus_id' => $campusId, + 'campus_id_name' => $v['campus_id_name'], + 'dept_arr' => [] + ]; + } + + // 检查去重 + $exists = false; + foreach ($cameus_dept_arr[$campusId]['dept_arr'] as $dept) { + if ($dept['dept_id'] === $deptId) { + $exists = true; + break; + } + } + + if (!$exists) { + $cameus_dept_arr[$campusId]['dept_arr'][] = [ + 'dept_id' => $deptId, + 'dept_name' => $deptName + ]; + } + } + // 最终转换 + $cameus_dept_arr = array_values($cameus_dept_arr); + $department_name_str = implode(',', $department_name_arr); if($data){ $data = $data->toArray(); @@ -79,6 +122,7 @@ class PersonnelService extends BaseApiService $data['role_name_str'] = $role_name_str; $data['role_key_arr'] = $role_key_arr; $data['department_name_str'] = $department_name_str; + $data['cameus_dept_arr'] = $cameus_dept_arr;//校区+部门的组合 $res['code'] = 1; $res['msg'] = '操作成功'; From f9ac6fbae016b739563cd694da12eea5d154c969 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 22 May 2025 16:26:51 +0800 Subject: [PATCH 2/5] =?UTF-8?q?feat(personnel):=20=E5=91=98=E5=B7=A5?= =?UTF-8?q?=E7=AB=AF=E5=A2=9E=E5=8A=A0=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 checkOldPwd 方法用于验证旧密码是否正确 - 新增 edidPassword 方法用于修改员工登录密码 - 在路由中添加相应的 API 接口 - 优化了代码格式和命名规范 --- .../controller/apiController/Personnel.php | 31 +++ niucloud/app/api/route/route.php | 6 + .../api/apiService/PersonnelService.php | 192 +++++++++++++----- 3 files changed, 180 insertions(+), 49 deletions(-) diff --git a/niucloud/app/api/controller/apiController/Personnel.php b/niucloud/app/api/controller/apiController/Personnel.php index b5f63cdf..96e18ff8 100644 --- a/niucloud/app/api/controller/apiController/Personnel.php +++ b/niucloud/app/api/controller/apiController/Personnel.php @@ -81,5 +81,36 @@ class Personnel extends BaseApiService return success($res); } + //验证新旧密码是否正确 + public function checkOldPwd(Request $request){ + //获取员工信息 + $old_password = $request->param('old_password',''); + if(empty($old_password)){ + return fail('请输入旧密码'); + } + $res = (new PersonnelService())->checkOldPwd($old_password); + if(!$res['code']){ + return fail('旧密码不正确'); + } + return success($res['data']); + } + + //员工端-修改登录密码 + public function edidPassword(Request $request){ + $new_password = $request->param('new_password','');//新密码 + $key_value = $request->param('key_value','');//修改密码的key_value + $phone = $request->param('phone','');//登录账号 + + if(empty($new_password) || empty($key_value)){ + return fail('缺少参数'); + } + + $res = (new PersonnelService())->edidPassword($phone,$new_password,$key_value); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + + } } diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 1e0e64e6..a73e32ed 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -173,6 +173,8 @@ Route::group(function () { Route::post('personnelLogin', 'login.Login/personnelLogin'); //获取字典 Route::get('common/getDictionary', 'apiController.Common/getDictionary'); + //员工端-修改密码操作 + Route::post('personnel/edidPassword', 'apiController.Personnel/edidPassword'); @@ -202,6 +204,10 @@ Route::group(function () { Route::get('personnel/info', 'apiController.Personnel/info'); //员工端-修改 Route::post('personnel/edit', 'apiController.Personnel/edit'); + //员工端-验证旧密码是否正确 + Route::post('personnel/checkOldPwd', 'apiController.Personnel/checkOldPwd'); + + //员工端-获取全部人员列表 Route::get('personnel/getPersonnelAll', 'apiController.Personnel/getPersonnelAll'); //客户资源-添加 diff --git a/niucloud/app/service/api/apiService/PersonnelService.php b/niucloud/app/service/api/apiService/PersonnelService.php index e7e686d7..8ac1516e 100644 --- a/niucloud/app/service/api/apiService/PersonnelService.php +++ b/niucloud/app/service/api/apiService/PersonnelService.php @@ -16,10 +16,9 @@ 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 app\model\sys\SysUser; use core\base\BaseApiService; -use core\exception\ApiException; -use core\util\Barcode; +use think\facade\Cache; use think\Model; /** @@ -36,52 +35,56 @@ class PersonnelService extends BaseApiService } //获取员工信息 - public function info(array $where,string $field = '*'){ + public function info(array $where, string $field = '*') + { $model = $this->model; $res = [ - 'code'=>0, - 'msg'=>'请添加检索条件', - 'data'=>[] + 'code' => 0, + 'msg' => '请添加检索条件', + 'data' => [] ]; - if(!$where){ + if (!$where) { return $res; } - if(!empty($where['id'])){ - $model = $model->where('id',$where['id']); + if (!empty($where['id'])) { + $model = $model->where('id', $where['id']); } $data = $model->field($field)->find();//员工信息 //查询用户角色校区部门信息 - $campus_person_role = CampusPersonRole::where('person_id',$where['id']) + $campus_person_role = CampusPersonRole::where('person_id', $where['id']) ->with([ - 'campus' => function ($query) {}, - 'sysRole' => function ($query) {}, - 'departments' => function ($query) {} + 'campus' => function ($query) { + }, + 'sysRole' => function ($query) { + }, + 'departments' => function ($query) { + } ]) ->select()->toArray(); $role_id = array_unique(array_column($campus_person_role, 'role_id')); $dept_id = array_unique(array_column($campus_person_role, 'dept_id')); //查询用户角色 - $role = SysRole::whereIn('role_id',$role_id)->where('status',1)->field('role_id,role_name,role_key,addon_keys,status')->select()->toArray(); + $role = SysRole::whereIn('role_id', $role_id)->where('status', 1)->field('role_id,role_name,role_key,addon_keys,status')->select()->toArray(); $role_name_arr = []; $role_key_arr = []; - foreach($role as $v){ + foreach ($role as $v) { $role_name_arr[] = $v['role_name']; $role_key_arr[] = $v['role_key']; } - $role_name_str = implode(',',$role_name_arr);// + $role_name_str = implode(',', $role_name_arr);// //校区部门 // 初始化新的校区-部门合并数组 和 部门名称字符串 $cameus_dept_arr = []; $department_name_arr = []; foreach ($campus_person_role as $v) { - $campusId = $v['campus_id']; - $deptId = $v['dept_id']; - $deptName = $v['dept_id_name']; + $campusId = $v['campus_id']; + $deptId = $v['dept_id']; + $deptName = $v['dept_id_name']; // 收集部门名称 $department_name_arr[] = $deptName; @@ -89,9 +92,9 @@ class PersonnelService extends BaseApiService // 构建校区+部门结构 if (!isset($cameus_dept_arr[$campusId])) { $cameus_dept_arr[$campusId] = [ - 'campus_id' => $campusId, + 'campus_id' => $campusId, 'campus_id_name' => $v['campus_id_name'], - 'dept_arr' => [] + 'dept_arr' => [] ]; } @@ -106,7 +109,7 @@ class PersonnelService extends BaseApiService if (!$exists) { $cameus_dept_arr[$campusId]['dept_arr'][] = [ - 'dept_id' => $deptId, + 'dept_id' => $deptId, 'dept_name' => $deptName ]; } @@ -116,9 +119,9 @@ class PersonnelService extends BaseApiService $cameus_dept_arr = array_values($cameus_dept_arr); $department_name_str = implode(',', $department_name_arr); - if($data){ + if ($data) { $data = $data->toArray(); - $data['role']=$role; + $data['role'] = $role; $data['role_name_str'] = $role_name_str; $data['role_key_arr'] = $role_key_arr; $data['department_name_str'] = $department_name_str; @@ -127,10 +130,10 @@ class PersonnelService extends BaseApiService $res['code'] = 1; $res['msg'] = '操作成功'; $res['data'] = $data; - }else{ + } else { $data = []; $res['code'] = 0; - $res['msg'] = '为找到数据'; + $res['msg'] = '未找到数据'; $res['data'] = $data; } @@ -139,31 +142,32 @@ class PersonnelService extends BaseApiService } //员工信息-修改 - public function edit(array $where,array $data){ + public function edit(array $where, array $data) + { $data['update_time'] = date('Y-m-d H:i:s'); - if(!$where){ + if (!$where) { return [ - 'code'=>0, - 'msg'=>'查询条件不能为空' + 'code' => 0, + 'msg' => '查询条件不能为空' ]; } $model = $this->model; - if(!empty($where['id'])){ - $model = $model->where('id',$where['id']); + if (!empty($where['id'])) { + $model = $model->where('id', $where['id']); } $res = $model->update($data);//员工信息 - if($res){ + if ($res) { $res = [ - 'code'=>1, - 'msg'=>'操作成功' + 'code' => 1, + 'msg' => '操作成功' ]; - }else{ + } else { $res = [ - 'code'=>0, - 'msg'=>'操作失败' + 'code' => 0, + 'msg' => '操作失败' ]; } return $res; @@ -171,7 +175,7 @@ class PersonnelService extends BaseApiService } //员工信息-获取全部用户 - public function getAll(array $where,string $field = '*') + public function getAll(array $where, string $field = '*') { if (!$where) { return [ @@ -209,7 +213,96 @@ class PersonnelService extends BaseApiService return $res; } + //验证旧密码 + public function checkOldPwd(string $old_passowrd) + { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + $personnel_id = $this->member_id; + $phone = $this->model->where('id', $personnel_id)->value('phone'); + $password = (new SysUser())->where('username', $phone)->value('password'); + if (!check_password($old_passowrd, $password)) { + $res['msg'] = '旧密码错误'; + return $res; + } + $res['code'] = 1; + $res['msg'] = '密码正确'; + $res['data'] = [ + 'key_value' => $this->setEditPasswordKey($phone) + ]; + return $res; + } + + //设置新密码 + public function edidPassword($phone, $new_password, $key_value) + { + $checkEditPasswordKey = $this->checkEditPasswordKey($phone, $key_value);//验证修改密码允许的缓存key + if (!$checkEditPasswordKey['code']) { + return $checkEditPasswordKey; + } + //查询用户修改密码 + $update = (new SysUser())->where('username', $phone)->update([ + 'password' => create_password($new_password),//创建密码 + 'update_time' => time(), + ]); + if (!$update) { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } + return $res; + } + + + //生成修改密码允许的缓存key + public function setEditPasswordKey(string $phone) + { + $key_name = 'edit_password_' . $phone; + //生成字符串,存入cache中 + //check_password()//验证 + //create_password()//创建 + + $key_value = create_password($key_name); + // 缓存在3600秒之后过期 + Cache::set($key_name, $key_value, 3600); + return $key_value; + } + + //验证修改密码允许的缓存key + public function checkEditPasswordKey(string $phone, string $key_value) + { + $res = [ + 'code' => 0, + 'msg' => '' + ]; + $key_name = 'edit_password_' . $phone; + $key_value_cache = Cache::get($key_name); + if (empty($key_value_cache)) { + $res['msg'] = '参数已过期,请重新输入旧密码进行验证'; + return $res; + } + + //验证 + if ($key_value_cache != $key_value) { + $res['msg'] = '参数不正确,请重新输入旧密码进行验证'; + return $res; + } + $res['code'] = 1; + $res['msg'] = '操作成功'; + return $res; + } /** @@ -217,28 +310,29 @@ class PersonnelService extends BaseApiService * @param array $data * @return Member|array|mixed|Model !!! 仔细看,返回值是模型对象 如果想要判断是否为空 请用 $member->isEmpty() */ - public function findMemberInfo(array $data){ + public function findMemberInfo(array $data) + { //会员账号 - if(!empty($data['username'])) + if (!empty($data['username'])) $where[] = ['username', '=', $data['username']]; //会员手机号 - if(!empty($data['mobile'])) + if (!empty($data['mobile'])) $where[] = ['mobile', '=', $data['mobile']]; //会员id - if(!empty($data['id'])) + if (!empty($data['id'])) $where[] = ['id', '=', $data['id']]; //微信公众号openid - if(!empty($data['wx_openid'])) + if (!empty($data['wx_openid'])) $where[] = ['wx_openid', '=', $data['wx_openid']]; //微信小程序openid - if(!empty($data['weapp_openid'])) + if (!empty($data['weapp_openid'])) $where[] = ['weapp_openid', '=', $data['weapp_openid']]; // 微信unionid - if(!empty($data['wx_unionid'])) + if (!empty($data['wx_unionid'])) $where[] = ['wx_unionid', '=', $data['wx_unionid']]; - if(!empty($data['username|mobile'])) + if (!empty($data['username|mobile'])) $where[] = ['username|mobile', '=', $data['username|mobile']]; - if(empty($where)){ + if (empty($where)) { $where[] = ['member_id', '=', -1]; } return $this->model->where($where)->findOrEmpty(); From 1b411edf5958d283f9ab940388a9bfe3c2eec100 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 22 May 2025 18:07:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E6=B2=9F?= =?UTF-8?q?=E9=80=9A=E8=AE=B0=E5=BD=95=E5=8A=9F=E8=83=BD-=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20CommunicationRecords=20=E6=8E=A7=E5=88=B6=E5=99=A8?= =?UTF-8?q?=E5=92=8C=20CommunicationRecordsService=20=E6=9C=8D=E5=8A=A1?= =?UTF-8?q?=E7=B1=BB-=20=E5=AE=9E=E7=8E=B0=E6=B2=9F=E9=80=9A=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E6=B7=BB=E5=8A=A0=E6=8E=A5=E5=8F=A3=E5=92=8C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=B8=9A=E5=8A=A1=E9=80=BB=E8=BE=91=20-=20=E5=9C=A8?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E6=96=87=E4=BB=B6=E4=B8=AD=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B2=9F=E9=80=9A=E8=AE=B0=E5=BD=95=E7=9B=B8=E5=85=B3=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../apiController/CommunicationRecords.php | 49 ++++++++++ niucloud/app/api/route/route.php | 4 + .../CommunicationRecordsService.php | 89 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 niucloud/app/api/controller/apiController/CommunicationRecords.php create mode 100644 niucloud/app/service/api/apiService/CommunicationRecordsService.php diff --git a/niucloud/app/api/controller/apiController/CommunicationRecords.php b/niucloud/app/api/controller/apiController/CommunicationRecords.php new file mode 100644 index 00000000..4814a2e3 --- /dev/null +++ b/niucloud/app/api/controller/apiController/CommunicationRecords.php @@ -0,0 +1,49 @@ + $request->param('staff_id', ''),// + 'resource_id' => $request->param('resource_id', ''),// + 'resource_type' => $request->param('resource_type', ''),//资源类型(如设备、文件、系统等) + 'communication_type' => $request->param('communication_type', ''),// + 'communication_result' => $request->param('communication_result', ''),//沟通结果: success-成功, failure-失败, pending-待定 + 'communication_time' => $request->param('communication_time', $date),//沟通时间 + 'remarks' => $request->param('remarks', ''),//备注 + 'tag' => $request->param('tag', null),//标签:|默认null high-高, medium-中, low-低 + ]; + + $res = (new CommunicationRecordsService())->add($data); + if(!$res['code']){ + return fail('操作失败'); + } + return success('操作成功'); + } +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index a73e32ed..ec249eac 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -226,6 +226,10 @@ Route::group(function () { Route::post('resourceSharing/assign', 'apiController.ResourceSharing/assign'); + //沟通记录-添加 + Route::post('communicationRecords/add', 'apiController.CommunicationRecords/add'); + + diff --git a/niucloud/app/service/api/apiService/CommunicationRecordsService.php b/niucloud/app/service/api/apiService/CommunicationRecordsService.php new file mode 100644 index 00000000..a0f2986c --- /dev/null +++ b/niucloud/app/service/api/apiService/CommunicationRecordsService.php @@ -0,0 +1,89 @@ +model = (new CommunicationRecords()); + } + + //添加沟通记录 + public function add(array $data) + { + $model = $this->model; + $add = $model->create($data);//员工信息 + if ($add) { + $res = [ + 'code' => 1, + 'msg' => '操作成功', + 'data' => [] + ]; + } else { + $res = [ + 'code' => 0, + 'msg' => '操作失败', + 'data' => [] + ]; + } + return $res; + } + + /** + * 对比新旧数据改变 + * @param array $old_data 旧数据 + * @param array $new_data 新数据 + * @param array $ignoreFields 忽略验证的字段|默认[] + * @return array + */ + public function compareData(array $old_data, array $new_data, array $ignoreFields = ['updated_at']) + { + $changedFields = [];//改了那些字段 + $oldChanges = [];//数据修改前的样子 + $newChanges = [];//数据修改后的样子 + + foreach ($new_data as $key => $value) { + // 如果字段在忽略列表中,则跳过 + if (in_array($key, $ignoreFields)) { + continue; + } + + if (!isset($old_data[$key]) || $old_data[$key] != $value) { + $changedFields[] = $key; + $oldChanges[$key] = $old_data[$key] ?? null; + $newChanges[$key] = $value; + } + } + + return [ + 'changed_fields' => $changedFields, + 'old_values' => $oldChanges, + 'new_values' => $newChanges, + + 'changed_fields_json' => json_encode($changedFields, JSON_UNESCAPED_UNICODE), + 'old_values_json' => json_encode($oldChanges, JSON_UNESCAPED_UNICODE), + 'new_values_json' => json_encode($newChanges, JSON_UNESCAPED_UNICODE) + ]; + } + +} From 3840500adead1538647ea1341446ebe9fc6e2d05 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 23 May 2025 11:17:29 +0800 Subject: [PATCH 4/5] =?UTF-8?q?feat(api):=20=E6=B7=BB=E5=8A=A0=E6=A0=A1?= =?UTF-8?q?=E5=8C=BA=E6=8E=A5=E5=8F=A3=E5=92=8C=E7=9B=B8=E5=85=B3=E6=9C=8D?= =?UTF-8?q?=E5=8A=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 Campus 控制器,实现获取员工下的全部校区接口 - 新增 CampusService服务类,提供校区相关的业务逻辑 - 在路由文件中添加新的校区接口路由 --- .../api/controller/apiController/Campus.php | 42 ++++++++++ niucloud/app/api/route/route.php | 3 + .../service/api/apiService/CampusService.php | 81 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 niucloud/app/api/controller/apiController/Campus.php create mode 100644 niucloud/app/service/api/apiService/CampusService.php diff --git a/niucloud/app/api/controller/apiController/Campus.php b/niucloud/app/api/controller/apiController/Campus.php new file mode 100644 index 00000000..126c41a3 --- /dev/null +++ b/niucloud/app/api/controller/apiController/Campus.php @@ -0,0 +1,42 @@ +param('personnel_id',''); + if(empty($personnel_id)){ + return fail('缺少参数'); + } + $where = [ + 'personnel_id'=>$personnel_id + ]; + $res = (new CampusService())->getAll($where); + if(!$res['code']){ + return fail($res['msg']); + } + return success($res['data']); + } +} diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index ec249eac..c88b5ab9 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -229,6 +229,9 @@ Route::group(function () { //沟通记录-添加 Route::post('communicationRecords/add', 'apiController.CommunicationRecords/add'); + //校区-获取员工下的全部校区 + Route::get('campus/getPersonnelCampus', 'apiController.campus/getPersonnelCampus'); + diff --git a/niucloud/app/service/api/apiService/CampusService.php b/niucloud/app/service/api/apiService/CampusService.php new file mode 100644 index 00000000..801d8ced --- /dev/null +++ b/niucloud/app/service/api/apiService/CampusService.php @@ -0,0 +1,81 @@ +model = (new Campus()); + } + + //获取全部校区 + public function getAll(array $where){ + $res = [ + 'code'=>0, + 'msg'=>'缺少筛选条件', + 'data'=>[] + ]; + if(!$where){ + return $res; + } + + $model = $this->model; + //判断用没有员工id + if(!empty($where['personnel_id'])){ + //获取员工归属的校区id + $campus_id = $this->getPersonnelCamousId($where['personnel_id']); + if(!$campus_id){ + $res = [ + 'code'=>0, + 'msg'=>'暂无归属校区', + 'data'=>[] + ]; + return $res; + } + $model = $model->whereIn('id',$campus_id); + } + $data = $model->select()->toArray(); + $res = [ + 'code'=>1, + 'msg'=>'操作成功', + 'data'=>$data + ]; + return $res; + } + + /** + * 查询员工归属的校区id + * @param $personnel_id 员工表id + */ + private function getPersonnelCamousId($personnel_id){ + //这里要去重 + $campus_id = CampusPersonRole::where('person_id',$personnel_id) + ->distinct(true) + ->column('campus_id'); + return $campus_id; + } + + + +} From 37dabf100f767f496037d3f6ad1f55a4f3726fc0 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Fri, 23 May 2025 16:16:30 +0800 Subject: [PATCH 5/5] =?UTF-8?q?feat(campus):=20=E6=B7=BB=E5=8A=A0=E6=A0=A1?= =?UTF-8?q?=E5=8C=BA=E5=9D=90=E6=A0=87=E6=95=B0=E7=BB=84=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在获取校区数据时,增加校区坐标数组信息的解析 - 新增 campus_coordinates_arr 字段,包含地址、纬度和经度信息 --- niucloud/app/service/api/apiService/CampusService.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/niucloud/app/service/api/apiService/CampusService.php b/niucloud/app/service/api/apiService/CampusService.php index 801d8ced..d84ede64 100644 --- a/niucloud/app/service/api/apiService/CampusService.php +++ b/niucloud/app/service/api/apiService/CampusService.php @@ -56,6 +56,16 @@ class CampusService extends BaseApiService $model = $model->whereIn('id',$campus_id); } $data = $model->select()->toArray(); + + foreach ($data as &$v){ + $campus_coordinates_arr = json_decode($v['campus_coordinates'],true); + $v['campus_coordinates_arr'] = [ + 'address'=>$campus_coordinates_arr['address'] ?? '', + 'lat'=>$campus_coordinates_arr['lat'] ?? '', + 'lng'=>$campus_coordinates_arr['lng'] ?? '', + ]; + } + $res = [ 'code'=>1, 'msg'=>'操作成功',