model = new CampusPersonRole(); } /** * 获取角色关系列表 * @param array $where * @return array */ public function getPage(array $data = []) { $field = 'a.*,b.phone'; $order = 'a.id desc'; $where = []; if($data['campus_id']){ $where[] = ['a.campus_id','=',$data['campus_id']]; } // if($data['role_id']){ // $where[] = ['a.role_id','=',$data['role_id']]; // } if($data['dept_id']){ $where[] = ['a.dept_id','=',$data['dept_id']]; } if($data['person_name']){ $where[] = ['b.name','like','%'.$data['person_name'].'%']; } $search_model = $this->model ->alias("a") ->join(['school_personnel' => 'b'],'a.person_id = b.id','left') ->where($where) ->with(['campus','personnel','sysRole','departments']) ->field($field)->order($order); $search_model->where(get_campus_where($this->uid,'campus_id')); $list = $this->pageQuery($search_model); return $list; } /** * 获取角色关系信息 * @param int $id * @return array */ public function getInfo(int $id) { $field = 'id,campus_id,person_id,role_id,dept_id,created_at,updated_at,deleted_at'; $info = $this->model->field($field)->where([['id', "=", $id]])->with(['campus','personnel','sysRole','departments'])->findOrEmpty()->toArray(); return $info; } /** * 添加角色关系 * @param array $data * @return mixed */ public function add(array $data) { if($this->model->where(['person_id' => $data['person_id']])->find()){ return fail("重复操作"); } $res = $this->model->create($data); return success("操作成功"); } /** * 角色关系编辑 * @param int $id * @param array $data */ public function edit(int $id, array $data) { if($this->model->where([['id', '<>', $id]])->where(['person_id' => $data['person_id']])->find()){ return fail("重复操作"); } $this->model->where([['id', '=', $id]])->update($data); return success("操作成功"); } /** * 删除角色关系 * @param int $id * @return bool */ public function del(int $id) { $model = $this->model->where([['id', '=', $id]])->find(); $res = $model->delete(); return $res; } public function getCampusAll(){ $campusModel = new Campus(); return $campusModel->select()->toArray(); } public function getPersonnelAll(){ $person_ids = $this->model->column("person_id"); $personnelModel = new Personnel(); return $personnelModel->where([['id','not in',$person_ids]])->select()->toArray(); } public function getSysRoleAll($data){ $sysRoleModel = new SysRole(); return $sysRoleModel->where(['dept_id' => $data['dept_id']])->select()->toArray(); } public function getDepartmentsAll(){ $departmentsModel = new Departments(); return $departmentsModel->select()->toArray(); } }