ProjectRoleController.php
4.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Models\ProjectRole as ProjectRoleModel;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
class ProjectRoleController extends BaseController
{
/**
* @name :用户角色列表()
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
//TODO::根据当前登录用户返回
$projectRoleModel = new ProjectRoleModel();
$lists = $projectRoleModel->lists($this->param,$this->p,$this->row,$this->order);
$this->result($lists);
}
/**
* @name :添加角色
* @return void
* @author :liyuhang
* @method
*/
public function add(){
//TODO::获取当前用户的所在项目组
//参数验证
$rules = [
'name'=>'required|max:11',
'role_menu'=>'required|string',
];
//验证的提示信息
$message = [
'name.required'=>'名称必须填写',
'name.max' => '号码不大于11字符.',
'role_menu.required'=>'密码必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$this->param['project_id'] = $this->user['project_id'];
//获取当前项目下的角色超级管理员
$projectRoleModel = new ProjectRoleModel();
//验证当前角色是否存在
$info = $projectRoleModel->read(['name'=>$this->param['name']]);
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->add($this->param);
if($rs === false){
$this->response('添加失败',Code::USER_PARAMS_ERROE);
}
$this->response('添加成功',Code::SUCCESS);
}
/**
* @name :编辑角色
* @return void
* @author :liyuhang
* @method
*/
public function edit(){
//TODO::根据当前登录用户返回
//参数验证
$rules = [
'id'=>'required',
'name'=>'required|max:11',
'role_menu'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'name.required'=>'名称必须填写',
'role_menu.required'=>'菜单权限列表填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE);
}
$projectRoleModel = new ProjectRoleModel();
//TODO::查询当前名称是否重复
$info = DB::table($projectRoleModel->getTable())->where('id','<>',$this->param['id'])
->where(['name'=>$this->param['name'],'project_id'=>$this->user['project_id']])->first();
if(!empty($info)){
$this->response('当前添加的角色已存在',Code::USER_PARAMS_ERROE);
}
$rs = $projectRoleModel->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$this->response('编辑成功',Code::SUCCESS);
}
/**
* @name :修改用户状态
* @return void
* @author :liyuhang
* @method
*/
public function status(){
//参数验证
$rules = [
'id'=>'required',
'status'=>'required',
];
//验证的提示信息
$message = [
'id.required'=>'主键必须填写',
'status.required'=>'状态必须填写',
];
$validate = Validator::make($this->param, $rules, $message);
if($validate->fails()){
return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);
}
$projectRoleModel = new ProjectRoleModel();
$rs = $projectRoleModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
if($rs === false){
$this->response('编辑失败',Code::USER_PARAMS_ERROE);
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS);
}
}