作者 lyh

gx

@@ -101,7 +101,7 @@ class BTemplateLogLogic extends BaseLogic @@ -101,7 +101,7 @@ class BTemplateLogLogic extends BaseLogic
101 $bTemplateModel->edit($data,$condition); 101 $bTemplateModel->edit($data,$condition);
102 //还原头部+底部 102 //还原头部+底部
103 $commonData = [ 103 $commonData = [
104 - 'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_style'],'other'=>$info['other'] 104 + 'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_style'=>$info['footer_css'],'other'=>$info['other']
105 ]; 105 ];
106 $this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']); 106 $this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']);
107 }catch (\Exception $e){ 107 }catch (\Exception $e){
@@ -124,15 +124,15 @@ class BTemplateLogLogic extends BaseLogic @@ -124,15 +124,15 @@ class BTemplateLogLogic extends BaseLogic
124 if($type == BTemplate::COMMON_HEAD){ 124 if($type == BTemplate::COMMON_HEAD){
125 $param['html'] = $handleInfo['head_html']; 125 $param['html'] = $handleInfo['head_html'];
126 $param['html_style'] = $handleInfo['head_style']; 126 $param['html_style'] = $handleInfo['head_style'];
127 - $typeSource = $this->getType($source,$is_list,$is_custom,$type);//头部是否为独立头部 127 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
128 }elseif ($type == BTemplate::COMMON_FOOTER){ 128 }elseif ($type == BTemplate::COMMON_FOOTER){
129 $param['html'] = $handleInfo['footer_html']; 129 $param['html'] = $handleInfo['footer_html'];
130 $param['html_style'] = $handleInfo['footer_style']; 130 $param['html_style'] = $handleInfo['footer_style'];
131 - $typeSource = $this->getType($source,$is_list,$is_custom,$type); 131 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
132 }else{ 132 }else{
133 $param['html'] = $handleInfo['other']; 133 $param['html'] = $handleInfo['other'];
134 $param['html_style'] = null; 134 $param['html_style'] = null;
135 - $typeSource = $this->getType($source,$is_list,$is_custom); 135 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
136 } 136 }
137 //查看当前数据是否还存在 137 //查看当前数据是否还存在
138 $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type]; 138 $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
@@ -154,7 +154,11 @@ class BTemplateLogLogic extends BaseLogic @@ -154,7 +154,11 @@ class BTemplateLogLogic extends BaseLogic
154 * @method :post 154 * @method :post
155 * @time :2023/10/21 17:29 155 * @time :2023/10/21 17:29
156 */ 156 */
157 - public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD){ 157 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  158 + if($template_id == 0){//定制全为独立头部和底部
  159 + $type = $source;
  160 + return $this->success($type);
  161 + }
158 $type = BTemplate::SOURCE_COM;//公共头部底部 162 $type = BTemplate::SOURCE_COM;//公共头部底部
159 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 163 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
160 if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部 164 if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
@@ -104,7 +104,7 @@ class BTemplateLogic extends BaseLogic @@ -104,7 +104,7 @@ class BTemplateLogic extends BaseLogic
104 */ 104 */
105 public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){ 105 public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){
106 $condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>'','is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id]; 106 $condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>'','is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id];
107 - $headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom); 107 + $headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id);
108 $bTemplateComModel = new BTemplateCom(); 108 $bTemplateComModel = new BTemplateCom();
109 $condition['common_type'] = BTemplate::COMMON_OTHER; 109 $condition['common_type'] = BTemplate::COMMON_OTHER;
110 $condition['source'] = $headComInfo['source']; 110 $condition['source'] = $headComInfo['source'];
@@ -112,7 +112,7 @@ class BTemplateLogic extends BaseLogic @@ -112,7 +112,7 @@ class BTemplateLogic extends BaseLogic
112 if($otherInfo === false){ 112 if($otherInfo === false){
113 $this->fail('获取失败,请联系管理员'); 113 $this->fail('获取失败,请联系管理员');
114 } 114 }
115 - $footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom); 115 + $footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id);
116 $data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '', 116 $data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
117 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? '']; 117 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
118 return $this->success($data); 118 return $this->success($data);
@@ -125,8 +125,8 @@ class BTemplateLogic extends BaseLogic @@ -125,8 +125,8 @@ class BTemplateLogic extends BaseLogic
125 * @method :post 125 * @method :post
126 * @time :2024/4/29 17:20 126 * @time :2024/4/29 17:20
127 */ 127 */
128 - public function getHeadComHtml($condition,$source,$is_list,$is_custom){  
129 - $commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD); 128 + public function getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id){
  129 + $commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
130 $bTemplateComModel = new BTemplateCom(); 130 $bTemplateComModel = new BTemplateCom();
131 $condition['source'] = $commonHead; 131 $condition['source'] = $commonHead;
132 $condition['common_type'] = BTemplate::COMMON_HEAD; 132 $condition['common_type'] = BTemplate::COMMON_HEAD;
@@ -148,10 +148,10 @@ class BTemplateLogic extends BaseLogic @@ -148,10 +148,10 @@ class BTemplateLogic extends BaseLogic
148 * @method :post 148 * @method :post
149 * @time :2024/4/29 17:18 149 * @time :2024/4/29 17:18
150 */ 150 */
151 - public function getFooterComHtml($condition,$source,$is_list,$is_custom){ 151 + public function getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id){
152 $bTemplateComModel = new BTemplateCom(); 152 $bTemplateComModel = new BTemplateCom();
153 $condition['common_type'] = BTemplate::COMMON_FOOTER; 153 $condition['common_type'] = BTemplate::COMMON_FOOTER;
154 - $condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER); 154 + $condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER,$template_id);
155 $footerComInfo = $bTemplateComModel->read($condition); 155 $footerComInfo = $bTemplateComModel->read($condition);
156 if($footerComInfo === false){ 156 if($footerComInfo === false){
157 //取默认首页的 157 //取默认首页的
@@ -504,21 +504,20 @@ class BTemplateLogic extends BaseLogic @@ -504,21 +504,20 @@ class BTemplateLogic extends BaseLogic
504 public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){ 504 public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){
505 $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER]; 505 $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
506 $handleInfo = $this->handleCommonParam($html); 506 $handleInfo = $this->handleCommonParam($html);
507 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($handleInfo, true) . PHP_EOL, FILE_APPEND);  
508 $templateComModel = new BTemplateCom(); 507 $templateComModel = new BTemplateCom();
509 foreach ($typeArr as $type){ 508 foreach ($typeArr as $type){
510 if($type == BTemplate::COMMON_HEAD){ 509 if($type == BTemplate::COMMON_HEAD){
511 $param['html'] = $handleInfo['head_html']; 510 $param['html'] = $handleInfo['head_html'];
512 $param['html_style'] = $handleInfo['head_style']; 511 $param['html_style'] = $handleInfo['head_style'];
513 - $typeSource = $this->getType($source,$is_list,$is_custom,$type);//头部是否为独立头部 512 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
514 }elseif ($type == BTemplate::COMMON_FOOTER){ 513 }elseif ($type == BTemplate::COMMON_FOOTER){
515 $param['html'] = $handleInfo['footer_html']; 514 $param['html'] = $handleInfo['footer_html'];
516 $param['html_style'] = $handleInfo['footer_style']; 515 $param['html_style'] = $handleInfo['footer_style'];
517 - $typeSource = $this->getType($source,$is_list,$is_custom,$type); 516 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
518 }else{ 517 }else{
519 $param['html'] = $handleInfo['other']; 518 $param['html'] = $handleInfo['other'];
520 $param['html_style'] = null; 519 $param['html_style'] = null;
521 - $typeSource = $this->getType($source,$is_list,$is_custom); 520 + $typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
522 } 521 }
523 //查看当前数据是否还存在 522 //查看当前数据是否还存在
524 $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type]; 523 $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
@@ -573,10 +572,13 @@ class BTemplateLogic extends BaseLogic @@ -573,10 +572,13 @@ class BTemplateLogic extends BaseLogic
573 * @method :post 572 * @method :post
574 * @time :2023/10/21 17:29 573 * @time :2023/10/21 17:29
575 */ 574 */
576 - public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD){ 575 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  576 + if($template_id == 0){
  577 + return $this->success($source);
  578 + }
577 $type = BTemplate::SOURCE_COM;//公共头部底部 579 $type = BTemplate::SOURCE_COM;//公共头部底部
578 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 580 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
579 - if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部 581 + if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为公共头+底
580 return $this->success($type); 582 return $this->success($type);
581 } 583 }
582 //查看页面是否设置自定义头部底部 584 //查看页面是否设置自定义头部底部
@@ -592,7 +594,7 @@ class BTemplateLogic extends BaseLogic @@ -592,7 +594,7 @@ class BTemplateLogic extends BaseLogic
592 else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}} 594 else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
593 if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}} 595 if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
594 else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}} 596 else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
595 - if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}} 597 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::SOURCE_KEYWORD;}}
596 return $this->success($type); 598 return $this->success($type);
597 } 599 }
598 600
@@ -50,13 +50,81 @@ class CustomTemplateLogic extends BaseLogic @@ -50,13 +50,81 @@ class CustomTemplateLogic extends BaseLogic
50 $this->fail('当前数据不存在'); 50 $this->fail('当前数据不存在');
51 } 51 }
52 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){ 52 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
53 - $html = $this->getBodyHeaderFooter($info['html'],$info['html_style']); 53 + $html = $this->getTemplateComHtml($info['html'],$info['html_style']);
54 $info['html'] = $this->getHeadFooter($html); 54 $info['html'] = $this->getHeadFooter($html);
55 } 55 }
56 return $this->success($info); 56 return $this->success($info);
57 } 57 }
58 58
59 /** 59 /**
  60 + * @remark :非定制获取头部+底部
  61 + * @name :getTemplateComHtml
  62 + * @author :lyh
  63 + * @method :post
  64 + * @time :2024/4/29 16:53
  65 + */
  66 + public function getTemplateComHtml($html,$html_style){
  67 + $headComInfo = $this->getHeadComHtml(['common_type'=>BTemplate::COMMON_HEAD]);
  68 + $bTemplateComModel = new BTemplateCom();
  69 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  70 + $condition['source'] = $headComInfo['source'];
  71 + $otherInfo = $bTemplateComModel->read($condition);
  72 + if($otherInfo === false){
  73 + $this->fail('获取失败,请联系管理员');
  74 + }
  75 + $footerComInfo = $this->getFooterComHtml();
  76 + $commonInfo = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
  77 + 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
  78 + $html = $commonInfo['head_style'].$html_style.$commonInfo['footer_style'].$commonInfo['other']. $commonInfo['head_html'].$html.$commonInfo['footer_html'];
  79 + return $this->success($html);
  80 + }
  81 +
  82 + /**
  83 + * @remark :公共头部
  84 + * @name :HeadComHtml
  85 + * @author :lyh
  86 + * @method :post
  87 + * @time :2024/4/29 17:20
  88 + */
  89 + public function getHeadComHtml($condition){
  90 + $bTemplateComModel = new BTemplateCom();
  91 + $condition['source'] = $this->getType();
  92 + $condition['common_type'] = BTemplate::COMMON_HEAD;
  93 + $headComInfo = $bTemplateComModel->read($condition);
  94 + if($headComInfo === false){
  95 + //取默认公共的
  96 + $condition['source'] = BTemplate::SOURCE_COM;
  97 + $headComInfo = $bTemplateComModel->read($condition);
  98 + if($headComInfo === false){
  99 + $this->fail('获取失败,请联系管理员');
  100 + }
  101 + }
  102 + return $this->success($headComInfo);
  103 + }
  104 + /**
  105 + * @remark :公共底部
  106 + * @name :footerComHtml
  107 + * @author :lyh
  108 + * @method :post
  109 + * @time :2024/4/29 17:18
  110 + */
  111 + public function getFooterComHtml(){
  112 + $bTemplateComModel = new BTemplateCom();
  113 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  114 + $condition['source'] = $this->getType(BTemplate::COMMON_FOOTER);
  115 + $footerComInfo = $bTemplateComModel->read($condition);
  116 + if($footerComInfo === false){
  117 + //取默认首页的
  118 + $condition['source'] = BTemplate::SOURCE_COM;
  119 + $footerComInfo = $bTemplateComModel->read($condition);
  120 + if($footerComInfo === false){
  121 + $this->fail('获取失败,请联系管理员');
  122 + }
  123 + }
  124 + return $this->success($footerComInfo);
  125 + }
  126 +
  127 + /**
60 * @remark :保存自定义界面 128 * @remark :保存自定义界面
61 * @name :customTemplateSave 129 * @name :customTemplateSave
62 * @author :lyh 130 * @author :lyh
@@ -109,15 +177,16 @@ class CustomTemplateLogic extends BaseLogic @@ -109,15 +177,16 @@ class CustomTemplateLogic extends BaseLogic
109 if($bSettingInfo === false){ 177 if($bSettingInfo === false){
110 $this->fail('请先选择模版'); 178 $this->fail('请先选择模版');
111 } 179 }
112 - $this->saveCommonTemplate($html,$bSettingInfo['template_id']);  
113 - $this->param['html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');  
114 - $this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'); 180 + $handleInfo = $this->handleResultParam($html);
  181 + $this->saveTemplateCom($handleInfo,$bSettingInfo['template_id']);
  182 + $this->param['html'] = $handleInfo['main_html'];
  183 + $this->param['html_style'] = $handleInfo['main_style'];
115 } 184 }
116 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]); 185 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]);
117 if($rs === false){ 186 if($rs === false){
118 $this->fail('系统错误,请联系管理'); 187 $this->fail('系统错误,请联系管理');
119 } 188 }
120 - $this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']); 189 + $this->setTemplateLog($bSettingInfo['template_id'],$handleInfo,$this->param['id']);
121 //通知 190 //通知
122 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']); 191 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']);
123 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]); 192 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]);
@@ -132,6 +201,7 @@ class CustomTemplateLogic extends BaseLogic @@ -132,6 +201,7 @@ class CustomTemplateLogic extends BaseLogic
132 * @time :2023/8/23 11:16 201 * @time :2023/8/23 11:16
133 */ 202 */
134 public function setTemplateLog($template_id,$html,$source_id){ 203 public function setTemplateLog($template_id,$html,$source_id){
  204 + $handleInfo = $this->handleResultParam($html);
135 $data = [ 205 $data = [
136 'template_id'=>$template_id, 206 'template_id'=>$template_id,
137 'project_id'=>$this->user['project_id'], 207 'project_id'=>$this->user['project_id'],
@@ -139,49 +209,38 @@ class CustomTemplateLogic extends BaseLogic @@ -139,49 +209,38 @@ class CustomTemplateLogic extends BaseLogic
139 'text'=>$html, 209 'text'=>$html,
140 'source'=>9, 210 'source'=>9,
141 'source_id'=>$source_id, 211 'source_id'=>$source_id,
142 - 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),  
143 - 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),  
144 - 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),  
145 - 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),  
146 - 'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),  
147 - 'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'), 212 + 'head_html'=>$handleInfo['head_html'],
  213 + 'head_css'=>$handleInfo['head_style'],
  214 + 'footer_html'=>$handleInfo['footer_html'],
  215 + 'footer_css'=>$handleInfo['footer_style'],
  216 + 'main_html' => $handleInfo['main_html'],
  217 + 'main_css' => $handleInfo['main_style'],
  218 + 'other'=>$handleInfo['other']
