|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside;
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Models\ProjectMenu as ProjectMenuModel;
|
|
|
|
use App\Models\ProjectRole as ProjectRoleModel;
|
|
|
|
use App\Models\User;
|
|
|
|
use App\Models\User as UserModel;
|
|
|
|
|
|
|
|
class RoleLogic extends BaseLogic
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->model = new ProjectRoleModel();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :添加角色
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function role_add(){
|
|
|
|
$this->param['create_id'] = $this->user['id'];
|
|
|
|
$this->param['operator_id'] = $this->user['id'];
|
|
|
|
$this->param['project_id'] = $this->user['project_id'];
|
|
|
|
//验证当前角色是否存在
|
|
|
|
$info = $this->model->read(['name'=>$this->param['name']]);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前添加的角色已存在',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
$rs = $this->model->add($this->param);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('添加失败',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :编辑角色
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function role_edit(){
|
|
|
|
//TODO::查询当前名称是否重复
|
|
|
|
$condition = [
|
|
|
|
['id'=>['!=',$this->param['id']]],
|
|
|
|
['name'=>$this->param['name']],
|
|
|
|
['project_id'=>$this->user['project_id']],
|
|
|
|
];
|
|
|
|
$info = $this->model->read($condition);
|
|
|
|
if($info !== false){
|
|
|
|
$this->fail('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('编辑失败',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :修改状态/排序
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function role_status(){
|
|
|
|
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error',Code::USER_PARAMS_ERROE);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :删除角色
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
*/
|
|
|
|
public function role_del(){
|
|
|
|
//查询当前角色下是否有用户
|
|
|
|
$userModel = new UserModel();
|
|
|
|
//批量删除
|
|
|
|
foreach ($this->param['id'] as $v){
|
|
|
|
$user_info = $userModel->read(['role_id'=>$v]);
|
|
|
|
if(!empty($user_info)){
|
|
|
|
$this->fail('当前角色下有用户存在,不允许删除',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->param['id'] = ['in',$this->param['id']];
|
|
|
|
$rs = $this->model->del(['id'=>$this->param['id']]);
|
|
|
|
if($rs === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :获取角色详情
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function role_info(){
|
|
|
|
$info = $this->model->read($this->param);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('error',Code::USER_ERROR);
|
|
|
|
}
|
|
|
|
return $this->success($info);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :获取菜单列表
|
|
|
|
* @return array
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function role_get_menu(){
|
|
|
|
//根据当前登录用户角色返回用户菜单列表
|
|
|
|
$info = $this->model->read(['id'=>$this->user['role_id']]);
|
|
|
|
$info['role_menu'] = trim($info['role_menu'],',');
|
|
|
|
$menuModel = new ProjectMenu();
|
|
|
|
$lists = $menuModel->where(['status'=>0])->whereIn('id',explode(',',$info['role_menu']))->get();
|
|
|
|
$lists = $lists->toArray();
|
|
|
|
$menu = array();
|
|
|
|
foreach ($lists as $k => $v){
|
|
|
|
$v = (array)$v;
|
|
|
|
if ($v['pid'] == 0) {
|
|
|
|
$v['sub'] = $this->_get_child($v['id'], $lists);
|
|
|
|
$menu[] = $v;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($menu);
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|