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; + } + + + +}