148 ]; 219 ];
149 - $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));  
150 - $data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);  
151 $bTemplateLogModel = new BTemplateLog(); 220 $bTemplateLogModel = new BTemplateLog();
152 return $bTemplateLogModel->add($data); 221 return $bTemplateLogModel->add($data);
153 } 222 }
154 223
155 /** 224 /**
156 - * @remark :保存头部公共数据  
157 - * @name :saveCommonTemplate 225 + * @remark :截取数据返回
  226 + * @name :handleResultParam
158 * @author :lyh 227 * @author :lyh
159 * @method :post 228 * @method :post
160 - * @time :2023/10/13 14:27 229 + * @time :2024/5/6 14:14
161 */ 230 */
162 - public function saveCommonTemplate($html,$template_id){  
163 - $type = $this->getType();  
164 - $templateCommonModel = new BTemplateCommon();  
165 - $info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);  
166 - $data = [ 231 + public function handleResultParam($html){
  232 + $handleInfo = [
167 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'), 233 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
168 'head_style'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'), 234 'head_style'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
169 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'), 235 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
170 'footer_style'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'), 236 'footer_style'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  237 + 'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
  238 + 'main_style' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
171 ]; 239 ];
172 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 240 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
173 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 241 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
174 - if($info === false){  
175 - $data['template_id'] = $template_id;  
176 - $data['project_id'] = $this->user['project_id'];  
177 - $data['type'] = $type;  
178 - $templateCommonModel->add($data);  
179 - }else{  
180 - $templateCommonModel->edit($data,['id'=>$info['id']]);  
181 - }  
182 - //更新所有界面的other  
183 - $templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);  
184 - return $this->success(); 242 + $handleInfo['other'] = $other;
  243 + return $this->success($handleInfo);
