UserLogic.php
3.1 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\Logic\Bside;
use App\Enums\Common\Code;
use App\Models\User;
class UserLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new User();
$this->param = $this->requestAll;
}
/**
* @name :添加会员
* @author :liyuhang
*/
public function user_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(['mobile'=>$this->param['mobile']]);
if($info !== false){
$this->fail('error',Code::USER_ERROR);
}
//密码加密
$this->param['password'] = base64_encode(md5($this->param['password']));
//上传头像
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['hash'];
}
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
/**
* @name :编辑用户
* @author :liyuhang
*/
public function user_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'mobile'=>$this->param['mobile']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前编辑的手机号码已存在',Code::USER_PARAMS_ERROE);
}
//上传头像
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data['hash'];
}
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edits($this->param);
if($rs === false){
$this->fail('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]);
}
return $this->success();
}
/**
* @name :编辑状态/排序
* @author :liyuhang
*/
public function user_status(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
/**
* @name :用户详情
* @return void
* @author :liyuhang
* @method
*/
public function user_info(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success($info);
}
/**
* @name :删除用户(逻辑删除)
* @return void
* @author :liyuhang
* @method
*/
public function user_del(){
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->edit(['status'=>2],['id'=>['in',$this->param['id']]]);
if($rs === false){
$this->fail('error',Code::USER_ERROR);
}
return $this->success();
}
}