You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
156 lines
4.2 KiB
156 lines
4.2 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | Niucloud-admin 企业快速开发的多应用管理平台
|
|
// +----------------------------------------------------------------------
|
|
// | 官方网址:https://www.niucloud.com
|
|
// +----------------------------------------------------------------------
|
|
// | niucloud团队 版权所有 开源版本可自由商用
|
|
// +----------------------------------------------------------------------
|
|
// | Author: Niucloud Team
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\service\admin\campus_person_role;
|
|
|
|
use app\model\campus_person_role\CampusPersonRole;
|
|
use app\model\campus\Campus;
|
|
use app\model\personnel\Personnel;
|
|
use app\model\sys\SysRole;
|
|
use app\model\departments\Departments;
|
|
|
|
use core\base\BaseAdminService;
|
|
|
|
|
|
/**
|
|
* 角色关系服务层
|
|
* Class CampusPersonRoleService
|
|
* @package app\service\admin\campus_person_role
|
|
*/
|
|
class CampusPersonRoleService extends BaseAdminService
|
|
{
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->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();
|
|
}
|
|
|
|
|
|
}
|
|
|