185 } 244 }
186 245
187 /** 246 /**
@@ -191,10 +250,8 @@ class CustomTemplateLogic extends BaseLogic @@ -191,10 +250,8 @@ class CustomTemplateLogic extends BaseLogic
191 * @method :post 250 * @method :post
192 * @time :2024/4/29 10:32 251 * @time :2024/4/29 10:32
193 */ 252 */
194 - public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){ 253 + public function saveTemplateCom($handleInfo,$template_id){
195 $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER]; 254 $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
196 - $handleInfo = $this->handleCommonParam($html);  
197 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($handleInfo, true) . PHP_EOL, FILE_APPEND);  
198 $templateComModel = new BTemplateCom(); 255 $templateComModel = new BTemplateCom();
199 foreach ($typeArr as $type){ 256 foreach ($typeArr as $type){
200 if($type == BTemplate::COMMON_HEAD){ 257 if($type == BTemplate::COMMON_HEAD){
@@ -208,16 +265,20 @@ class CustomTemplateLogic extends BaseLogic @@ -208,16 +265,20 @@ class CustomTemplateLogic extends BaseLogic
208 }else{ 265 }else{
209 $param['html'] = $handleInfo['other']; 266 $param['html'] = $handleInfo['other'];
210 $param['html_style'] = null; 267 $param['html_style'] = null;
211 - $typeSource = $this->getType(); 268 + $type == BTemplate::COMMON_HEAD;
  269 + $typeSource = $this->getType($type);
212 } 270 }
213 //查看当前数据是否还存在 271 //查看当前数据是否还存在
214 - $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type]; 272 + $condition = ['template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];
215 $info = $templateComModel->read($condition); 273 $info = $templateComModel->read($condition);
216 if($info === false){ 274 if($info === false){
217 $data = array_merge($param,$condition); 275 $data = array_merge($param,$condition);
218 - $templateComModel->add($data); 276 + $rs = $templateComModel->add($data);
219 }else{ 277 }else{
220 - $templateComModel->edit($param,$condition); 278 + $rs = $templateComModel->edit($param,$condition);
  279 + }
  280 + if($rs === false){
  281 + $this->fail('保存错误,请联系管理员');
221 } 282 }
222 } 283 }
223 return $this->success(); 284 return $this->success();
@@ -233,17 +294,13 @@ class CustomTemplateLogic extends BaseLogic @@ -233,17 +294,13 @@ class CustomTemplateLogic extends BaseLogic
233 public function getType($CommonType = BTemplate::COMMON_HEAD){ 294 public function getType($CommonType = BTemplate::COMMON_HEAD){
234 $type = BTemplate::SOURCE_COM;//公共头部底部 295 $type = BTemplate::SOURCE_COM;//公共头部底部
235 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 296 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
236 - if($is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部 297 + if($is_head == BTemplate::IS_NO_HEADER){
237 return $this->success($type); 298 return $this->success($type);
238 } 299 }
239 //查看页面是否设置自定义头部底部 300 //查看页面是否设置自定义头部底部
240 $pageSettingModel = new PageSetting(); 301 $pageSettingModel = new PageSetting();
241 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]); 302 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
242 - if ($pageInfo !== false) {  
243 - if ($pageInfo['page_list'] != 0) {  
244 - $type = 9;  
245 - }  
246 - } 303 + if ($pageInfo !== false) {if ($pageInfo['page_list'] != 0) {$type = 9;}}
247 return $this->success($type); 304 return $this->success($type);
248 } 305 }
249 306
@@ -330,7 +387,7 @@ class CustomTemplateLogic extends BaseLogic @@ -330,7 +387,7 @@ class CustomTemplateLogic extends BaseLogic
330 $this->fail('请先设置模版'); 387 $this->fail('请先设置模版');
331 } 388 }
332 //获取type类型 389 //获取type类型
333 - $commonInfo = $this->getCommonPage($info['template_id']); 390 + $commonInfo = $this->getType();
334 $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other']. 391 $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].
335 $commonInfo['head_html'].$preg_html.$commonInfo['footer_html']; 392 $commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];
336 return $this->success($html); 393 return $this->success($html);
@@ -14,6 +14,7 @@ use App\Models\Project\PageSetting; @@ -14,6 +14,7 @@ use App\Models\Project\PageSetting;
14 use App\Models\RouteMap\RouteMap; 14 use App\Models\RouteMap\RouteMap;
15 use App\Models\Service\Service as ServiceSettingModel; 15 use App\Models\Service\Service as ServiceSettingModel;
16 use App\Models\Template\BTemplate; 16 use App\Models\Template\BTemplate;
  17 +use App\Models\Template\BTemplateCom;
