ProjectUserController.php
5.5 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
<?php
namespace App\Http\Controllers\Aside\User;
use App\Enums\Common\Code;
use App\Http\Controllers\Aside\BaseController;
use App\Http\Logic\Aside\User\UserLogic;
use App\Http\Requests\Aside\User\UserRequest;
use App\Models\Project\Project;
use App\Models\User\ProjectRole;
use App\Models\User\User;
use App\Models\User\User as UserModel;
/**
* @remark :b端用户管理
* @name :ProjectUserController
* @author :lyh
* @time :2023/6/17 16:24
*/
class ProjectUserController extends BaseController
{
//超级管理员
const ROLE_ID = 0;
/**
* @remark :超级管理员用户列表
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/25 9:27
*/
public function lists(){
$userModel = new UserModel();
$query = $userModel->leftJoin('gl_project', 'gl_project_user.project_id', '=', 'gl_project.id')
->leftJoin('gl_project_role', 'gl_project_user.role_id', '=', 'gl_project_role.id');
$query = $this->searchParam($query);
$lists = $query->orderBy('gl_project_user.id', 'desc')->paginate($this->row, $this->selectParam(), 'page', $this->page);
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @remark :查询字段
* @name :selectParam
* @author :lyh
* @method :post
* @time :2023/8/4 11:44
*/
public function selectParam(){
$select = [
'gl_project_user.id AS id',
'gl_project.title AS title',
'gl_project_user.project_id AS project_id',
'gl_project_user.mobile AS mobile',
'gl_project_user.email AS email',
'gl_project_user.status AS status',
'gl_project_user.name AS name',
'gl_project_role.name AS role_name',
];
return $select;
}
public function searchParam(&$query){
//搜索条件处理
if(isset($this->map['title'])){
$query = $query->where('gl_project.title','like','%'.$this->map['title'].'%');
}
if(isset($this->map['name'])){
$query = $query->where('gl_project_user.name',$this->map['name'][0],$this->map['name'][1]);
}
if(isset($this->map['mobile'])){
$query = $query->where('gl_project_user.mobile','like','%'.$this->map['mobile'].'%');
}
if(isset($this->map['project_id'])){
$query = $query->where('gl_project_user.project_id',$this->map['project_id']);
}
return $query;
}
/**
* @remark :用户详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/6/25 9:27
*/
public function info(UserLogic $userLogic){
$this->request->validate([
'id'=>'required'
],[
'id.required' => 'ID不能为空'
]);
$info = $userLogic->user_info();
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :保存用户
* @name :edit
* @author :lyh
* @method :post
* @time :2023/6/25 9:28
*/
public function save(UserRequest $request,UserLogic $userLogic){
$request->validated();
if(!isset($this->param['id'])){
$this->request->validate([
'password'=>'required',
],[
'password.required' => '密码不能为空',
]);
}
$userLogic->projectUserSave();
$this->response('success');
}
/**
* @param UserLogic $userLogic
* @remark :编辑用户
* @name :del
* @author :lyh
* @method :post
* @time :2023/6/25 9:28
*/
public function del(UserLogic $userLogic){
$this->request->validate([
'id'=>['required','array'],
],[
'id.required' => 'ID不能为空',
'id.array' => 'ID为数组',
]);
$userLogic->user_del();
$this->response('success');
}
/**
* @remark :获取项目角色
* @name :getRole
* @author :lyh
* @method :post
* @time :2023/8/29 13:47
*/
public function getRole(){
$this->request->validate([
'project_id'=>'required',
],[
'project_id.required' => 'project_id不能为空',
]);
$roleModel = new ProjectRole();
$list = $roleModel->list($this->map);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :排序
* @name :setSort
* @author :lyh
* @method :post
* @time :2023/8/10 16:40
*/
public function sort(UserLogic $userLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$userLogic->setParamStatus();
$this->response('success');
}
/**
* @remark :保存用户获取项目列表
* @name :getProjectList
* @author :lyh
* @method :post
* @time :2023/9/6 9:06
*/
public function getProjectList(Project $project){
$lists = $project->list(['type'=>['!=',$project::TYPE_ZERO]],'id',['id','title']);
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :设置超级管理员
* @name :setRole
* @author :lyh
* @method :post
* @time :2023/9/22 14:53
*/
public function setAdmin(UserLogic $userLogic){
$this->request->validate([
'id'=>'required',
],[
'id.required' => 'ID不能为空',
]);
$userLogic->setRole();
$this->response('success');
}
}