ATemplateLogic.php
9.5 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
<?php
namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\Aside\BaseLogic;
use App\Models\Manage\Manage;
use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Template;
use App\Models\Template\Setting;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class ATemplateLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new Template();
$this->param = $this->requestAll;
}
/**
* @remark :公共模块模板
* @name :aTemplateList
* @author :lyh
* @method :post
* @time :2023/6/28 17:03
*/
public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['*']){
$map['deleted_status'] = 0;
$map['status'] = 0;
$lists = $this->model->lists($map,$page,$row,$order,$filed);
return $this->success($lists);
}
/**
* @remark :添加或编辑模块
* @name :aTemplateSave
* @author :lyh
* @method :post
* @time :2023/6/28 17:13
*/
public function aTemplateSave(){
//字符串截取
$this->StringProcessing();
if(isset($this->param['id'])){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
}else{
$rs = $this->model->add($this->param);
}
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :字符串处理
* @name :StringProcessing
* @author :lyh
* @method :post
* @time :2023/6/29 15:35
*/
public function StringProcessing(){
//字符串截取
$this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
$this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
$this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s');
$this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
}
/**
* @remark :修改模块状态
* @name :aTemplateStatus
* @author :lyh
* @method :post
* @time :2023/6/28 17:15
*/
public function aTemplateStatus(){
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :逻辑删除模板数据
* @name :aTemplateDel
* @author :lyh
* @method :post
* @time :2023/6/28 17:17
*/
public function aTemplateDel(){
//查看当前模板是否有模板在使用
$BSettingModel = new Setting();
$info = $BSettingModel->read(['template_id'=>$this->param['id']]);
if($info !== false){
$this->fail('当前模板有项目在使用,不允许删除');
}
$rs = $this->model->edit(['deleted_status'=>1,'deleted_at'=>date('Y-m-d H:i:s')],['id'=>$this->param['id']]);
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :获取数据详情
* @name :aTemplateRead
* @author :lyh
* @method :post
* @time :2023/7/3 9:22
*/
public function aTemplateRead(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
if(!empty($info['image'])){
$info['image_link'] = getImageUrl($info['image']);
}
if(!empty($info['design_manager'])){
$info['design_manager'] = (new Manage())->getName($info['design_manager']);
}
if(!empty($info['front_manager'])){
$info['front_manager'] = (new Manage())->getName($info['front_manager']);
}
return $this->success($info);
}
/**
* @remark :设置主题公共head
* @name :setHeadInfo
* @author :lyh
* @method :post
* @time :2023/7/10 15:32
*/
public function setHeadFooterSave(){
$serviceSettingModel = new ServiceSettingModel();
DB::beginTransaction();
try {
$serviceSettingModel->del(['type'=>2]);
$data = [
['type'=>2,'key'=>'head','values'=>$this->param['head'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')],
['type'=>2,'key'=>'footer','values'=>$this->param['footer'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]
];
$serviceSettingModel->insert($data);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('error');
}
return $this->success();
}
/**
* @remark :获取主题公共head
* @name :getHeadInfo
* @author :lyh
* @method :post
* @time :2023/7/10 15:33
*/
public function getHeadFooterList(){
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
return $this->success($list);
}
/**
* @remark :设置模板
* @name :setTemplate
* @author :lyh
* @method :post
* @time :2023/6/29 9:47
*/
public function setTemplate(){
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
if($info === false){
$param = [
'project_id'=>$this->param['project_id'],
'template_id'=>$this->param['template_id'],
];
$rs = $bSettingModel->add($param);
}else{
$rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['id'=>$info['id']]);
}
$this->saveTemplate($this->param['project_id'],$this->param['template_id']);
//保存一条装修数据
if($rs === false){
$this->fail('error');
}
return $this->success();
}
/**
* @remark :设置模版保存装修首页记录
* @name :saveTemplate
* @author :lyh
* @method :post
* @time :2023/11/17 11:04
*/
public function saveTemplate($project_id,$template_id){
$templateInfo = $this->model->read(['id'=>$template_id]);
ProjectServer::useProject($project_id);
$bTemplateModel = new BTemplate();
$info = $bTemplateModel->read(['source'=>1,'template_id'=>$template_id]);
if($info === false){
$data = [
'source'=>1, 'source_id'=>0, 'template_id'=>$template_id, 'main_html'=>$templateInfo['main_html'],
'main_css'=>$templateInfo['main_css'], 'project_id'=>$project_id,
];
$bTemplateModel->add($data);
}
//保存一次公共头部信息
$bCommonTemplateModel = new BTemplateCommon();
$commonInfo = $bCommonTemplateModel->read(['template_id'=>$template_id,'type'=>1]);
if($commonInfo === false){
$commonData = [
'type'=>1, 'template_id'=>$template_id, 'head_html'=>$templateInfo['head_html'],
'head_css'=>$templateInfo['head_css'], 'footer_html'=>$templateInfo['footer_html'],
'footer_css'=>$templateInfo['footer_css'],'project_id'=>$project_id,
'other'=>str_replace('<header','',characterTruncation($templateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s"))
];
$bCommonTemplateModel->add($commonData);
}
RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $project_id);
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @remark :获取选择的模版
* @name :getSettingInfo
* @author :lyh
* @method :post
* @time :2023/11/3 17:21
*/
public function getSettingInfo(){
$data = [];
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$this->param['project_id']],['template_id']);
if($info !== false){
$data = $this->model->read(['id'=>$info['template_id']],['id','name']);
}
return $this->success($data);
}
/**
* @remark :修改状态
* @name :auditingStatus
* @author :lyh
* @method :post
* @time :2024/5/23 16:44
*/
public function auditingStatus(){
//获取当前数据详情
$info = $this->model->read(['id'=>$this->param['id']]);
if(isset($this->param['front_status']) && $this->param['front_status'] == 1){
if($info['design_status'] == 0){
$this->fail('请先提交设计审核');
}
$this->param['design_manager'] = $this->manager['id'];
$this->param['test_model'] = 0;
}else{
$this->param['front_manager'] = $this->manager['id'];
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
if($rs === false){
$this->fail('修改失败,请联系管理员');
}
return $this->success(['id'=>$this->param['id']]);
}
}