|
@@ -104,9 +104,14 @@ class BTemplateLogic extends BaseLogic |
|
@@ -104,9 +104,14 @@ class BTemplateLogic extends BaseLogic |
|
104
|
$ATemplateModel = new Template();
|
104
|
$ATemplateModel = new Template();
|
|
105
|
$TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
|
105
|
$TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
|
|
106
|
}else{
|
106
|
}else{
|
|
107
|
- //渲染首页数据
|
107
|
+ $commonTemplateModel = new BTemplateCommon();
|
|
|
|
108
|
+ $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
|
|
|
|
109
|
+ if($commonInfo !== false){
|
|
|
|
110
|
+ $TemplateInfo['html'] = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
|
|
|
|
111
|
+ $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
|
|
|
|
112
|
+ }
|
|
108
|
$ATemplateModel = new Template();
|
113
|
$ATemplateModel = new Template();
|
|
109
|
- $ATemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
|
114
|
+ $ATemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']],['name','image']);
|
|
110
|
$TemplateInfo['name'] = $ATemplateInfo['name'];
|
115
|
$TemplateInfo['name'] = $ATemplateInfo['name'];
|
|
111
|
$TemplateInfo['image_link'] = getImageUrl($ATemplateInfo['image']);
|
116
|
$TemplateInfo['image_link'] = getImageUrl($ATemplateInfo['image']);
|
|
112
|
}
|
117
|
}
|
|
@@ -122,23 +127,34 @@ class BTemplateLogic extends BaseLogic |
|
@@ -122,23 +127,34 @@ class BTemplateLogic extends BaseLogic |
|
122
|
* @time :2023/7/25 16:40
|
127
|
* @time :2023/7/25 16:40
|
|
123
|
*/
|
128
|
*/
|
|
124
|
public function productHtml($info,$source,$source_id){
|
129
|
public function productHtml($info,$source,$source_id){
|
|
|
|
130
|
+ $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
|
|
|
|
131
|
+ if($homeTemplateInfo === false){
|
|
|
|
132
|
+ $this->fail('请先装修首页');
|
|
|
|
133
|
+ }
|
|
125
|
//查看当前模板是否已编辑保存web_template
|
134
|
//查看当前模板是否已编辑保存web_template
|
|
126
|
$TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
|
135
|
$TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
|
|
127
|
if($TemplateInfo === false){
|
136
|
if($TemplateInfo === false){
|
|
128
|
- //获取首页数据
|
|
|
|
129
|
- $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
|
|
|
|
130
|
- if($homeTemplateInfo === false){
|
|
|
|
131
|
- $this->fail('请先装修首页');
|
137
|
+ //兼容老数据
|
|
|
|
138
|
+ $commonTemplateModel = new BTemplateCommon();
|
|
|
|
139
|
+ $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
|
|
|
|
140
|
+ if($commonInfo !== false){
|
|
|
|
141
|
+ $html = $commonInfo['head_css']."<style id='globalsojs-styles'></style>".$commonInfo['footer_css'].$commonInfo['other'].
|
|
|
|
142
|
+ $commonInfo['head_html']."<main>{$this->getProductModule()}</main>".$commonInfo['footer_html'];
|
|
|
|
143
|
+ }else{
|
|
|
|
144
|
+ $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);
|
|
|
|
145
|
+ $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);
|
|
132
|
}
|
146
|
}
|
|
133
|
- $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);
|
|
|
|
134
|
- $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html);
|
|
|
|
135
|
}else{
|
147
|
}else{
|
|
136
|
- $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
|
|
|
|
137
|
- if($homeTemplateInfo === false){
|
|
|
|
138
|
- $this->fail('请先装修首页');
|
148
|
+ //兼容老数据
|
|
|
|
149
|
+ $commonTemplateModel = new BTemplateCommon();
|
|
|
|
150
|
+ $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);
|
|
|
|
151
|
+ if($commonInfo !== false){
|
|
|
|
152
|
+ $html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
|
|
|
|
153
|
+ $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
|
|
|
|
154
|
+ }else{
|
|
|
|
155
|
+ $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
|
|
|
|
156
|
+ $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
|
|
139
|
}
|
157
|
}
|
|
140
|
- $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);
|
|
|
|
141
|
- $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html);
|
|
|
|
142
|
}
|
158
|
}
|
|
143
|
$TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
|
159
|
$TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
|
|
144
|
return $this->success($TemplateInfo);
|
160
|
return $this->success($TemplateInfo);
|
|
@@ -187,17 +203,19 @@ class BTemplateLogic extends BaseLogic |
|
@@ -187,17 +203,19 @@ class BTemplateLogic extends BaseLogic |
|
187
|
$info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
|
203
|
$info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
|
|
188
|
//字符串截取
|
204
|
//字符串截取
|
|
189
|
$this->param = $this->stringProcessing($this->param);
|
205
|
$this->param = $this->stringProcessing($this->param);
|
|
190
|
- $this->param = $this->templateSaveParam($this->param);
|
206
|
+ $this->saveCommonTemplate($this->param);
|
|
|
|
207
|
+ $this->param = $this->templateSaveParam($this->param);//组装数据
|
|
191
|
if($info === false){
|
208
|
if($info === false){
|
|
192
|
$this->model->add($this->param);
|
209
|
$this->model->add($this->param);
|
|
193
|
}else{
|
210
|
}else{
|
|
194
|
$this->model->edit($this->param,['id'=>$info['id']]);
|
211
|
$this->model->edit($this->param,['id'=>$info['id']]);
|
|
195
|
}
|
212
|
}
|
|
|
|
213
|
+ //写入操作模版记录
|
|
196
|
$this->setTemplateLog($this->param);
|
214
|
$this->setTemplateLog($this->param);
|
|
197
|
DB::commit();
|
215
|
DB::commit();
|
|
198
|
}catch (\Exception $e){
|
216
|
}catch (\Exception $e){
|
|
199
|
DB::rollBack();
|
217
|
DB::rollBack();
|
|
200
|
- $this->fail('error');
|
218
|
+ $this->fail('系统错误,请联系管理员');
|
|
201
|
}
|
219
|
}
|
|
202
|
//通知更新
|
220
|
//通知更新
|
|
203
|
$this->homeOrProduct($this->param['source'],$this->param['source_id']);
|
221
|
$this->homeOrProduct($this->param['source'],$this->param['source_id']);
|
|
@@ -205,6 +223,34 @@ class BTemplateLogic extends BaseLogic |
|
@@ -205,6 +223,34 @@ class BTemplateLogic extends BaseLogic |
|
205
|
}
|
223
|
}
|
|
206
|
|
224
|
|
|
207
|
/**
|
225
|
/**
|
|
|
|
226
|
+ * @remark :保存头部公共数据
|
|
|
|
227
|
+ * @name :saveCommonTemplate
|
|
|
|
228
|
+ * @author :lyh
|
|
|
|
229
|
+ * @method :post
|
|
|
|
230
|
+ * @time :2023/10/13 14:27
|
|
|
|
231
|
+ */
|
|
|
|
232
|
+ public function saveCommonTemplate($param){
|
|
|
|
233
|
+ $templateCommonModel = new BTemplateCommon();
|
|
|
|
234
|
+ $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id']]);
|
|
|
|
235
|
+// @file_put_contents(storage_path('logs/lyh_error.log'), var_export($param['html'], true) . PHP_EOL, FILE_APPEND);
|
|
|
|
236
|
+ $data = [
|
|
|
|
237
|
+ 'head_html'=>$param['head_html'],
|
|
|
|
238
|
+ 'head_css'=>$param['head_css'],
|
|
|
|
239
|
+ 'footer_html'=>$param['footer_html'],
|
|
|
|
240
|
+ 'footer_css'=>$param['footer_css'],
|
|
|
|
241
|
+ 'other'=>str_replace('<header','',characterTruncation($param['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")),
|
|
|
|
242
|
+ ];
|
|
|
|
243
|
+ if($info === false){
|
|
|
|
244
|
+ $data['template_id'] = $param['template_id'];
|
|
|
|
245
|
+ $data['project_id'] = $this->user['project_id'];
|
|
|
|
246
|
+ $templateCommonModel->add($data);
|
|
|
|
247
|
+ }else{
|
|
|
|
248
|
+ $templateCommonModel->edit($data,['id'=>$info['id']]);
|
|
|
|
249
|
+ }
|
|
|
|
250
|
+ return $this->success();
|
|
|
|
251
|
+ }
|
|
|
|
252
|
+
|
|
|
|
253
|
+ /**
|
|
208
|
* @remark :生成记录
|
254
|
* @remark :生成记录
|
|
209
|
* @name :setTemplateLog
|
255
|
* @name :setTemplateLog
|
|
210
|
* @author :lyh
|
256
|
* @author :lyh
|