CustomModuleContentController.php
4.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
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
<?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\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\User\User;
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);
if(!empty($lists)){
$data = $this->getAllCategoryName();
foreach ($lists['list'] as $k=>$v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['image_link'] = getImageUrl($v['image']);
$v['operator_name'] = (new User())->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @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 $this->success($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();
$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不能为空'
]);
$logic->contentSave();
$this->response('success');
}
/**
* @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');
}
}