BTemplateLogLogic.php
10.0 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
<?php
/**
* @remark :
* @name :BTemplateLogLogic.php
* @author :lyh
* @method :post
* @time :2023/8/23 11:54
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\Setting;
class BTemplateLogLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BTemplateLog();
$this->param = $this->requestAll;
}
/**
* @remark :回滚版本
* @name :saveRollbackVersion
* @author :lyh
* @method :post
* @time :2023/8/23 11:55
*/
public function saveRollbackVersion(){
//获取当前数据详情
$info = $this->model->read(['id'=>$this->param['id']]);
if($info === false){
$this->fail('error');
}
$bTemplateModel = new BTemplate();
//演示项目,不允许其他号码编辑
if(($this->user['project_id'] == 1) && (!in_array($this->user['mobile'],$bTemplateModel->mobile)) && ($info['source'] == 1)){
$this->fail('演示项目仅支持演示功能,无法更改首页');
}
if($info['template_id'] == 0) {//todo::定制项目
return $this->rollBackCustomized($info);
}
//TODO::非定制项目,获取当前项目的模版
return $this->rollBackNoCustomized($info);
}
/**
* @remark :定制页面还原
* @name :rollBackCustomized
* @author :lyh
* @method :post
* @time :2024/4/23 14:36
*/
public function rollBackCustomized($info){
$bTemplateModel = new BTemplate();
$condition = ['template_id'=>0,'source'=>$info['source'],'source_id'=>$info['source_id'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
//TODO::还原头部+底部
$bTemplateModel->edit(['html'=>$info['text']],$condition);
$commonTemplateModel = new BTemplateCommon();
//还原头部
$condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom'],'project_id'=>$this->user['project_id']];
$condition['common_type'] = BTemplate::COMMON_HEAD;
$commonTemplateModel->edit(['head'=>$info['head_html'], 'head_style'=>$info['head_css']],$condition);
$condition['common_type'] = BTemplate::COMMON_FOOTER;
$commonTemplateModel->edit(['footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']],$condition);
return $this->success();
}
/**
* @remark :非定制界面还原
* @name :rollBackNoCustomized
* @author :lyh
* @method :post
* @time :2024/4/23 14:38
*/
public function rollBackNoCustomized($info){
$bSettingModel = new Setting();
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($settingInfo === false){
$this->fail('请先选择模版');
}
$bTemplateModel = new BTemplate();
try {
//切换模版
if($info['template_id'] != $settingInfo['template_id']){
$bSettingModel->edit(['template_id'=>$info['template_id']],['id'=>$settingInfo['id']]);
}
$data = ['main_html'=>$info['main_html'], 'main_css'=>$info['main_css']];
$condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
$bTemplateModel->edit($data,$condition);
//还原头部+底部
$commonData = [
'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_style'=>$info['footer_css'],'other'=>$info['other']
];
$this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']);
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :保存公共部分(头部。底部。连接部分)
* @name :saveTemplateCom
* @author :lyh
* @method :post
* @time :2024/4/29 10:32
*/
public function saveTemplateCom($handleInfo,$template_id,$source,$is_list,$is_custom){
$typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
$templateComModel = new BTemplateCom();
foreach ($typeArr as $type){
if($type == BTemplate::COMMON_HEAD){
$param['html'] = $handleInfo['head_html'];
$param['html_style'] = $handleInfo['head_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
}elseif ($type == BTemplate::COMMON_FOOTER){
$param['html'] = $handleInfo['footer_html'];
$param['html_style'] = $handleInfo['footer_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
}else{
$param['html'] = $handleInfo['other'];
$param['html_style'] = null;
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
}
//查看当前数据是否还存在
$condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
$info = $templateComModel->read($condition);
if($info === false){
$data = array_merge($param,$condition);
$templateComModel->add($data);
}else{
$templateComModel->edit($param,$condition);
}
}
return $this->success();
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
if($template_id == 0){//定制全为独立头部和底部
$type = $source;
return $this->success($type);
}
$type = BTemplate::SOURCE_COM;//公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
if ($pageInfo === false) {
return $this->success($type);
}
if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
return $this->success($type);
}
/**
* @remark :获取数据详情
* @name :templateLogInfo
* @author :lyh
* @method :post
* @time :2023/9/19 14:42
*/
public function templateLogInfo(){
$info = $this->model->read($this->param);
if($info === false){
$this->fail('当前数据不存在,或已被删除');
}
if($this->user['is_customized'] != BTemplate::IS_VISUALIZATION){
$html = $this->getTemplateHtml($info);
}else{
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
if (in_array(1, $page_array)) {//首页是定制界面
$html = $info['text'];
}else{
$html = $this->getTemplateHtml($info);
}
}
return $this->success(['html'=>$html]);
}
/**
* @remark :生成界面
* @name :getTemplateHtml
* @author :lyh
* @method :post
* @time :2024/4/3 17:11
*/
public function getTemplateHtml($info){
if(empty($info['other'])){
$footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s'));
$info['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
}
$html = $info['head_css'].$info['main_css'].$info['footer_css'].$info['other'].
$info['head_html'].$info['main_html'].$info['footer_html'];
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
//拼接html
foreach ($list as $v){
if($v['key'] == 'head'){
$html = $v['values'].$html;
}
if($v['key'] == 'footer'){
$html = $html.$v['values'];
}
}
return $this->success($html);
}
}