UserController.php
3.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
<?php
namespace App\Http\Controllers\Bside;
use App\Enums\Common\Code;
use App\Http\Requests\Bside\UserRequest;
use App\Models\User as UserModel;
use Illuminate\Support\Facades\Validator;
class UserController extends BaseController
{
/**
* @name :name
* @return void
* @author :liyuhang
* @method
*/
public function lists(){
//TODO::搜索参数处理
$userModel = new UserModel();
$this->map['project_id'] = $this->user['project_id'];
$lists = $userModel->lists($this->map,$this->p,$this->row,$this->order,['id','name','mobile','created_at']);
if(empty($lists)){
$this->response('请求失败',Code::USER_ERROR,[]);
}
$this->response('列表',Code::SUCCESS,$lists);
}
/**
* @name :添加管理员
* @return void
* @author :liyuhang
* @method
*/
public function add(UserRequest $request){
$request->validated();
$userModel = new UserModel();
$this->param['project_id'] = $this->user['project_id'];
$rs = $userModel->adds($this->param);
if($rs === false){
$this->response('当前添加用户已存在或参数错误,添加失败',Code::USER_REGISTER_ERROE,[]);
}
$this->response('添加成功',Code::SUCCESS,[]);
}
/**
* @name : 编辑管理员
* @return void
* @author :liyuhang
* @method
*/
public function edit(UserRequest $request){
$request->validate([
'id'=>['required']
],[
'id.required' => 'ID不能为空'
]);
$userModel = new UserModel();
//TODO::查询当前手机号码是否重复
$info = $userModel->where('id','<>',$this->param['id'])
->where(['mobile'=>$this->param['mobile']])->first();
if(!empty($info)){
$this->response('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
}
$rs = $userModel->edits($this->param);
if($rs === false){
$this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
}
$this->response('编辑成功',Code::SUCCESS,[]);
}
/**
* @name :修改当前用户状态
* @return void
* @author :liyuhang
* @method
*/
public function status(UserRequest $request){
$request->validate([
'id'=>['required'],
'status'=>['required'],
],[
'id.required' => 'ID不能为空',
'status.required' => 'status不能为空'
]);
$userLogic = new UserModel();
$rs = $userLogic->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->response('error',Code::USER_ERROR);
}
$this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功');
}
/**
* @name :删除管理员
* @return void
* @author :liyuhang
* @method
*/
public function del(UserRequest $request){
$request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$userModel = new UserModel();
$rs = $userModel->del($this->param);
if($rs === false){
$this->response('删除失败',Code::USER_ERROR);
}
$this->response('删除成功');
}
}