17 use App\Models\Template\BTemplateCommon; 18 use App\Models\Template\BTemplateCommon;
18 use App\Models\Template\BTemplateMain; 19 use App\Models\Template\BTemplateMain;
19 use App\Models\Template\Setting; 20 use App\Models\Template\Setting;
@@ -51,14 +52,83 @@ class InitHtmlLogic extends BaseLogic @@ -51,14 +52,83 @@ class InitHtmlLogic extends BaseLogic
51 $data['id'] = $mainInfo['id']; 52 $data['id'] = $mainInfo['id'];
52 $data['updated_at'] = $mainInfo['updated_at']; 53 $data['updated_at'] = $mainInfo['updated_at'];
53 } 54 }
54 - $commonInfo = $this->getCommonHtml($this->param['type'],$is_list,$template_id,$is_custom); //获取头部  
55 - $html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html']; 55 + $commonInfo = $this->getTemplateComHtml($this->param['type'],$is_list,$is_custom,$template_id); //获取头部
  56 + $html = $commonInfo['head_style'].$main_style.$commonInfo['footer_style'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
56 $html = $this->getHeadFooter($html);//组装数据 57 $html = $this->getHeadFooter($html);//组装数据
57 $data['html'] = $html; 58 $data['html'] = $html;
58 return $this->success($data); 59 return $this->success($data);
59 } 60 }
60 61
61 /** 62 /**
  63 + * @remark :非定制获取头部+底部
  64 + * @name :getTemplateComHtml
  65 + * @author :lyh
  66 + * @method :post
  67 + * @time :2024/4/29 16:53
  68 + */
  69 + public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){
  70 + $condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id];
  71 + $headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id);
  72 + $bTemplateComModel = new BTemplateCom();
  73 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  74 + $condition['source'] = $headComInfo['source'];
  75 + $otherInfo = $bTemplateComModel->read($condition);
  76 + if($otherInfo === false){
  77 + $this->fail('获取失败,请联系管理员');
  78 + }
  79 + $footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id);
  80 + $data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
  81 + 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
  82 + return $this->success($data);
  83 + }
  84 +
  85 + /**
  86 + * @remark :公共头部
  87 + * @name :HeadComHtml
  88 + * @author :lyh
  89 + * @method :post
  90 + * @time :2024/4/29 17:20
  91 + */
  92 + public function getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id){
  93 + $commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
  94 + $bTemplateComModel = new BTemplateCom();
  95 + $condition['source'] = $commonHead;
  96 + $condition['common_type'] = BTemplate::COMMON_HEAD;
  97 + $headComInfo = $bTemplateComModel->read($condition);
  98 + if($headComInfo === false){
  99 + //取默认公共的
  100 + $condition['source'] = BTemplate::SOURCE_COM;
  101 + $headComInfo = $bTemplateComModel->read($condition);
  102 + if($headComInfo === false){
  103 + $this->fail('获取失败,请联系管理员');
  104 + }
  105 + }
  106 + return $this->success($headComInfo);
  107 + }
  108 + /**
  109 + * @remark :公共底部
  110 + * @name :footerComHtml
  111 + * @author :lyh
  112 + * @method :post
  113 + * @time :2024/4/29 17:18
  114 + */
  115 + public function getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id){
  116 + $bTemplateComModel = new BTemplateCom();
  117 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  118 + $condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER,$template_id);
  119 + $footerComInfo = $bTemplateComModel->read($condition);
  120 + if($footerComInfo === false){
  121 + //取默认首页的
  122 + $condition['source'] = BTemplate::SOURCE_COM;
  123 + $footerComInfo = $bTemplateComModel->read($condition);
  124 + if($footerComInfo === false){
  125 + $this->fail('获取失败,请联系管理员');
  126 + }
  127 + }
  128 + return $this->success($footerComInfo);
  129 + }
  130 +
  131 + /**
62 * @remark :拼接获取公共头部底部 132 * @remark :拼接获取公共头部底部
63 * @name :getHeadFooter 133 * @name :getHeadFooter
64 * @author :lyh 134 * @author :lyh
@@ -114,93 +184,80 @@ class InitHtmlLogic extends BaseLogic @@ -114,93 +184,80 @@ class InitHtmlLogic extends BaseLogic
114 ]; 184 ];
115 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]); 185 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
116 } 186 }
117 - $this->saveCommonHtml($this->param['html'],$this->param['type'],$is_list,$template_id,$is_custom); 187 + $this->saveTemplateCom($this->param['html'],$template_id,$this->param['type'],$is_list,$is_custom);
118 $route = RouteMap::getRoute('all',0,$this->user['project_id']); 188 $route = RouteMap::getRoute('all',0,$this->user['project_id']);
119 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]); 189 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]);
120 return $this->success(); 190 return $this->success();
121 } 191 }
122 192
123 /** 193 /**
124 - * @remark :保存公共头部底部  
125 - * @name :saveCommonHtml 194 + * @remark :保存公共部分(头部。底部。连接部分)
  195 + * @name :saveTemplateCom
126 * @author :lyh 196 * @author :lyh
127 * @method :post 197 * @method :post
128 - * @time :2023/12/13 17:05 198 + * @time :2024/4/29 10:32
129 */ 199 */
130 - public function saveCommonHtml($html,$source,$is_list,$template_id,$is_custom){  
131 - $type = $this->getType($source,$is_list,$is_custom);//获取头部类型1-9(首页到自定义页面)  
132 - $templateCommonModel = new BTemplateCommon();  
133 - $commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);//查看当前头部是否存在 200 + public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){
  201 + $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
