GroupLogic.php
5.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
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
<?php
namespace App\Http\Logic\Bside\User;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\User\ProjectGroup;
use App\Models\User\User as UserModel;
use Illuminate\Support\Facades\DB;
class GroupLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new ProjectGroup();
$this->param = $this->requestAll;
}
/**
* @name :添加用户组
* @return void
* @author :liyuhang
* @method
*/
public function group_add(){
$this->param['project_id'] = $this->user['project_id'];
$this->param['admin_id'] = $this->user['id'];
$this->param['create_id'] = $this->user['id'];
$this->param['operator_id'] = $this->user['id'];
$rs = $this->model->add($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(添加成员)group_add_user
* @author :lyh
* @method :post
* @time :2023/5/17 15:58
*/
public function group_add_user(){
$info = $this->model->read(['id'=>$this->param['id']]);
//组装数据
$str = ltrim($info['user_list'],',').$this->param['user_list'];
$arr = array_unique(explode(',',$str));
sort($arr);
$str = ','.implode(',',$arr).',';
DB::beginTransaction();
try {
$this->model->edit(['user_list'=>$str],['id'=>$this->param['id']]);
//更新父类
$this->update_parent($this->param,$info);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加成员失败');
}
return $this->success();
}
/**
* @name :编辑
* @return void
* @author :liyuhang
* @method
*/
public function group_edit(){
$rs = $this->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(获取成员列表)user_list
* @author :lyh
* @method :post
* @time :2023/5/17 14:51
*/
public function user_list($data = [],$order = 'id'){
unset($this->param['id']);
$userModel = new UserModel();
$data = array_merge($data,$this->param);
$lists = $userModel->list($data,$order,['id','name','mobile','created_at']);
return $this->success($lists);
}
/**
* @name :详情
* @return void
* @author :liyuhang
* @method
*/
public function group_info($param = []){
if(empty($param)){
$param = $this->param;
}
$info = $this->model->read($this->param);
return $this->success($info);
}
/**
* @name :删除
* @return void
* @author :liyuhang
* @method
*/
public function group_del(){
//查看当前是否拥有父类
$info = $this->model->read(['pid'=>$this->param['id']]);
if($info !== false){
$this->fail('当前删除组织拥有下级组织,不允许删除');
}
$rs = $this->del($this->param);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @name :(更新父类成员)update_parent
* @author :lyh
* @method :post
* @time :2023/5/17 9:22
*/
public function update_parent($param,$info){
//查询当前组是否拥有父类
if($info['pid'] != 0){
$parent_info = $this->model->read(['id'=>$info['pid']]);
//把添加成员合并到上级
$str = trim(trim($param['user_list'],',').$parent_info['user_list'],',');
$arr = array_unique(explode(',', $str));
sort($arr);
$mergedString = ','.implode(',', $arr).',';
$rs = $this->model->edit(['user_list'=>$mergedString],['id'=>$parent_info['id']]);
if($rs === false){
$this->fail('更新父级失败');
}
//查看当前父级是否还拥有父级
if($parent_info['pid'] != 0){
return $this->update_parent($param,$parent_info);
}
}
return $this->success();
}
/**
* @name :(更新子类,同时清空子集成员)edit_son
* @author :lyh
* @method :post
* @time :2023/5/17 13:52
*/
public function update_son($param,$id){
//当前数据详情
$info = $this->model->read(['id'=>$id]);
//子集详情
$son_list = $this->model->list(['pid'=>$info['id']],'id');
if(!empty($son_list)){
//循环查询
foreach ($son_list as $k => $v){
$son_data = explode(',',trim($v['user_list'],','));
$son_str = '';
foreach ($son_data as $v1){
if(strpos($param['user_list'],','.$v1.',') > -1){
$son_str .= $v1.',';
}
}
$this->model->edit(['user_list'=>','.$son_str],['id'=>$v['id']]);
}
}
return true;
}
}