GeneratePageService.php
18.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
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
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
<?php
/**
* @remark :
* @name :GeneratePageService.php
* @author :lyh
* @method :post
* @time :2024/2/19 15:54
*/
namespace App\Services\Html;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Project\PageSetting;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
use App\Models\Template\TemplateTypeMain;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
class GeneratePageService
{
protected $route;
protected $param;
protected $project_id = 0;
/**
* @remark :生成单页数据
* @name :generateHtml
* @author :lyh
* @method :post
* @time :2024/2/19 16:57
*/
public function generateHtml($projectInfo,$routeInfo){
$this->project_id = $projectInfo['id'];
$this->route = $routeInfo['route'];
ProjectServer::useProject($this->project_id);
$this->handleParam($routeInfo);
$result = $this->getTemplateHtml($projectInfo);
DB::disconnect('custom_mysql');
return $this->success($result);
}
/**
* @remark :生成页面参数处理
* @name :generateHtml
* @author :lyh
* @method :post
* @time :2024/2/19 16:36
*/
public function handleParam($routeInfo){
switch ($routeInfo['source']){
case RouteMap::SOURCE_PRODUCT:
$this->param['source'] = BTemplate::SOURCE_PRODUCT;
$this->param['is_list'] = BTemplate::IS_DETAIL;
break;
case RouteMap::SOURCE_PRODUCT_CATE:
$this->param['source'] = BTemplate::SOURCE_PRODUCT;
$this->param['is_list'] = BTemplate::IS_LIST;
break;
case RouteMap::SOURCE_BLOG:
$this->param['source'] = BTemplate::SOURCE_BLOG;
$this->param['is_list'] = BTemplate::IS_DETAIL;
break;
case RouteMap::SOURCE_BLOG_CATE:
$this->param['source'] = BTemplate::SOURCE_BLOG;
$this->param['is_list'] = BTemplate::IS_LIST;
break;
case RouteMap::SOURCE_NEWS:
$this->param['source'] = BTemplate::SOURCE_NEWS;
$this->param['is_list'] = BTemplate::IS_DETAIL;
break;
case RouteMap::SOURCE_NEWS_CATE:
$this->param['source'] = BTemplate::SOURCE_NEWS;
$this->param['is_list'] = BTemplate::IS_LIST;
break;
case RouteMap::SOURCE_MODULE:
$this->param['is_custom'] = BTemplate::IS_CUSTOM;
//TODO::获取对应模块数据
$moduleModel = new CustomModuleContent();
$moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);
$this->param['source'] = $moduleInfo['id'] ?? 0;
$this->param['is_list'] = BTemplate::IS_DETAIL;
break;
case RouteMap::SOURCE_MODULE_CATE:
$this->param['is_custom'] = BTemplate::IS_CUSTOM;
//TODO::获取对应模块数据
$moduleModel = new CustomModuleCategory();
$moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);
$this->param['source'] = $moduleInfo['id'] ?? 0;
$this->param['is_list'] = BTemplate::IS_LIST;
break;
default:
$this->param['source'] = BTemplate::SOURCE_HOME;
$this->param['is_list'] = BTemplate::IS_DETAIL;
break;
return true;
}
}
/**
* @notes: 请简要描述方法功能
* @param array $data
* @return array
*/
public function success($data = [])
{
return $data;
}
/**
* @remark :获取html
* @name :getTemplateHtml
* @author :lyh
* @method :post
*/
public function getTemplateHtml($projectInfo){
$is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块
$is_list = $this->param['is_list'] ?? 0;//是否为列表页
$template_id = $this->getSettingTemplate($projectInfo,$this->param['source'],$is_list,$is_custom);//设置的模版id
if($template_id === false){
return false;
}
$templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list);
if($templateInfo === false){
if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
$html = $this->customizedReturnHtml($projectInfo,$this->param['source'],$template_id,$is_custom,$is_list);
if($html !== false){
return $this->success($html);
}
}
//非定制初始中间部分
$mainInfo = $this->getMAinHtml($this->param['source'],$is_custom,$is_list);//获取中间部分代码
}else{
if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码
return $this->getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list);
}
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
}
$commonInfo = $this->getCommonHtml($projectInfo,$this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部
$html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
$result = ['html'=>$html];
return $this->success($result);
}
/**
* @remark :获取整个html代码
* @name :getCustomizeAllHtml
* @author :lyh
* @method :post
* @time :2024/1/10 14:15
*/
public function getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list){
if($is_custom == BTemplate::IS_CUSTOM){
$commonInfo = $this->getCustomizedCommonHtml($this->param['source'],$is_custom,$is_list);//获取定制头部
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
}else{
$type = $this->getCustomizedType($this->param['source'],$is_list);
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
}
return $this->success(['html'=>$html,'template_id'=>$template_id]);
}
/**
* @remark :获取装修详情
* @name :webTemplateInfo
* @author :lyh
* @method :post
* @time :2024/1/10 13:43
*/
public function webTemplateInfo($source,$source_id,$template_id,$is_custom,$is_list){
$templateInfo = $this->model->read([
'template_id'=>$template_id, 'source'=>$source,
'project_id'=>$this->project_id, 'source_id'=>$source_id,
'is_custom'=>$is_custom, 'is_list'=>$is_list
]);
return $this->success($templateInfo);
}
/**
* @remark :定制页面获取html
* @name :customizedReturnHtml
* @author :lyh
* @method :post
* @time :2024/1/10 13:46
*/
public function customizedReturnHtml($projectInfo,$source,$template_id,$is_custom,$is_list){
//TODO::扩展模块定制单独处理
if($is_custom == BTemplate::IS_CUSTOM){
$customModuleModel = new CustomModule();
$info = $customModuleModel->read(['id'=>$source]);
if($info === false){
return false;
}
//扩展模块定制
if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
if($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
if($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
return false;
}
//TODO::默认模块定制
$html = $this->isCustomizedPage($projectInfo,$source,$is_list,$is_custom);//获取定制页面的html
if($html !== false){
return $this->success(['html'=>$html]);
}
return false;
}
/**
* @remark :扩展模块定制html
* @name :customModuleInfo
* @author :lyh
* @method :post
* @time :2024/1/10 9:20
*/
public function customModuleCustomizeHtml($source,$is_list,$is_custom){
$bTemplateMainModel = new BTemplateMain();
//TODO::获取初始代码
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($customHtmlInfo === false){
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
$customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
}
return $customHtmlInfo['main_html'];
}
/**
* @remark :获取中间部分的html
* @name :getMAinHtml
* @author :lyh
* @method :post
* @time :2023/12/27 15:00
*/
public function getMAinHtml($type,$is_custom,$is_list){
//获取设置的默认中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['type'=>$type,'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($mainInfo === false){
$main_html = $this->getInitModule($type,$is_custom,$is_list);
$main_css = "<style id='globalsojs-styles'></style>";
}else{
$main_html = $mainInfo['main_html'];
$main_css = $mainInfo['main_css'];
}
return ['main_html'=>$main_html,'main_css'=>$main_css];
}
/**
* @remark :默认复合页数据
* @name :getProductModule
* @author :lyh
* @method :post
* @time :2023/7/27 15:08
*/
public function getInitModule($type,$is_custom,$is_list){
if($is_custom == BTemplate::IS_CUSTOM) {
$type = BTemplate::SOURCE_CUSTOM;
}
$mainModel = new TemplateTypeMain();
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
return $info['main_html'];
}
/**
* @remark :返回整个html截取代码
* @name :handleAllHtml
* @author :lyh
* @method :post
* @time :2023/12/13 15:39
*/
public function handleAllHtml($commonInfo,$html){
if(!empty($commonInfo)){
$html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
$html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
$html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
$html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
}
return $html;
}
/**
* @remark :页面是否为定制页面获取初始代码
* @name :watchProjectIsCustomized
* @author :lyh
* @method :post
* @time :2023/12/13 10:55
*/
public function isCustomizedPage($projectInfo,$source,$is_list,$is_custom)
{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
//TODO::获取初始代码
$bTemplateMainModel = new BTemplateMain();
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_custom'=>$is_custom,'is_list'=>$is_list]);
if($customHtmlInfo === false){
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
$customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
}
return $customHtmlInfo['main_html'];
}
return false;
}
/**
* @remark :定制项目获取头部底部
* @name :getCustomizedCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/29 13:13
*/
public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){
$data = [
'template_id' => 0,
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>$is_custom,
'is_list'=>$is_list
];
$commonTemplateModel = new BTemplateCommon();
return $commonTemplateModel->read($data);
}
/**
* @remark :定制页面头部类型---根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/11/16 11:20
*/
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_HOME;
if($source == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_PRODUCT_LIST;
}else{
$type = BTemplate::TYPE_PRODUCT_DETAIL;
}
}
if($source == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_BLOG_LIST;
}else{
$type = BTemplate::TYPE_BLOG_DETAIL;
}
}
if($source == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_NEWS_LIST;
}else{
$type = BTemplate::TYPE_NEWS_DETAIL;
}
}
return $type;
}
/**
* @remark :获取当前项目设置的模版
* @name :getSettingTemplate
* @author :lyh
* @method :post
* @time :2023/12/13 10:48
*/
public function getSettingTemplate($projectInfo,$source,$is_list,$is_custom){
$template_id = 0;
if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
if($is_custom == BTemplate::IS_CUSTOM){
$customModuleModel = new CustomModule();
$info = $customModuleModel->read(['id'=>$source]);
if($info === false){
return false;
}
if($info['list_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_LIST){
return $this->success($template_id);
}
if($info['detail_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_DETAIL){
return $this->success($template_id);
}
}else{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$projectInfo['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
return $this->success($template_id);
}
}
}
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$this->project_id]);
if($info === false){
return false;
}
$template_id = $info['template_id'];
return $this->success($template_id);
}
/**
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @author :lyh
* @method :post
* @time :2023/10/21 16:55
*/
public function getCommonHtml($ProjectInfo,$source,$is_list,$template_id,$is_custom = 0,){
$type = $this->getType($ProjectInfo,$source,$is_list,$is_custom);
$data = [
'template_id' => $template_id,
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>0,
];
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$data['type'] = BTemplate::SOURCE_HOME;
$commonInfo = $commonTemplateModel->read($data);
}
return $this->success($commonInfo);
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($projectInfo,$source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);
if ($pageInfo === false) {
return $this->success($type);
}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
}
return $this->success($type);
}
}