134 $handleInfo = $this->handleCommonParam($html); 202 $handleInfo = $this->handleCommonParam($html);
135 - if($commonInfo === false){  
136 - $data = [  
137 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
138 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
139 - 'type'=>$type,'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],  
140 - ];  
141 - $templateCommonModel->add($data); 203 + $templateComModel = new BTemplateCom();
  204 + foreach ($typeArr as $type){
  205 + if($type == BTemplate::COMMON_HEAD){
  206 + $param['html'] = $handleInfo['head_html'];
  207 + $param['html_style'] = $handleInfo['head_style'];
  208 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
  209 + }elseif ($type == BTemplate::COMMON_FOOTER){
  210 + $param['html'] = $handleInfo['footer_html'];
  211 + $param['html_style'] = $handleInfo['footer_style'];
  212 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
142 }else{ 213 }else{
143 - $data = [  
144 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
145 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
146 - ];  
147 - $templateCommonModel->edit($data,['id'=>$commonInfo['id']]); 214 + $param['html'] = $handleInfo['other'];
  215 + $param['html_style'] = null;
  216 + $typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
148 } 217 }
149 - //更新所有界面的other  
150 - return $templateCommonModel->edit(['other'=>$handleInfo['other']],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]); 218 + //查看当前数据是否还存在
  219 + $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
  220 + $info = $templateComModel->read($condition);
  221 + if($info === false){
  222 + $data = array_merge($param,$condition);
  223 + $templateComModel->add($data);
  224 + }else{
  225 + $templateComModel->edit($param,$condition);
151 } 226 }
152 -  
153 - /**  
154 - * @remark :根据类型获取公共头和底  
155 - * @name :getCommonPage  
156 - * @author :lyh  
157 - * @method :post  
158 - * @time :2023/10/21 16:55  
159 - */  
160 - public function getCommonHtml($source,$is_list,$template_id,$is_custom){  
161 - $type = $this->getType($source,$is_list,$is_custom);  
162 - $data = [  
163 - 'template_id' => $template_id,  
164 - 'project_id' => $this->user['project_id'],  
165 - 'type'=>$type  
166 - ];  
167 - $commonTemplateModel = new BTemplateCommon();  
168 - $commonInfo = $commonTemplateModel->read($data);  
169 - if($commonInfo === false){  
170 - $data['type'] = BTemplate::SOURCE_HOME;  
171 - $commonInfo = $commonTemplateModel->read($data);  
172 } 227 }
173 - return $this->success($commonInfo); 228 + return $this->success();
174 } 229 }
175 230
176 /** 231 /**
177 - * @remark :保存时获取获取设置的类型 232 + * @remark :(非定制)保存时获取获取设置的类型
178 * @name :getType 233 * @name :getType
179 * @author :lyh 234 * @author :lyh
180 * @method :post 235 * @method :post
181 * @time :2023/10/21 17:29 236 * @time :2023/10/21 17:29
182 */ 237 */
183 - public function getType($source,$is_list,$is_custom = 0){  
184 - $type = BTemplate::SOURCE_HOME;//首页公共头部底部 238 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  239 + if($template_id == 0){
  240 + return $this->success($source);
  241 + }
  242 + $type = BTemplate::SOURCE_COM;//公共头部底部
