ReplaceHtmlLogic.php
3.1 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
<?php
/**
* @remark :
* @name :ReplaceHtmlLogic.php
* @author :lyh
* @method :post
* @time :2024/5/8 10:03
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BTemplate;
use App\Models\Template\TemplateReplaceHtml;
use App\Models\Template\TemplateReplaceHtmlLog;
class ReplaceHtmlLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new TemplateReplaceHtml();
$this->param = $this->requestAll;
}
/**
* @remark :替换可视化的html代码(按类型)
* @name :replaceHtml
* @author :lyh
* @method :post
* @time :2024/5/7 15:52
*/
public function replaceHtml(){
$type = $this->getCustomizedType($this->param['type'], $this->param['is_list']);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//当前页面是定制界面
$this->param['template_id'] = 0;
}
$replaceId = $this->saveReplaceHtml($this->param);
//TODO::生成一条任务记录
//查询当前所有装修的
$condition = ['source'=>$this->param['type'],'is_custom'=>$this->param['is_custom'],'is_list'=>$this->param['is_list'],
'template_id'=>$this->param['template_id']];
$list = $this->model->list($condition);
foreach ($list as $v){
if($v['type'] == 0){
$main_html = str_replace($this->param['old_html'],$this->param['html'],$v['main_html']);
$this->model->edit(['main_html'=>$main_html],['id'=>$v['id']]);
}else{
$html = str_replace($this->param['old_html'],$this->param['html'],$v['html']);
$this->model->edit(['html'=>$html],['id'=>$v['id']]);
}
$this->saveReplaceHtmlLog($replaceId,$v['id']);
}
return $this->success();
}
/**
* @remark :生成一条记录
* @name :saveTemplateLog
* @author :lyh
* @method :post
* @time :2024/5/8 9:23
*/
public function saveReplaceHtml($data,$template_id){
$logData = [
'type'=>$data['type'],
'is_custom'=>$data['is_custom'],
'is_list'=>$data['is_list'],
'template_id'=>$template_id,
'old_html'=>$data['old_html'],
'html'=>$data['html'],
];
return $this->model->addReturnId($logData);
}
/**
* @remark :保存每条替换记录
* @name :saveReplaceHtmlLog
* @author :lyh
* @method :post
* @time :2024/5/8 9:37
*/
public function saveReplaceHtmlLog($replace_id,$replace_template_id){
$logData = [
'replace_id'=>$replace_id,
'replace_template_id'=>$replace_template_id,
'uid'=>$this->user['manager_id'],
];
$replaceHtmlModel = new TemplateReplaceHtmlLog();
return $replaceHtmlModel->add($logData);
}
}