CustomModuleLogic.php
5.8 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
<?php
/**
* @remark :
* @name :CustomModuleLogic.php
* @author :lyh
* @method :post
* @time :2023/12/4 15:46
*/
namespace App\Http\Logic\Aside\CustomModule;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\IsCom\ProjectComConfig;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class CustomModuleLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
}
/**
* @remark :获取当前数据详情
* @name :getCustomModuleInfo
* @author :lyh
* @method :post
* @time :2023/12/4 16:10
*/
public function getCustomModuleInfo(){
ProjectServer::useProject($this->param['project_id']);
$info = (new CustomModule())->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
DB::disconnect('custom_mysql');
return $this->success($info);
}
/**
* @remark :保存数据
* @name :ModuleSave
* @author :lyh
* @method :post
* @time :2023/12/4 15:47
*/
public function customModuleSave(){
ProjectServer::useProject($this->param['project_id']);
$this->param = $this->handleParam($this->param);
$this->checkIsName($this->param['name'],$this->param['id'] ?? 0);
if(isset($this->param['id']) && !empty($this->param['id'])){
$this->moduleEdit();
}else{
$this->moduleAdd();
}
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @name :(参数处理)paramProcessing
* @author :lyh
* @method :post
* @time :2023/6/13 11:30
*/
public function handleParam($param)
{
$param['operator_id'] = $this->manager['id'];
if(!isset($param['id']) || empty($param['id'])){
$param['project_id'] = $this->param['project_id'];
}
if(in_array($param['route'],['blogs','news','top_blog','blog','product','products'])){
$this->fail('不允许使用项目默认模块路由');
}
return $this->success($param);
}
/**
* @remark :新增
* @name :moduleAdd
* @author :lyh
* @method :post
* @time :2023/12/5 9:39
*/
public function moduleAdd(){
$id = (new CustomModule())->addReturnId($this->param);
if($id){
//同时创建对应route的分类
$customModuleCateModel = new CustomModuleCategory();
$data = [
'name'=>$this->param['route'],
'module_id'=>$id,
'project_id'=>$this->param['project_id'],
'route'=>$this->param['route']
];
$cateId = $customModuleCateModel->addReturnId($data);
$route = RouteMap::setRoute($this->param['route'],RouteMap::SOURCE_MODULE_CATE,$cateId,$this->param['project_id']);
$customModuleCateModel->edit(['route'=>$route],['id'=>$cateId]);
}
return $this->success();
}
/**
* @remark :编辑
* @name :moduleEdit
* @author :lyh
* @method :post
* @time :2023/12/5 9:39
*/
public function moduleEdit(){
$rs = (new CustomModule())->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :验证名称是否存在
* @name :checkIsName
* @author :lyh
* @method :post
* @time :2024/1/6 14:06
*/
public function checkIsName($name,$id = 0){
$param['name'] = $name;
if(!empty($id)){
$param['id'] = ['!=',$id];
}
$info = (new CustomModule())->read($param);
if($info !== false){
$this->fail('当前名称已存在');
}
return $this->success();
}
/**
* @remark :删除数据
* @name :ModuleDel
* @author :lyh
* @method :post
* @time :2023/12/4 15:47
*/
public function customModuleDel(){
ProjectServer::useProject($this->param['project_id']);
//查看当前模块是否拥有数据
$contentModel = new CustomModuleContent();
$contentInfo = $contentModel->read(['module_id'=>$this->param['id']],['id']);
if($contentInfo !== false){
$this->fail('当前模块拥有内容不允许删除');
}
$categoryModel = new CustomModuleCategory();
$categoryInfo = $categoryModel->read(['module_id'=>$this->param['id']],['id']);
if($categoryInfo !== false){
$this->fail('当前模块拥有分类不允许删除');
}
$rs = (new CustomModule())->del($this->param);
//对应删除项目头部底部配置
$projectComConfigModel = new ProjectComConfig();
$projectComConfigModel->del(['source'=>$this->param['id'],'is_custom'=>1]);
if($rs === false){
$this->fail('系统错误,请联系管理员');
}
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @remark :设置排序
* @name :setTopping
* @author :lyh
* @method :post
* @time :2023/12/21 11:03
*/
public function setTopping(){
ProjectServer::useProject($this->param['project_id']);
$moduleModel = new CustomModule();
$rs = $moduleModel->edit(['topping_time'=>date('Y-m-d H:i:s')],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('置顶失败,请联系管理员');
}
DB::disconnect('custom_mysql');
}
}