185 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 243 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
186 - if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部 244 + if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
187 return $this->success($type); 245 return $this->success($type);
188 } 246 }
189 //查看页面是否设置自定义头部底部 247 //查看页面是否设置自定义头部底部
190 - if($is_head != BTemplate::IS_NO_HEADER) {  
191 $pageSettingModel = new PageSetting(); 248 $pageSettingModel = new PageSetting();
192 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]); 249 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
193 if ($pageInfo === false) { 250 if ($pageInfo === false) {
194 return $this->success($type); 251 return $this->success($type);
195 } 252 }
196 - if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}  
197 - else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}  
198 - if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}  
199 - else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}  
200 - if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}  
201 - else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}  
202 - if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}  
203 - } 253 + if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
  254 + if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
  255 + else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
  256 + if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
  257 + else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
  258 + if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
  259 + else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
  260 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::SOURCE_KEYWORD;}}
204 return $this->success($type); 261 return $this->success($type);
205 } 262 }
206 263
@@ -215,8 +272,8 @@ class InitHtmlLogic extends BaseLogic @@ -215,8 +272,8 @@ class InitHtmlLogic extends BaseLogic
215 //字符串截取 272 //字符串截取
216 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'); 273 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
217 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'); 274 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
218 - $param['head_css'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');  
219 - $param['footer_css'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'); 275 + $param['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
  276 + $param['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
220 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 277 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
221 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 278 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
222 return $this->success($param); 279 return $this->success($param);
@@ -269,21 +326,39 @@ class InitHtmlLogic extends BaseLogic @@ -269,21 +326,39 @@ class InitHtmlLogic extends BaseLogic
269 if($info === false){ 326 if($info === false){
270 $html = ''; 327 $html = '';
271 }else{ 328 }else{
272 - //扩展模块获取头部  
273 - if($is_custom == BTemplate::IS_CUSTOM){  
274 - $type = $this->param['type']; 329 + $commonInfo = $this->getCustomizeTemplateComHtml($this->param['type'],$is_custom,$is_list);
  330 + $html = $this->handleAllHtml($commonInfo,$info['main_html']);
  331 + }
  332 + //更新头部底部
  333 + return $this->success(['html'=>$html]);
  334 + }
  335 +
  336 + /**
  337 + * @remark :定制获取头部底部
  338 + * @name :getCustomizedCommonHtml
  339 + * @author :lyh
  340 + * @method :post
  341 + * @time :2023/12/29 13:13
  342 + */
  343 + public function getCustomizeTemplateComHtml($type,$is_custom,$is_list,$template_id = 0){
  344 + $data = ['head_html'=>'','head_style'=>'','footer_html'=>'','footer_style'=>'','other'=>''];
  345 + $param = ['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list];
  346 + $commonTemplateModel = new BTemplateCom();
  347 + $commonList = $commonTemplateModel->list($param);
  348 + if(!empty($commonList)){
  349 + foreach ($commonList as $v){
  350 + if($v['common_type'] == BTemplate::COMMON_HEAD){
  351 + $data['head_html'] = $v['html'];
  352 + $data['head_style'] = $v['html_style'];
  353 + }elseif ($v['common_type'] == BTemplate::COMMON_FOOTER){
  354 + $data['footer_html'] = $v['html'];
  355 + $data['footer_style'] = $v['html_style'];
275 }else{ 356 }else{
276 - $type = $this->getCustomizedType($this->param['type'],$is_list); 357 + $data['other'] = $v['html'];
277 } 358 }
278 - $commonTemplateModel = new BTemplateCommon();  
279 - $commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list]);  
280 - if($commonInfo !== false){  
281 - $info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);  
282 } 359 }
283 - $html = $info['main_html'];  
284 } 360 }
285 - //更新头部底部  
286 - return $this->success(['html'=>$html]); 361 + return $this->success($data);
287 } 362 }
288 363
289 /** 364 /**
@@ -329,7 +404,7 @@ class InitHtmlLogic extends BaseLogic @@ -329,7 +404,7 @@ class InitHtmlLogic extends BaseLogic
329 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 404 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
330 } 405 }
331 //更新头部底部 406 //更新头部底部
332 - $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list,$is_custom); 407 + $this->saveTemplateCom($this->param['html'],0,$this->param['type'],$is_list,$is_custom);
333 }catch (\Exception $exception){ 408 }catch (\Exception $exception){
334 $this->fail('保存失败,请联系开发人员'); 409 $this->fail('保存失败,请联系开发人员');
335 } 410 }
@@ -337,73 +412,6 @@ class InitHtmlLogic extends BaseLogic @@ -337,73 +412,6 @@ class InitHtmlLogic extends BaseLogic
337 } 412 }
338 413
339 /** 414 /**
340 - * @remark :定制代码更新头部信息  
341 - * @name :saveCustomizeCommon  
342 - * @author :lyh  
343 - * @method :post  
344 - * @time :2024/1/6 10:29  
345 - */  
346 - public function saveCustomizeCommon($html,$source,$is_list,$is_custom){  
347 - if($is_custom == BTemplate::IS_CUSTOM){  
348 - $type = $source;  
349 - }else{  
350 - $type = $this->getCustomizedType($source,$is_list);  
351 - }  
352 - $templateCommonModel = new BTemplateCommon();  
353 - $commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list]);//查看当前头部是否存在  
354 - $handleInfo = $this->handleCommonParam($html);  
355 - if($commonInfo === false){  
356 - $data = [  
357 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],  
358 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
359 - 'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],  
360 - 'is_custom'=>$is_custom,'is_list'=>$is_list  
361 - ];  
362 - $templateCommonModel->add($data);  
363 - }else{  
364 - $data = [  
365 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],  
366 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
367 - ];  
368 - $templateCommonModel->edit($data,['id'=>$commonInfo['id']]);  
369 - }  
370 - return $this->success();  
371 - }  
372 -  
373 - /**  
374 - * @remark :定制页面头部类型---根据source获取type类型  
375 - * @name :getType  
376 - * @author :lyh  
377 - * @method :post  
378 - * @time :2023/11/16 11:20  
379 - */  
380 - public function getCustomizedType($source,$is_list){  
381 - $type = BTemplate::TYPE_HOME;  
382 - if($source == BTemplate::SOURCE_PRODUCT){  
383 - if($is_list == BTemplate::IS_LIST){  
384 - $type = BTemplate::TYPE_PRODUCT_LIST;  
385 - }else{  
386 - $type = BTemplate::TYPE_PRODUCT_DETAIL;  
387 - }  
388 - }  
389 - if($source == BTemplate::SOURCE_BLOG){  
390 - if($is_list == BTemplate::IS_LIST){  
391 - $type = BTemplate::TYPE_BLOG_LIST;  
392 - }else{  
393 - $type = BTemplate::TYPE_BLOG_DETAIL;  
394 - }  
395 - }  
396 - if($source == BTemplate::SOURCE_NEWS){  
397 - if($is_list == BTemplate::IS_LIST){  
398 - $type = BTemplate::TYPE_NEWS_LIST;  
399 - }else{  
400 - $type = BTemplate::TYPE_NEWS_DETAIL;  
401 - }  
402 - }  
403 - return $type;  
404 - }  
405 -  
406 - /**  
407 * @remark :前端获取设置模块(侧边栏) 415 * @remark :前端获取设置模块(侧边栏)
408 * @name :getInitModuleMain 416 * @name :getInitModuleMain
409 * @author :lyh 417 * @author :lyh