作者 赵彬吉
@@ -122,34 +122,23 @@ class BTemplateLogic extends BaseLogic @@ -122,34 +122,23 @@ class BTemplateLogic extends BaseLogic
122 * @time :2023/7/25 16:40 122 * @time :2023/7/25 16:40
123 */ 123 */
124 public function productHtml($info,$source,$source_id){ 124 public function productHtml($info,$source,$source_id){
125 - $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);  
126 - if($homeTemplateInfo === false){  
127 - $this->fail('请先装修首页');  
128 - }  
129 //查看当前模板是否已编辑保存web_template 125 //查看当前模板是否已编辑保存web_template
130 $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id); 126 $TemplateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id);
131 if($TemplateInfo === false){ 127 if($TemplateInfo === false){
132 - //兼容老数据  
133 - $commonTemplateModel = new BTemplateCommon();  
134 - $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);  
135 - if($commonInfo !== false){  
136 - $html = $commonInfo['head_css']."<style id='globalsojs-styles'></style>".$commonInfo['head_css'].$commonInfo['other'].  
137 - $commonInfo['head_html'].$this->getProductModule().$commonInfo['footer_html'];  
138 - }else{  
139 - $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', "<style id='globalsojs-styles'></style>", $homeTemplateInfo['html']);  
140 - $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s', "<main>{$this->getProductModule()}</main>", $html); 128 + //获取首页数据
  129 + $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
  130 + if($homeTemplateInfo === false){
  131 + $this->fail('请先装修首页');
141 } 132 }
  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);
142 }else{ 135 }else{
143 - //兼容老数据  
144 - $commonTemplateModel = new BTemplateCommon();  
145 - $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id']]);  
146 - if($commonInfo !== false){  
147 - $html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['head_css'].$commonInfo['other'].  
148 - $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];  
149 - }else{  
150 - $html = preg_replace('/<style id="globalsojs-styles">(.*?)<\/style>/s', $TemplateInfo['main_css'], $homeTemplateInfo['html']);  
151 - $html = preg_replace('/<main\b[^>]*>(.*?)<\/main>/s',$TemplateInfo['main_html'] , $html); 136 + $homeTemplateInfo = $this->webTemplateInfo($info['template_id'],1,0);
  137 + if($homeTemplateInfo === false){
  138 + $this->fail('请先装修首页');
152 } 139 }
  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);
153 } 142 }
154 $TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据 143 $TemplateInfo['html'] = $this->getHeadFooter($html);//组装数据
155 return $this->success($TemplateInfo); 144 return $this->success($TemplateInfo);
@@ -198,13 +187,12 @@ class BTemplateLogic extends BaseLogic @@ -198,13 +187,12 @@ class BTemplateLogic extends BaseLogic
198 $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']); 187 $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
199 //字符串截取 188 //字符串截取
200 $this->param = $this->stringProcessing($this->param); 189 $this->param = $this->stringProcessing($this->param);
201 - $this->param = $this->templateSaveParam($this->param);//组装数据 190 + $this->param = $this->templateSaveParam($this->param);
202 if($info === false){ 191 if($info === false){
203 $this->model->add($this->param); 192 $this->model->add($this->param);
204 }else{ 193 }else{
205 $this->model->edit($this->param,['id'=>$info['id']]); 194 $this->model->edit($this->param,['id'=>$info['id']]);
206 } 195 }
207 - $this->saveCommonTemplate($this->param);  
208 $this->setTemplateLog($this->param); 196 $this->setTemplateLog($this->param);
209 DB::commit(); 197 DB::commit();
210 }catch (\Exception $e){ 198 }catch (\Exception $e){
@@ -217,33 +205,6 @@ class BTemplateLogic extends BaseLogic @@ -217,33 +205,6 @@ class BTemplateLogic extends BaseLogic
217 } 205 }
218 206
219 /** 207 /**
220 - * @remark :保存头部公共数据  
221 - * @name :saveCommonTemplate  
222 - * @author :lyh  
223 - * @method :post  
224 - * @time :2023/10/13 14:27  
225 - */  
226 - public function saveCommonTemplate($param){  
227 - $templateCommonModel = new BTemplateCommon();  
228 - $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id']]);  
229 - $data = [  
230 - 'head_html'=>$param['head_html'],  
231 - 'head_css'=>$param['head_css'],  
232 - 'footer_html'=>$param['footer_html'],  
233 - 'footer_css'=>$param['footer_css'],  
234 - 'other'=>str_replace('header','',characterTruncation($param['html'],'/<link id="google-fonts-link">(.*?)header/s')),  
235 - ];  
236 - if($info === false){  
237 - $data['template_id'] = $param['template_id'];  
238 - $data['project_id'] = $this->user['project_id'];  
239 - $templateCommonModel->add($data);  
240 - }else{  
241 - $templateCommonModel->edit($data,['id'=>$info['id']]);  
242 - }  
243 - return $this->success();  
244 - }  
245 -  
246 - /**  
247 * @remark :生成记录 208 * @remark :生成记录
248 * @name :setTemplateLog 209 * @name :setTemplateLog
249 * @author :lyh 210 * @author :lyh
@@ -300,7 +261,11 @@ class BTemplateLogic extends BaseLogic @@ -300,7 +261,11 @@ class BTemplateLogic extends BaseLogic
300 */ 261 */
301 public function templateSaveParam($param){ 262 public function templateSaveParam($param){
302 $param['project_id'] = $this->user['project_id']; 263 $param['project_id'] = $this->user['project_id'];
303 - $param['html'] = $param['main_html']; 264 + if($param['source'] == 1){//首页
  265 + $param['html'] = characterTruncation($param['html'],'/<style id="globalsojs-header">(.*?)<\/footer>/s');
  266 + }else{
  267 + $param['html'] = $param['main_html'];
  268 + }
304 return $this->success($param); 269 return $this->success($param);
305 } 270 }
306 271