UserLogic.php
4.9 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
<?php
namespace App\Http\Logic\Aside\User;
use App\Helper\Common;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Manage\Manage;
use App\Models\Manage\MenuSpecial;
use App\Models\Project\Project;
use App\Models\User\User;
use App\Models\User\User as UserModel;
class UserLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new User();
$this->param = $this->requestAll;
}
/**
* @name :获取详情
* @return void
* @author :liyuhang
* @method
*/
public function user_info()
{
$info = Common::get_user_cache($this->model, $this->param['id'], 'A');
if (empty($info)) {
$info = $this->model->read($this->param, ['id', 'project_id', 'name', 'status', 'role_id' ,'mobile', 'operator_id']);
if ($info === false) {
$this->fail('当前数据不存在');
}
$info['project_name'] = (new Project())->read(['id' => $info['project_id']], ['title'])['title'];
Common::set_user_cache($info, $this->model, $this->param['id'], 'A');
}
return $this->success($info);
}
/**
* @name :添加会员
* @return void
* @author :liyuhang
* @method
*/
public function projectUserSave()
{
//验证手机号是否存在
$this->verifyMobile($this->param);
//验证一个项目是否只有一个超级管理员
$this->verifyRole($this->param);
if (isset($this->param['id']) && !empty($this->param['id'])) {
$this->param = $this->editPassword($this->param);
$rs = $this->model->edit($this->param, ['id' => $this->param['id']]);
} else {
$this->param['password'] = base64_encode(md5($this->param['password']));
$rs = $this->model->add($this->param);
}
if ($rs === false) {
$this->fail('添加失败');
}
return $this->success();
}
/**
* @remark :验证手机号是否可用
* @name :verifyMobile
* @author :lyh
* @method :post
* @time :2023/8/29 9:14
*/
public function verifyMobile($param){
if(isset($param['id']) && !empty($param['id'])){
$condition = [
'mobile' => $param['mobile'],
'project_id'=>$param['project_id'],
'id' => ['!=', $param['id']]
];
}else{
$condition = [
'mobile' => $param['mobile'],
'project_id'=>$param['project_id'],
];
}
$info = $this->model->read($condition);
if ($info !== false) {
$this->fail('当前手机号码已存在');
}
return $this->success();
}
/**
* @remark :验证一个项目超级管理员只允许存在一个
* @name :verifyRole
* @author :lyh
* @method :post
* @time :2023/8/29 9:22
*/
public function verifyRole($param){
if(!isset($param['role_id']) || empty($param['role_id'])){
$param['role_id'] = $this->model::ROLE_MANAGER;
}
if($param['role_id'] == $this->model::ROLE_MANAGER){
if(isset($param['id']) && !empty($param['id'])){
$condition = [
'mobile' => $param['mobile'],
'project_id'=>$param['project_id'],
'id' => ['!=', $param['id']],
'role_id'=>$this->model::ROLE_MANAGER
];
}else{
$condition = [
'mobile' => $param['mobile'],
'project_id'=>$param['project_id'],
'role_id'=>$this->model::ROLE_MANAGER,
];
}
$info = $this->model->read($condition);
if ($info !== false) {
$this->fail('当前项目已存在超级管理员');
}
}
}
/**
* @name :编辑会员
* @return void
* @author :liyuhang
* @method
*/
public function editPassword($param)
{
//验证密码是否更改
if (isset($param['password']) && !empty($param['password'])) {
$info = $this->model->read(['id' => $param['id']]);
if ($info['password'] != $param['password']) {
$param['password'] = base64_encode(md5($param['password']));
}
}
return $this->success($param);
}
/**
* @name :删除会员
* @return void
* @author :liyuhang
* @method
*/
public function user_del()
{
$ids = $this->param['id'];
$this->param['id'] = ['in', $this->param['id']];
$rs = $this->model->del($this->param);
if ($rs === false) {
$this->fail('删除失败');
}
Common::del_user_cache($this->model, $ids, 'A');
return $this->success();
}
}