|
@@ -272,10 +272,19 @@ class BTemplateLogic extends BaseLogic |
|
@@ -272,10 +272,19 @@ class BTemplateLogic extends BaseLogic |
|
272
|
$this->showProjectNoEdit($this->param['source']);
|
272
|
$this->showProjectNoEdit($this->param['source']);
|
|
273
|
DB::beginTransaction();
|
273
|
DB::beginTransaction();
|
|
274
|
try {
|
274
|
try {
|
|
275
|
- //字符串截取
|
|
|
|
276
|
- $this->param = $this->handleSaveParam($this->param);
|
|
|
|
277
|
- $this->saveTemplateHtml($this->param);
|
|
|
|
278
|
- $this->setTemplateLog($this->param);
|
275
|
+ $this->param = $this->handleDefaultString($this->param);//设置默认字符
|
|
|
|
276
|
+ $templateInfo = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],
|
|
|
|
277
|
+ $this->param['source_id'],$this->param['is_custom']);
|
|
|
|
278
|
+ if($templateInfo === false){//执行新增
|
|
|
|
279
|
+ $this->templateAddHtml($this->param['html'], $this->param['source'], $this->param['source_id'],
|
|
|
|
280
|
+ $this->param['template_id'], $this->param['section_list_id'], $this->param['is_custom']);
|
|
|
|
281
|
+ }else{//执行编辑
|
|
|
|
282
|
+ $this->templateEditHtml($this->param['html'],$this->param['source'],$this->param['source_id'],
|
|
|
|
283
|
+ $this->param['template_id'],$this->param['section_list_id'], $this->param['is_custom']);
|
|
|
|
284
|
+ }
|
|
|
|
285
|
+ //更新头部信息
|
|
|
|
286
|
+ $this->saveCommonHtml($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id']);
|
|
|
|
287
|
+ $this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom']);
|
|
279
|
DB::commit();
|
288
|
DB::commit();
|
|
280
|
}catch (\Exception $e){
|
289
|
}catch (\Exception $e){
|
|
281
|
DB::rollBack();
|
290
|
DB::rollBack();
|
|
@@ -287,56 +296,93 @@ class BTemplateLogic extends BaseLogic |
|
@@ -287,56 +296,93 @@ class BTemplateLogic extends BaseLogic |
|
287
|
}
|
296
|
}
|
|
288
|
|
297
|
|
|
289
|
/**
|
298
|
/**
|
|
290
|
- * @remark :可视化保存html
|
|
|
|
291
|
- * @name :saveHtml
|
299
|
+ * @remark :保存数据时设置默认字符
|
|
|
|
300
|
+ * @name :saveDefaultString
|
|
292
|
* @author :lyh
|
301
|
* @author :lyh
|
|
293
|
* @method :post
|
302
|
* @method :post
|
|
294
|
- * @time :2023/12/13 17:02
|
303
|
+ * @time :2023/12/15 10:30
|
|
295
|
*/
|
304
|
*/
|
|
296
|
- public function saveHtml($html,$source,$source_id,$section_list_id,$template_id = 0,$is_custom = 0){
|
|
|
|
297
|
- $type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
|
|
|
|
298
|
- //查看当前页面是否定制,是否开启可视化
|
|
|
|
299
|
- $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
|
|
|
|
300
|
- if (in_array($type, $page_array)) {//是定制界面
|
|
|
|
301
|
-
|
|
|
|
302
|
-
|
305
|
+ public function handleDefaultString($param){
|
|
|
|
306
|
+ if(!isset($param['template_id'])){
|
|
|
|
307
|
+ $param['template_id'] = 0;
|
|
303
|
}
|
308
|
}
|
|
304
|
- //保存头部底部
|
|
|
|
305
|
- $this->saveCommonHtml($html,$source,$source_id,$template_id);
|
|
|
|
306
|
- $templateInfo = $this->webTemplateInfo($template_id,$source,$source_id,$is_custom);
|
|
|
|
307
|
- $handleInfo = $this->handleTemplateParam($html);
|
|
|
|
308
|
- if($templateInfo === false){
|
|
|
|
309
|
- //TODO::查看当前界面是否为定制界面
|
|
|
|
310
|
- $data = [
|
|
|
|
311
|
- 'source'=>$source,'source_id'=>$source_id,'section_list_id'=>$section_list_id,
|
|
|
|
312
|
- 'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],
|
|
|
|
313
|
- 'main_html'=>$handleInfo['main_html'],'main_css'=>$handleInfo['main_css']
|
|
|
|
314
|
- ];
|
|
|
|
315
|
- $this->model->add($data);
|
|
|
|
316
|
- }else{
|
|
|
|
317
|
- $data = [
|
|
|
|
318
|
- 'main_html'=>$handleInfo['main_html'],'main_css'=>$handleInfo['main_css'],'section_list_id'=>$section_list_id
|
|
|
|
319
|
- ];
|
|
|
|
320
|
- $this->model->edit($data,['id'=>$templateInfo['id']]);
|
309
|
+ if(!isset($param['is_custom'])){
|
|
|
|
310
|
+ $param['is_custom'] = 0;
|
|
321
|
}
|
311
|
}
|
|
322
|
- return $this->success();
|
312
|
+ if(!isset($param['section_list_id'])){
|
|
|
|
313
|
+ $param['section_list_id'] = '';
|
|
|
|
314
|
+ }
|
|
|
|
315
|
+ return $this->success($param);
|
|
323
|
}
|
316
|
}
|
|
324
|
|
317
|
|
|
325
|
/**
|
318
|
/**
|
|
326
|
- * @remark :定制项目处理数据
|
|
|
|
327
|
- * @name :saveCustomizedHtml
|
319
|
+ * @remark :可视化添加数据
|
|
|
|
320
|
+ * @name :templateAddHtml
|
|
328
|
* @author :lyh
|
321
|
* @author :lyh
|
|
329
|
* @method :post
|
322
|
* @method :post
|
|
330
|
- * @time :2023/12/15 9:38
|
323
|
+ * @time :2023/12/15 10:15
|
|
331
|
*/
|
324
|
*/
|
|
332
|
- public function saveCustomizedHtml($source,$source_id)
|
|
|
|
333
|
- {
|
|
|
|
334
|
-
|
325
|
+ public function templateAddHtml($html,$source,$source_id,$template,$section_list_id,$is_custom){
|
|
|
|
326
|
+ $data = [
|
|
|
|
327
|
+ 'source'=>$source, 'source_id'=>$source_id,'type'=>BTemplate::PAGE_HTML,
|
|
|
|
328
|
+ 'template_id'=>$template, 'project_id'=>$this->user['project_id'],
|
|
|
|
329
|
+ 'section_list_id'=>$section_list_id,'is_custom'=>$is_custom,
|
|
|
|
330
|
+ ];
|
|
|
|
331
|
+ $data = $this->handleVisualizationParam($html,$source,$source_id,$data);
|
|
|
|
332
|
+ $this->model->add($data);
|
|
|
|
333
|
+ return true;
|
|
|
|
334
|
+ }
|
|
335
|
|
335
|
|
|
|
|
336
|
+ /**
|
|
|
|
337
|
+ * @remark :可视化更新html
|
|
|
|
338
|
+ * @name :templateEditHtml
|
|
|
|
339
|
+ * @author :lyh
|
|
|
|
340
|
+ * @method :post
|
|
|
|
341
|
+ * @time :2023/12/15 10:26
|
|
|
|
342
|
+ */
|
|
|
|
343
|
+ public function templateEditHtml($html,$source,$source_id,$template,$section_list_id,$is_custom){
|
|
|
|
344
|
+ $condition = [
|
|
|
|
345
|
+ 'source'=>$source, 'source_id'=>$source_id,
|
|
|
|
346
|
+ 'is_custom'=>$is_custom, 'template_id'=>$template
|
|
|
|
347
|
+ ];
|
|
|
|
348
|
+ $data = [
|
|
|
|
349
|
+ 'section_list_id'=>$section_list_id
|
|
|
|
350
|
+ ];
|
|
|
|
351
|
+ $data = $this->handleVisualizationParam($html,$source,$source_id,$data);
|
|
|
|
352
|
+ $this->model->edit($data,$condition);
|
|
336
|
return true;
|
353
|
return true;
|
|
337
|
}
|
354
|
}
|
|
338
|
|
355
|
|
|
339
|
/**
|
356
|
/**
|
|
|
|
357
|
+ * @remark :处理可视化数据
|
|
|
|
358
|
+ * @name :handleProjectParam
|
|
|
|
359
|
+ * @author :lyh
|
|
|
|
360
|
+ * @method :post
|
|
|
|
361
|
+ * @time :2023/12/15 10:59
|
|
|
|
362
|
+ */
|
|
|
|
363
|
+ public function handleVisualizationParam($html,$source, $source_id,$data){
|
|
|
|
364
|
+ if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//定制项目
|
|
|
|
365
|
+ $type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
|
|
|
|
366
|
+ //查看当前页面是否定制,是否开启可视化
|
|
|
|
367
|
+ $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
|
|
|
|
368
|
+ if (in_array($type, $page_array)) {//当前页面是定制界面
|
|
|
|
369
|
+ $data['html'] = $html;
|
|
|
|
370
|
+ $data['type'] = BTemplate::ALL_HTML;
|
|
|
|
371
|
+ }else{
|
|
|
|
372
|
+ $mainInfo = $this->handleTemplateHtml($html);
|
|
|
|
373
|
+ $data['main_html'] = $mainInfo['main_html'];
|
|
|
|
374
|
+ $data['main_css'] = $mainInfo['main_css'];
|
|
|
|
375
|
+ }
|
|
|
|
376
|
+ }else{
|
|
|
|
377
|
+ $mainInfo = $this->handleTemplateHtml($html);
|
|
|
|
378
|
+ $data['main_html'] = $mainInfo['main_html'];
|
|
|
|
379
|
+ $data['main_css'] = $mainInfo['main_css'];
|
|
|
|
380
|
+ }
|
|
|
|
381
|
+ return $data;
|
|
|
|
382
|
+ }
|
|
|
|
383
|
+
|
|
|
|
384
|
+
|
|
|
|
385
|
+ /**
|
|
340
|
* @remark :保存公共头部底部
|
386
|
* @remark :保存公共头部底部
|
|
341
|
* @name :saveCommonHtml
|
387
|
* @name :saveCommonHtml
|
|
342
|
* @author :lyh
|
388
|
* @author :lyh
|
|
@@ -382,61 +428,6 @@ class BTemplateLogic extends BaseLogic |
|
@@ -382,61 +428,6 @@ class BTemplateLogic extends BaseLogic |
|
382
|
}
|
428
|
}
|
|
383
|
|
429
|
|
|
384
|
/**
|
430
|
/**
|
|
385
|
- * @remark :保存可视化数据
|
|
|
|
386
|
- * @name :saveTemplateHtml
|
|
|
|
387
|
- * @author :lyh
|
|
|
|
388
|
- * @method :post
|
|
|
|
389
|
- * @time :2023/12/12 10:23
|
|
|
|
390
|
- */
|
|
|
|
391
|
- public function saveTemplateHtml($param){
|
|
|
|
392
|
- //TODO::自定义默认默认取首页的头部底部,不需要保存头部底部
|
|
|
|
393
|
- if($param['is_custom'] == 0){
|
|
|
|
394
|
- $this->saveCommonTemplate($param);
|
|
|
|
395
|
- }
|
|
|
|
396
|
- $info = $this->webTemplateInfo($this->param['template_id'],$param['source'],$param['source_id'],$param['is_custom']);
|
|
|
|
397
|
- $param['project_id'] = $this->user['project_id'];
|
|
|
|
398
|
- unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
|
|
|
|
399
|
- if($info === false){
|
|
|
|
400
|
- $this->model->add($param);
|
|
|
|
401
|
- }else{
|
|
|
|
402
|
- $this->model->edit($param,['id'=>$info['id']]);
|
|
|
|
403
|
- }
|
|
|
|
404
|
- return true;//组装数据
|
|
|
|
405
|
- }
|
|
|
|
406
|
-
|
|
|
|
407
|
- /**
|
|
|
|
408
|
- * @remark :保存头部公共数据
|
|
|
|
409
|
- * @name :saveCommonTemplate
|
|
|
|
410
|
- * @author :lyh
|
|
|
|
411
|
- * @method :post
|
|
|
|
412
|
- * @time :2023/10/13 14:27
|
|
|
|
413
|
- */
|
|
|
|
414
|
- public function saveCommonTemplate($param){
|
|
|
|
415
|
- $type = $this->getType($param['source'],$param['source_id']);
|
|
|
|
416
|
- $templateCommonModel = new BTemplateCommon();
|
|
|
|
417
|
- $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id'],'type'=>$type]);
|
|
|
|
418
|
- $data = [
|
|
|
|
419
|
- 'head_html'=>$param['head_html'],
|
|
|
|
420
|
- 'head_css'=>$param['head_css'],
|
|
|
|
421
|
- 'footer_html'=>$param['footer_html'],
|
|
|
|
422
|
- 'footer_css'=>$param['footer_css'],
|
|
|
|
423
|
- ];
|
|
|
|
424
|
- $footer_other = str_replace('<header','',characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<header/s'));
|
|
|
|
425
|
- $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
|
|
|
|
426
|
- if($info === false){
|
|
|
|
427
|
- $data['template_id'] = $param['template_id'];
|
|
|
|
428
|
- $data['project_id'] = $this->user['project_id'];
|
|
|
|
429
|
- $data['type'] = $type;
|
|
|
|
430
|
- $templateCommonModel->add($data);
|
|
|
|
431
|
- }else{
|
|
|
|
432
|
- $templateCommonModel->edit($data,['id'=>$info['id']]);
|
|
|
|
433
|
- }
|
|
|
|
434
|
- //更新所有界面的other
|
|
|
|
435
|
- $templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$param['template_id']]);
|
|
|
|
436
|
- return $this->success();
|
|
|
|
437
|
- }
|
|
|
|
438
|
-
|
|
|
|
439
|
- /**
|
|
|
|
440
|
* @remark :保存时字符串处理
|
431
|
* @remark :保存时字符串处理
|
|
441
|
* @name :handleCommonParam
|
432
|
* @name :handleCommonParam
|
|
442
|
* @author :lyh
|
433
|
* @author :lyh
|
|
@@ -461,7 +452,7 @@ class BTemplateLogic extends BaseLogic |
|
@@ -461,7 +452,7 @@ class BTemplateLogic extends BaseLogic |
|
461
|
* @method :post
|
452
|
* @method :post
|
|
462
|
* @time :2023/6/29 15:35
|
453
|
* @time :2023/6/29 15:35
|
|
463
|
*/
|
454
|
*/
|
|
464
|
- public function handleTemplateParam($html){
|
455
|
+ public function handleTemplateHtml($html){
|
|
465
|
//字符串截取
|
456
|
//字符串截取
|
|
466
|
$param['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
|
457
|
$param['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
|
|
467
|
$param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
458
|
$param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
@@ -500,24 +491,17 @@ class BTemplateLogic extends BaseLogic |
|
@@ -500,24 +491,17 @@ class BTemplateLogic extends BaseLogic |
|
500
|
* @method :post
|
491
|
* @method :post
|
|
501
|
* @time :2023/8/23 11:16
|
492
|
* @time :2023/8/23 11:16
|
|
502
|
*/
|
493
|
*/
|
|
503
|
- public function setTemplateLog($param){
|
494
|
+ public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){
|
|
504
|
$data = [
|
495
|
$data = [
|
|
505
|
- 'template_id'=>$param['template_id'],
|
496
|
+ 'template_id'=>$template_id,
|
|
506
|
'project_id'=>$this->user['project_id'],
|
497
|
'project_id'=>$this->user['project_id'],
|
|
507
|
'operator_id'=>$this->user['id'],
|
498
|
'operator_id'=>$this->user['id'],
|
|
508
|
- 'text'=>$param['html'],
|
|
|
|
509
|
- 'source'=>$param['source'],
|
|
|
|
510
|
- 'source_id'=>$param['source_id'],
|
|
|
|
511
|
- 'head_html'=>$param['head_html'],
|
|
|
|
512
|
- 'head_css'=>$param['head_css'],
|
|
|
|
513
|
- 'main_html'=>$param['main_html'],
|
|
|
|
514
|
- 'main_css'=>$param['main_css'],
|
|
|
|
515
|
- 'footer_html'=>$param['footer_html'],
|
|
|
|
516
|
- 'footer_css'=>$param['footer_css'],
|
|
|
|
517
|
- 'is_custom'=>$param['is_custom']
|
499
|
+ 'text'=>$html,
|
|
|
|
500
|
+ 'type'=>$type,
|
|
|
|
501
|
+ 'is_custom'=>$is_custom,
|
|
|
|
502
|
+ 'source'=>$source,
|
|
|
|
503
|
+ 'source_id'=>$source_id
|
|
518
|
];
|
504
|
];
|
|
519
|
- $footer_other = str_replace('<header','',characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<header/s'));
|
|
|
|
520
|
- $data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
|
|
|
|
521
|
$bTemplateLogModel = new BTemplateLog();
|
505
|
$bTemplateLogModel = new BTemplateLog();
|
|
522
|
return $bTemplateLogModel->add($data);
|
506
|
return $bTemplateLogModel->add($data);
|
|
523
|
}
|
507
|
}
|
|
@@ -591,8 +575,9 @@ class BTemplateLogic extends BaseLogic |
|
@@ -591,8 +575,9 @@ class BTemplateLogic extends BaseLogic |
|
591
|
$param['main_css'] = characterTruncation($param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
575
|
$param['main_css'] = characterTruncation($param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
592
|
$param['footer_css'] = characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
|
576
|
$param['footer_css'] = characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
|
|
593
|
if(!isset($param['is_custom'])){
|
577
|
if(!isset($param['is_custom'])){
|
|
594
|
- $param['is_custom'] = 0;
|
578
|
+ $param['is_custom'] = BTemplate::SOURCE_NO_CUSTOM;
|
|
595
|
}
|
579
|
}
|
|
|
|
580
|
+ $param['type'] = BTemplate::PAGE_HTML;//不显示整个HTML
|
|
596
|
return $this->success($param);
|
581
|
return $this->success($param);
|
|
597
|
}
|
582
|
}
|
|
598
|
|
583
|
|