CustomModuleContentController.php
10.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
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
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
<?php
/**
* @remark :
* @name :CustomModuleContentController.php
* @author :lyh
* @method :post
* @time :2023/12/4 15:55
*/
namespace App\Http\Controllers\Bside\CustomModule;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\CustomModule\CustomModuleContentLogic;
use App\Http\Logic\Bside\Product\ProductLogic;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;
use App\Models\User\User;
use App\Models\WebSetting\SettingNum;
use Illuminate\Support\Facades\Log;
class CustomModuleContentController extends BaseController
{
/**
* @remark :获取自定义模块列表
* @name :ModuleList
* @author :lyh
* @method :post
* @time :2023/12/4 15:43
*/
public function lists(CustomModuleContent $customModuleContent){
$this->request->validate([
'module_id'=>['required'],
],[
'module_id.required' => 'module_id不能为空',
]);
$this->map['project_id'] = $this->user['project_id'];
$lists = $customModuleContent->lists($this->map,$this->page,$this->row,$this->order = ['sort','id']);
if(!empty($lists)){
$template_id = $this->getModuleTemplateId($this->param['module_id']);
$data = $this->getAllCategoryName();
foreach ($lists['list'] as $k=>$v){
$v['url'] = $this->getUrl($v);
$v = $this->getHandleImageFile($v);
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['operator_name'] = (new User())->getName($v['operator_id']);
$v['is_renovation'] = $this->getIsRenovation($v['module_id'],BTemplate::IS_DETAIL,$template_id,$v['id'],BTemplate::IS_CUSTOM);
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @remark :扩展模块获取模版id
* @name :getTemplateId
* @author :lyh
* @method :post
* @time :2024/1/31 16:47
*/
public function getModuleTemplateId($module_id){
$template_id = 0;
$moduleModel = new CustomModule();
$info = $moduleModel->read(['id'=>$module_id]);
if($info['detail_customized'] != 1){
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
$template_id = $info['template_id'];
}
return $this->success($template_id);
}
/**
* @remark :获取时处理视频,图片,文件
* @name :getHandleImageFile
* @author :lyh
* @method :post
* @time :2024/1/31 15:48
*/
public function getHandleImageFile($v){
$v['image_link'] = getImageUrl($v['image'] ?? '',$this->user['storage_type'] ?? 0,$this->user['project_location']);
$v['og_image'] = getImageUrl(empty($v['og_image']) ? $v['image'] : $v['og_image'],$this->user['storage_type'],$this->user['project_location']);
if(!empty($v['video'])){
$v['video']['url'] = getFileUrl($v['video']['url'],$this->user['storage_type'] ?? 0,$this->user['project_location'],$this->user['file_cdn'] ?? 0);
$v['video']['video_image'] = getImageUrl($v['video']['video_image'],$this->user['storage_type'] ?? 0,$this->user['project_location']);
}
return $this->success($v);
}
/**
* @remark :获取连接
* @name :getUrl
* @author :lyh
* @method :post
* @time :2024/1/29 14:56
*/
public function getUrl($v){
$routeMapModel = new RouteMap();
if(!empty($v) && !empty($v['category_id'])){
$categoryIdArr = $v['category_id'];
$cate_id = (int)array_shift($categoryIdArr);
$routeInfo = $routeMapModel->read(['source'=>RouteMap::SOURCE_MODULE_CATE,'source_id'=>$cate_id]);
$v['path'] = ($routeInfo['route'] ?? '');
if(!empty($v['path'])){
$v['path'] = $v['path'].'/';
}
}
return $this->user['domain'].$v['path'].$v['route'];
}
/**
* @remark :获取所有分类名称
* @name :getAllCategoryName
* @author :lyh
* @method :post
* @time :2023/12/8 15:47
*/
public function getAllCategoryName(){
$categoryModel = new CustomModuleCategory();
$list = $categoryModel->list(['status'=>0],'id',['id','name']);
$data = [];
foreach ($list as $v){
$data[$v['id']] = $v['name'];
}
return $data;
}
/**
* @remark :获取分类名称
* @name :categoryName
* @author :lyh
* @method :post
* @time :2023/9/14 13:58
*/
public function categoryName($category_id,$data){
$category_name = '';
if(!empty($category_id) && !empty($data)){
foreach ($category_id as $v){
if(isset($data[$v])){
$category_name .= $data[$v].',';
}
}
$category_name = trim($category_name,',');
}
return $category_name;
}
/**
* @remark :添加/编辑内容时获取分类
* @name :getCategoryList
* @author :lyh
* @method :post
* @time :2023/12/7 15:19
*/
public function getCategoryList(){
$categoryModel = new CustomModuleCategory();
$list = $categoryModel->list(['project_id'=>$this->user['project_id'],'module_id'=>$this->param['module_id']],['id','name']);
$menu = [];
if(!empty($list)){
foreach ($list as $v){
if($v['pid'] == 0){
$v['sub'] = _get_child($v['id'],$list);
$menu[] = $v;
}
}
}
$this->response('success',Code::SUCCESS,$menu);
}
/**
* @remark :获取当前数据详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/12/4 16:09
*/
public function info(CustomModuleContentLogic $logic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$info = $logic->getContentInfo();
$info = $this->getHandleImageFile($info);
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :保存数据
* @name :save
* @author :lyh
* @method :post
* @time :2023/12/4 15:45
*/
public function save(CustomModuleContentLogic $logic){
$this->request->validate([
'name'=>['required'],
'route'=>['required'],
'module_id'=>['required']
],[
'name.required' => '分类名称不能为空',
'route.required' => '分类路由不能为空',
'module_id.required' => '所选模块id不能为空'
]);
$data = $logic->contentSave();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :删除数据
* @name :del
* @author :lyh
* @method :post
* @time :2023/12/4 16:14
*/
public function del(CustomModuleContentLogic $logic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$logic->contentDel();
$this->response('success');
}
/**
* @remark :排序
* @name :sort
* @author :lyh
* @method :post
* @time :2023/12/15 17:46
*/
public function sort(CustomModuleContentLogic $logic){
$this->request->validate([
'id'=>['required'],
'sort'=>['required']
],[
'id.required' => 'ID不能为空',
'sort.required' => '排序不能为空',
]);
$logic->contentSort();
$this->response('success');
}
/**
* @remark :批量排序
* @name :allSort
* @author :lyh
* @method :post
* @time :2024/1/11 9:46
*/
public function allSort(CustomModuleContentLogic $logic){
$logic->setAllSort();
$this->response('success');
}
/**
* @remark :复制扩展模块
* @name :copyModuleContent
* @author :lyh
* @method :post
* @time :2024/4/28 16:31
*/
public function copyModuleContent(CustomModuleContentLogic $logic){
$this->request->validate([
'id'=>['required'],
],[
'id.required' => 'ID不能为空',
]);
$data = $logic->copyModuleContentInfo();
$this->response('success',Code::SUCCESS,$data);
}
/**
* @remark :设置排序
* @name :setProductSort
* @author :lyh
* @method :post
* @time :2024/1/31 10:14
*/
public function setCustomSort(){
$setNumModel = new SettingNum();
try {
if(isset($this->param['id']) && !empty($this->param['id'])){
//执行编辑
$param = [
'data'=>json_encode($this->param['data']),
];
$setNumModel->edit($param,['id'=>$this->param['id']]);
}else{
//执行新增
$param = [
'type'=>$setNumModel::TYPE_CUSTOM_SORT,
'num'=>$this->param['module_id'],
'project_id'=>$this->user['project_id'],
'data'=>json_encode($this->param['data']),
];
$setNumModel->add($param);
}
}catch (\Exception $e){
Log::info('error file: ' . __CLASS__ . __FUNCTION__ . $e->getMessage());
$this->response('设置排序失败,请稍后重试',Code::SYSTEM_ERROR);
}
$this->response('success');
}
/**
* @remark :获取排序
* @name :getProductSort
* @author :lyh
* @method :post
* @time :2024/1/31 10:24
*/
public function getCustomSort(){
$setNumModel = new SettingNum();
$info = $setNumModel->read(['type'=>$setNumModel::TYPE_CUSTOM_SORT,'num'=>$this->param['module_id']]);
if($info === false){
$info = [];
}else{
$info['data'] = json_decode($info['data']);
}
$this->response('success',Code::SUCCESS,$info);
}
/**
* @remark :批量设置产品分类
* @name :batchSetCategory
* @author :lyh
* @method :post
* @time :2023/8/15 17:51
*/
public function batchSetCategory(CustomModuleContentLogic $logic){
$this->request->validate([
'id'=>'required',
'category_id'=>'required',
],[
'id.required' => '产品ID不能为空',
'category_id.required' => '分类ID不能为空',
]);
$logic->batchSetCategory();
$this->response('success');
}
}