ReplaceHtmlLogic.php
7.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
<?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\CustomModule\CustomModule;
use App\Models\Template\BTemplate;
use App\Models\Template\Setting;
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 :获取模版id
* @name :getTemplateId
* @author :lyh
* @method :post
* @time :2024/5/9 18:03
*/
public function getTemplateId($typeInfo){
//获取当前template_id
$bSettingModel = new Setting();
$templateInfo = $bSettingModel->read(['project_id'=>$this->param['project_id']]);
if($templateInfo === false){
$this->fail('请先选择模版');
}
$template_id = $templateInfo['template_id'];
if($typeInfo['is_custom'] == 1){//扩展模块
$customModuleModel = new CustomModule();
$moduleInfo = $customModuleModel->read(['id'=>$typeInfo['type']],['list_customized','detail_customized']);
if($moduleInfo === false){
$this->fail('当前扩展模块不存在或已被删除');
}
if($typeInfo['is_list'] == 1 && $moduleInfo['list_customized'] == 1){
$template_id = 0;
}
if($typeInfo['is_list'] == 0 && $moduleInfo['detail_customized'] == 1){
$template_id = 0;
}
}
return $this->success($template_id);
}
/**
* @remark :替换可视化的html代码(按类型)
* @name :replaceHtml
* @author :lyh
* @method :post
* @time :2024/5/7 15:52
*/
public function replaceTemplateMainHtml(){
$data = $this->sourceTypeInfo();
$typeInfo = $data[$this->param['name']];
if(!isset($typeInfo)){
$this->fail('当前类型不存在,请联系管理员');
}
$template_id = $this->getTemplateId($typeInfo);
//查询当前类型所有装修的记录
ProjectServer::useProject($this->param['project_id']);
$bTemplateModel = new BTemplate();
$condition = ['source'=>$typeInfo['source'],'is_custom'=>$typeInfo['is_custom'],
'is_list'=>$typeInfo['is_list'], 'template_id'=>$template_id,'main_html'=>['like','%'.$this->param['old_html'].'%']];
$list = $bTemplateModel->list($condition);
DB::disconnect('custom_mysql');
//TODO::生成一条任务记录
$total_num = count($list);
$replaceId = $this->saveReplaceHtml($this->param,$typeInfo,$template_id,$total_num);
foreach ($list as $value){
//生成子任务
$this->saveReplaceHtmlLog($replaceId,$value);
}
return $this->success();
}
/**
* @remark :生成一条记录
* @name :saveTemplateLog
* @author :lyh
* @method :post
* @time :2024/5/8 9:23
*/
public function saveReplaceHtml($param,$typeInfo,$template_id,$total_num){
$logData = [
'source'=>$typeInfo['source'],
'is_custom'=>$typeInfo['is_custom'],
'is_list'=>$typeInfo['is_list'],
'template_id'=>$template_id,
'status'=>$this->model::STATUS,
'old_html'=>$param['old_html'],
'html'=>$param['html'],
'project_id'=>$param['project_id'],
'total_num'=>$total_num,
];
return $this->model->addReturnId($logData);
}
/**
* @remark :保存每条替换记录
* @name :saveReplaceHtmlLog
* @author :lyh
* @method :post
* @time :2024/5/8 9:37
*/
public function saveReplaceHtmlLog($param,$replace_id,$data){
$logData = [
'replace_id'=>$replace_id,
'source'=>$data['source'],
'source_id'=>$data['source_id'],
'is_list'=>$data['is_list'],
'is_custom'=>$data['is_custom'],
'project_id'=>$data['project_id'],
'uid'=>$this->user['manager_id'],
'status'=>$this->model::STATUS,
'old_html'=>$param['old_html'],
'html'=>$param['html'],
'template_id'=>$data['template_id']
];
$replaceHtmlModel = new TemplateReplaceHtmlLog();
$save_id = $replaceHtmlModel->addReturnId($logData);
return $this->success($save_id);
}
/**
* @remark :还原所有记录
* @name :reductionHtml
* @author :lyh
* @method :post
* @time :2024/5/8 10:35
*/
public function reductionHtml(){
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('当前数据不存在');
}
$replaceId = $this->saveResultReplaceHtml($info);
ProjectServer::useProject($this->param['project_id']);
$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'=>$value['id']]);
}else{
$html = str_replace($info['html'],$info['old_html'],$value['html']);
$this->model->edit(['html'=>$html],['id'=>$value['id']]);
}
}
$this->saveReplaceHtmlLog($replaceId,$value['id']);
}
DB::disconnect('custom_mysql');
return $this->success();
}
/**
* @remark :保存还原的html
* @name :saveResultReplaceHtml
* @author :lyh
* @method :post
* @time :2024/5/10 10:01
*/
public function saveResultReplaceHtml($info){
$logData = [
'type'=>$info['type'],
'is_custom'=>$info['is_custom'],
'is_list'=>$info['is_list'],
'template_id'=>$info['template_id'],
'old_html'=>$info['html'],
'html'=>$info['old_html'],
'project_id'=>$info['project_id'],
];
return $this->model->addReturnId($logData);
}
/**
* @remark :替换类型
* @name :sourceTypeInfo
* @author :lyh
* @method :post
* @time :2024/5/9 17:15
*/
public function sourceTypeInfo(){
ProjectServer::useProject($this->param['project_id']);
$data = $this->model->sourceType();
$customModule = new CustomModule();
$moduleList = $customModule->list(['project_id'=>$this->param['project_id']],'id',['id','name']);
foreach ($moduleList as $value){
$data[$value['name'].'详情'] = ['source'=>$value['id'],'is_list'=>0,'is_custom'=>1];
$data[$value['name'].'列表'] = ['source'=>$value['id'],'is_list'=>1,'is_custom'=>1];
}
DB::disconnect('custom_mysql');
return $this->success($data);
}
}