CustomModuleCategoryLogic.php
7.2 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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @remark :
* @name :CustomModuleCategoryLogic.php
* @author :lyh
* @method :post
* @time :2023/12/4 16:07
*/
namespace App\Http\Logic\Bside\CustomModule;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\RouteMap\RouteMap;
class CustomModuleCategoryLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
$this->model = new CustomModuleCategory();
}
/**
* @remark :添加/编辑获取分类列表
* @name :getCateList
* @author :lyh
* @method :post
* @time :2023/12/5 17:12
*/
public function getCateList(){
$this->param['status'] = 0;
if(isset($this->param['id']) && !empty($this->param['id'])){
$str = [];
//排序掉当前id下所有子集
$str = $this->getAllSub($this->param['id'],$str);
$str[] = (int)$this->param['id'];
$this->param['id'] = ['not in',$str];
}
$menu = array();
$list = $this->model->list($this->param);
if(!empty($list)){
foreach ($list as $v){
if($v['pid'] == 0){
$v['sub'] = _get_child($v['id'],$list);
$menu[] = $v;
}
}
}
return $this->success($menu);
}
/**
* @remark :获取当前id下所有子集
* @name :getAllSub
* @author :lyh
* @method :post
* @time :2023/10/18 15:10
*/
public function getAllSub($id,&$str = []){
$list = $this->model->list(['pid'=>$id,'status'=>0],['id','pid']);
if(!empty($list)){
foreach ($list as $v){
$str[] = $v['id'];
$this->getAllSub($v['id'],$str);
}
}
return $str;
}
/**
* @remark :获取当前数据详情
* @name :getCustomModuleInfo
* @author :lyh
* @method :post
* @time :2023/12/4 16:10
*/
public function categoryInfo(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
$info['image'] = getImageUrl($info['image'],$this->user['storage_type'],$this->user['project_location']);
return $this->success($info);
}
/**
* @remark :保存数据
* @name :ModuleSave
* @author :lyh
* @method :post
* @time :2023/12/4 15:47
*/
public function categorySave(){
$this->param = $this->handleParam($this->param);
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->categoryEdit();
}else{
$this->categoryAdd();
}
return $this->success();
}
/**
* @name :(参数处理)paramProcessing
* @author :lyh
* @method :post
* @time :2023/6/13 11:30
*/
public function handleParam($param)
{
$param['operator_id'] = $this->user['id'];
if(!isset($param['id']) || empty($param['id'])){
$param['project_id'] = $this->user['project_id'];
}
if(isset($param['image']) && !empty($param['image'])){
$param['image'] = str_replace_url($param['image']);
}
return $this->success($param);
}
/**
* @remark :添加分类
* @name :categoryAdd
* @author :lyh
* @method :post
* @time :2023/12/5 10:55
*/
public function categoryAdd(){
try {
$id = $this->model->addReturnId($this->param);
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE,
$id, $this->user['project_id']);
$this->addUpdateNotify(RouteMap::SOURCE_MODULE_CATE,$route);
$this->curlDelRoute(['new_route'=>$route]);
$this->edit(['route' => $route], ['id' => $id]);
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :编辑分类
* @name :categoryEdit
* @author :lyh
* @method :post
* @time :2023/12/5 10:55
*/
public function categoryEdit(){
$route = RouteMap::setRoute($this->param['route'], RouteMap::SOURCE_MODULE_CATE,
$this->param['id'], $this->user['project_id']);
$this->editRoute($this->param['id'],$route);
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请连续管理员');
}
return $this->success();
}
/**
* @remark :查看是否编辑路由
* @name :editCategoryRoute
* @author :lyh
* @method :post
* @time :2023/9/7 11:05
*/
public function editRoute($id, $route)
{
//生成一条删除路由记录
$info = $this->model->read(['id' => $id], ['id', 'route']);
if ($info['route'] != $route) {
$this->addUpdateNotify(RouteMap::SOURCE_MODULE_CATE,$route);
$this->curlDelRoute(['route'=>$info['route'],'new_route'=>$route]);
}
return true;
}
/**
* @remark :删除数据
* @name :ModuleDel
* @author :lyh
* @method :post
* @time :2023/12/4 15:47
*/
public function categoryDel(){
$ids = $this->param['id'];
foreach ($ids as $id){
//删除路由
$this->delRoute($id);
$this->model->del(['id'=>$id]);
//同步删除产品字段category_id
$contentModel = new CustomModuleContent();
$contentModel->edit(['category_id'=>DB::raw("REPLACE(category_id, ',$id,' , ',')")],['category_id'=>['like','%,'.$id.',%']]);
$contentModel->edit(['category_id'=>null],['category_id'=>',']);
}
return $this->success();
}
/**
* @remark :删除路由
* @name :delRoute
* @author :lyh
* @method :post
* @time :2023/9/7 10:50
*/
public function delRoute($id)
{
$info = $this->model->read(['id' => $id], ['id', 'route','module_id']);
if($info === false){
return $this->success();
}
RouteMap::delRoute(RouteMap::SOURCE_MODULE_CATE, $id, $this->user['project_id']);
//通知
$this->curlDelRoute(['route'=>$info['route']]);
return $this->success();
}
/**
* @remark :排序
* @name :categorySort
* @author :lyh
* @method :post
* @time :2023/9/26 17:38
*/
public function categorySort(){
$rs = $this->model->edit(['sort'=>$this->param['sort']],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :设置批量排序
* @name :setAllSort
* @author :lyh
* @method :post
* @time :2024/1/10 15:40
*/
public function setAllSort(){
foreach ($this->param['data'] as $k => $v){
$this->model->edit(['sort'=>$v['sort']],['id'=>$v['id']]);
}
return $this->success();
}
}