作者 lyh

gx

@@ -176,9 +176,6 @@ class BTemplateLogic extends BaseLogic @@ -176,9 +176,6 @@ class BTemplateLogic extends BaseLogic
176 $this->fail('定制页面,请先上传代码块'); 176 $this->fail('定制页面,请先上传代码块');
177 } 177 }
178 $commonInfo = $this->getCustomizedCommonHtml($type);//获取定制头部 178 $commonInfo = $this->getCustomizedCommonHtml($type);//获取定制头部
179 - if($this->user['project_id'] == 655){  
180 - return $customHtmlInfo['main_html'];  
181 - }  
182 if($commonInfo !== false){ 179 if($commonInfo !== false){
183 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']); 180 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
184 } 181 }
@@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic @@ -264,12 +264,36 @@ class InitHtmlLogic extends BaseLogic
264 if($info === false){ 264 if($info === false){
265 $html = ''; 265 $html = '';
266 }else{ 266 }else{
  267 + $type = $this->getCustomizedType($this->param['type'],$is_list);
  268 + $commonTemplateModel = new BTemplateCommon();
  269 + $commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type]);
  270 + if($commonInfo !== false){
  271 + $info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);
  272 + }
267 $html = $info['main_html']; 273 $html = $info['main_html'];
268 } 274 }
  275 + //更新头部底部
269 return $this->success(['html'=>$html]); 276 return $this->success(['html'=>$html]);
270 } 277 }
271 278
272 /** 279 /**
  280 + * @remark :返回整个html截取代码
  281 + * @name :handleAllHtml
  282 + * @author :lyh
  283 + * @method :post
  284 + * @time :2023/12/13 15:39
  285 + */
  286 + public function handleAllHtml($commonInfo,$html){
  287 + if(!empty($commonInfo)){
  288 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
  289 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
  290 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
  291 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
  292 + }
  293 + return $html;
  294 + }
  295 +
  296 + /**
273 * @remark :保存定制html 297 * @remark :保存定制html
274 * @name :saveHtml 298 * @name :saveHtml
275 * @author :lyh 299 * @author :lyh
@@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic @@ -292,6 +316,8 @@ class InitHtmlLogic extends BaseLogic
292 }else{ 316 }else{
293 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 317 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
294 } 318 }
  319 + //更新头部底部
  320 + $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list);
295 }catch (\Exception $exception){ 321 }catch (\Exception $exception){
296 $this->fail('保存失败,请联系开发人员'); 322 $this->fail('保存失败,请联系开发人员');
297 } 323 }
@@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic @@ -299,6 +325,68 @@ class InitHtmlLogic extends BaseLogic
299 } 325 }
300 326
301 /** 327 /**
  328 + * @remark :定制代码更新头部信息
  329 + * @name :saveCustomizeCommon
  330 + * @author :lyh
  331 + * @method :post
  332 + * @time :2024/1/6 10:29
  333 + */
  334 + public function saveCustomizeCommon($html,$source,$is_list){
  335 + $type = $this->getCustomizedType($source,$is_list);
  336 + $templateCommonModel = new BTemplateCommon();
  337 + $commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type]);//查看当前头部是否存在
  338 + $handleInfo = $this->handleCommonParam($html);
  339 + if($commonInfo === false){
  340 + $data = [
  341 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  342 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  343 + 'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],
  344 + ];
  345 + $templateCommonModel->add($data);
  346 + }else{
  347 + $data = [
  348 + 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
  349 + 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
  350 + ];
  351 + $templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
  352 + }
  353 + return $this->success();
  354 + }
  355 +
  356 + /**
  357 + * @remark :定制页面头部类型---根据source获取type类型
  358 + * @name :getType
  359 + * @author :lyh
  360 + * @method :post
  361 + * @time :2023/11/16 11:20
  362 + */
  363 + public function getCustomizedType($source,$is_list){
  364 + $type = BTemplate::TYPE_HOME;
  365 + if($source == BTemplate::SOURCE_PRODUCT){
  366 + if($is_list == BTemplate::IS_LIST){
  367 + $type = BTemplate::TYPE_PRODUCT_LIST;
  368 + }else{
  369 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
  370 + }
  371 + }
  372 + if($source == BTemplate::SOURCE_BLOG){
  373 + if($is_list == BTemplate::IS_LIST){
  374 + $type = BTemplate::TYPE_BLOG_LIST;
  375 + }else{
  376 + $type = BTemplate::TYPE_BLOG_DETAIL;
  377 + }
  378 + }
  379 + if($source == BTemplate::SOURCE_NEWS){
  380 + if($is_list == BTemplate::IS_LIST){
  381 + $type = BTemplate::TYPE_NEWS_LIST;
  382 + }else{
  383 + $type = BTemplate::TYPE_NEWS_DETAIL;
  384 + }
  385 + }
  386 + return $type;
  387 + }
  388 +
  389 + /**
302 * @remark :前端获取设置模块(侧边栏) 390 * @remark :前端获取设置模块(侧边栏)
303 * @name :getInitModuleMain 391 * @name :getInitModuleMain
304 * @author :lyh 392 * @author :lyh