ReplaceHtmlLogic.php
4.3 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
<?php
/**
* @remark :
* @name :ReplaceHtmlLogic.php
* @author :lyh
* @method :post
* @time :2024/5/8 10:03
*/
namespace App\Http\Logic\Aside\Template;
use App\Http\Logic\aside\BaseLogic;
use App\Models\Template\BTemplate;
use App\Models\Template\TemplateReplaceHtml;
use App\Models\Template\TemplateReplaceHtmlLog;
use App\Services\ProjectServer;
use Illuminate\Support\Facades\DB;
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(){
ProjectServer::useProject($this->param['project_id']);
//TODO::生成一条任务记录
$replaceId = $this->saveReplaceHtml($this->param);
//查询当前类型所有装修的记录
$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']);
}
DB::disconnect('custom_mysql');
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);
}
/**
* @remark :还原所有记录
* @name :reductionHtml
* @author :lyh
* @method :post
* @time :2024/5/8 10:35
*/
public function reductionHtml(){
ProjectServer::useProject($this->param['project_id']);
//获取当前数据详情
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在');
}
$replaceLogModel = new TemplateReplaceHtmlLog();
$logList = $replaceLogModel->list(['replace_id'=>$this->param['id']]);
$replaceArr = [];
foreach ($logList as $v){
$replaceArr[] = $v['replace_template_id'];
}
if(!empty($replaceArr)){
//查询可视化数据
$bTemplateModel = new BTemplate();
$templateList = $bTemplateModel->list(['id'=>['in',$replaceArr]]);
foreach ($templateList as $value){
if($v['type'] == 0){
$main_html = str_replace($info['html'],$info['old_html'],$value['main_html']);
$this->model->edit(['main_html'=>$main_html],['id'=>$v['id']]);
}else{
$html = str_replace($info['html'],$info['old_html'],$value['html']);
$this->model->edit(['html'=>$html],['id'=>$v['id']]);
}
}
}
DB::disconnect('custom_mysql');
return $this->success();
}
}