UserLogic.php
3.7 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
<?php
namespace App\Http\Logic\Bside\User;
use App\Enums\Common\Code;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\User\User;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\DB;
class UserLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new User();
$this->param = $this->requestAll;
}
/**
* @remark :获取用户详情
* @name :User_info
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_info(){
$info = $this->model->read($this->param);
return $this->success($info);
}
/**
* @remark :添加用户
* @name :user_add
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_add(){
//验证当前用户是否存在
$info = $this->model->read(['mobile'=>$this->param['mobile'],
'project_id'=>$this->user['project_id']]);
if($info !== false){
$this->fail('当前手机号码已注册');
}
if(!isset($this->param['role_id']) || empty($this->param['role_id'])){
$this->fail('一个账号只允许一个超级管理员,请先添加角色');
}
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$this->param['project_id'] = $this->user['project_id'];
$this->param['type'] = 1;
//密码加密
$this->param['password'] = base64_encode(md5($this->param['password']));
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :编辑用户
* @name :user_edit
* @author :lyh
* @method :post
* @time :2023/6/17 16:42
*/
public function user_edit(){
$condition = [
'id'=>['!=',$this->param['id']],
'mobile'=>$this->param['mobile'],
'project_id'=>$this->user['project_id']
];
$info = $this->model->read($condition);
if($info !== false){
$this->fail('当前编辑的手机号码已存在');
}
$this->param['type'] = 1;
$this->param['operator_id'] = $this->user['id'];
if(isset($this->param['password']) && !empty($this->param['password'])){
$this->param['password'] = base64_encode(md5($this->param['password']));
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
//todo::写入日志
DB::table('gl_user_edit_log')->insert(['message'=>json_encode($this->param),'user_id'=>$this->user['id'],'project_id'=>$this->user['project_id'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]);
return $this->success();
}
/**
* @remark :编辑状态与排序
* @name :user_status
* @author :lyh
* @method :post
* @time :2023/6/17 16:41
*/
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();
}
/**
* @remark :删除用户
* @name :user_del
* @author :lyh
* @method :post
* @time :2023/6/17 16:41
*/
public function user_del(){
$this->param['id'] = ['in',$this->param['id']];
$this->model->del($this->param);
//对应删除组织架构
return $this->success();
}
}