作者 lyh

gx

@@ -13,7 +13,6 @@ use App\Http\Logic\Bside\BaseLogic; @@ -13,7 +13,6 @@ use App\Http\Logic\Bside\BaseLogic;
13 use App\Models\Project\PageSetting; 13 use App\Models\Project\PageSetting;
14 use App\Models\Service\Service as ServiceSettingModel; 14 use App\Models\Service\Service as ServiceSettingModel;
15 use App\Models\Template\BTemplate; 15 use App\Models\Template\BTemplate;
16 -use App\Models\Template\BTemplateCom;  
17 use App\Models\Template\BTemplateCommon; 16 use App\Models\Template\BTemplateCommon;
18 use App\Models\Template\BTemplateLog; 17 use App\Models\Template\BTemplateLog;
19 use App\Models\Template\Setting; 18 use App\Models\Template\Setting;
@@ -65,14 +64,13 @@ class BTemplateLogLogic extends BaseLogic @@ -65,14 +64,13 @@ class BTemplateLogLogic extends BaseLogic
65 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']]; 64 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
66 //TODO::还原头部+底部 65 //TODO::还原头部+底部
67 $bTemplateModel->edit(['html'=>$info['text']],$condition); 66 $bTemplateModel->edit(['html'=>$info['text']],$condition);
  67 + $commonData = [
  68 + 'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'],
  69 + 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
  70 + ];
  71 + $type = $this->getCustomizedType($info['source'],$info['is_list']);
68 $commonTemplateModel = new BTemplateCommon(); 72 $commonTemplateModel = new BTemplateCommon();
69 - //还原头部  
70 - $condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],  
71 - 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom'],'project_id'=>$this->user['project_id']];  
72 - $condition['common_type'] = BTemplate::COMMON_HEAD;  
73 - $commonTemplateModel->edit(['head'=>$info['head_html'], 'head_style'=>$info['head_css']],$condition);  
74 - $condition['common_type'] = BTemplate::COMMON_FOOTER;  
75 - $commonTemplateModel->edit(['footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']],$condition); 73 + $commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
76 return $this->success(); 74 return $this->success();
77 } 75 }
78 76
@@ -101,9 +99,18 @@ class BTemplateLogLogic extends BaseLogic @@ -101,9 +99,18 @@ class BTemplateLogLogic extends BaseLogic
101 $bTemplateModel->edit($data,$condition); 99 $bTemplateModel->edit($data,$condition);
102 //还原头部+底部 100 //还原头部+底部
103 $commonData = [ 101 $commonData = [
104 - 'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_style'=>$info['footer_css'],'other'=>$info['other'] 102 + 'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
105 ]; 103 ];
106 - $this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']); 104 + $commonTemplateModel = new BTemplateCommon();
  105 + $type = $this->getType($info['source'],$info['is_list'],$info['is_custom']);
  106 + $commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
  107 + if(!empty($info['other'])){
  108 + $commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]);
  109 + }else{
  110 + $footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s'));
  111 + $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
  112 + $commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$type]);
  113 + }
107 }catch (\Exception $e){ 114 }catch (\Exception $e){
108 $this->fail('系统错误,请联系管理员'); 115 $this->fail('系统错误,请联系管理员');
109 } 116 }
@@ -111,40 +118,36 @@ class BTemplateLogLogic extends BaseLogic @@ -111,40 +118,36 @@ class BTemplateLogLogic extends BaseLogic
111 } 118 }
112 119
113 /** 120 /**
114 - * @remark :保存公共部分(头部。底部。连接部分)  
115 - * @name :saveTemplateCom 121 + * @remark :定制页面头部类型---根据source获取type类型
  122 + * @name :getType
116 * @author :lyh 123 * @author :lyh
117 * @method :post 124 * @method :post
118 - * @time :2024/4/29 10:32 125 + * @time :2023/11/16 11:20
119 */ 126 */
120 - public function saveTemplateCom($handleInfo,$template_id,$source,$is_list,$is_custom){  
121 - $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];  
122 - $templateComModel = new BTemplateCom();  
123 - foreach ($typeArr as $type){  
124 - if($type == BTemplate::COMMON_HEAD){  
125 - $param['html'] = $handleInfo['head_html'];  
126 - $param['html_style'] = $handleInfo['head_style'];  
127 - $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部  
128 - }elseif ($type == BTemplate::COMMON_FOOTER){  
129 - $param['html'] = $handleInfo['footer_html'];  
130 - $param['html_style'] = $handleInfo['footer_style'];  
131 - $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id); 127 + public function getCustomizedType($source,$is_list){
  128 + $type = BTemplate::TYPE_HOME;
  129 + if($source == BTemplate::SOURCE_PRODUCT){
  130 + if($is_list == BTemplate::IS_LIST){
  131 + $type = BTemplate::TYPE_PRODUCT_LIST;
132 }else{ 132 }else{
133 - $param['html'] = $handleInfo['other'];  
134 - $param['html_style'] = null;  
135 - $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id); 133 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
136 } 134 }
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];  
139 - $info = $templateComModel->read($condition);  
140 - if($info === false){  
141 - $data = array_merge($param,$condition);  
142 - $templateComModel->add($data); 135 + }
  136 + if($source == BTemplate::SOURCE_BLOG){
  137 + if($is_list == BTemplate::IS_LIST){
  138 + $type = BTemplate::TYPE_BLOG_LIST;
143 }else{ 139 }else{
144 - $templateComModel->edit($param,$condition); 140 + $type = BTemplate::TYPE_BLOG_DETAIL;
145 } 141 }
146 } 142 }
147 - return $this->success(); 143 + if($source == BTemplate::SOURCE_NEWS){
  144 + if($is_list == BTemplate::IS_LIST){
  145 + $type = BTemplate::TYPE_NEWS_LIST;
  146 + }else{
  147 + $type = BTemplate::TYPE_NEWS_DETAIL;
  148 + }
  149 + }
  150 + return $type;
148 } 151 }
149 152
150 /** 153 /**
@@ -154,30 +157,27 @@ class BTemplateLogLogic extends BaseLogic @@ -154,30 +157,27 @@ class BTemplateLogLogic extends BaseLogic
154 * @method :post 157 * @method :post
155 * @time :2023/10/21 17:29 158 * @time :2023/10/21 17:29
156 */ 159 */
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 - }  
162 - $type = BTemplate::SOURCE_COM;//公共头部底部 160 + public function getType($source,$is_list,$is_custom = 0){
  161 + $type = BTemplate::SOURCE_HOME;//首页公共头部底部
163 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 162 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
164 - if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部 163 + if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
165 return $this->success($type); 164 return $this->success($type);
166 } 165 }
167 //查看页面是否设置自定义头部底部 166 //查看页面是否设置自定义头部底部
168 - $pageSettingModel = new PageSetting();  
169 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);  
170 - if ($pageInfo === false) {  
171 - return $this->success($type); 167 + if($is_head != BTemplate::IS_NO_HEADER) {
  168 + $pageSettingModel = new PageSetting();
  169 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
  170 + if ($pageInfo === false) {
  171 + return $this->success($type);
  172 + }
  173 + if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
  174 + else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
  175 + if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
  176 + else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
  177 + if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
  178 + else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
  179 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
172 } 180 }
173 - if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}  
174 - if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}  
175 - else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}  
176 - if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}  
177 - else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}  
178 - if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}  
179 - else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}  
180 - if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}  
181 return $this->success($type); 181 return $this->success($type);
182 } 182 }
183 183
@@ -7,7 +7,6 @@ use App\Models\Project\PageSetting; @@ -7,7 +7,6 @@ use App\Models\Project\PageSetting;
7 use App\Models\RouteMap\RouteMap; 7 use App\Models\RouteMap\RouteMap;
8 use App\Models\Service\Service as ServiceSettingModel; 8 use App\Models\Service\Service as ServiceSettingModel;
9 use App\Models\Template\BCustomTemplate; 9 use App\Models\Template\BCustomTemplate;
10 -use App\Models\Template\BTemplateCom;  
11 use App\Models\Template\BTemplateCommon; 10 use App\Models\Template\BTemplateCommon;
12 use App\Models\Template\BTemplateLog; 11 use App\Models\Template\BTemplateLog;
13 use App\Models\Template\Setting; 12 use App\Models\Template\Setting;
@@ -50,81 +49,13 @@ class CustomTemplateLogic extends BaseLogic @@ -50,81 +49,13 @@ class CustomTemplateLogic extends BaseLogic
50 $this->fail('当前数据不存在'); 49 $this->fail('当前数据不存在');
51 } 50 }
52 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){ 51 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
53 - $html = $this->getTemplateComHtml($info['html'],$info['html_style']); 52 + $html = $this->getBodyHeaderFooter($info['html'],$info['html_style']);
54 $info['html'] = $this->getHeadFooter($html); 53 $info['html'] = $this->getHeadFooter($html);
55 } 54 }
56 return $this->success($info); 55 return $this->success($info);
57 } 56 }
58 57
59 /** 58 /**
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 - /**  
128 * @remark :保存自定义界面 59 * @remark :保存自定义界面
129 * @name :customTemplateSave 60 * @name :customTemplateSave
130 * @author :lyh 61 * @author :lyh
@@ -177,16 +108,15 @@ class CustomTemplateLogic extends BaseLogic @@ -177,16 +108,15 @@ class CustomTemplateLogic extends BaseLogic
177 if($bSettingInfo === false){ 108 if($bSettingInfo === false){
178 $this->fail('请先选择模版'); 109 $this->fail('请先选择模版');
179 } 110 }
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']; 111 + $this->saveCommonTemplate($html,$bSettingInfo['template_id']);
  112 + $this->param['html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
  113 + $this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
184 } 114 }
185 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]); 115 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]);
186 if($rs === false){ 116 if($rs === false){
187 $this->fail('系统错误,请联系管理'); 117 $this->fail('系统错误,请联系管理');
188 } 118 }
189 - $this->setTemplateLog($bSettingInfo['template_id'],$handleInfo,$this->param['id']); 119 + $this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']);
190 //通知 120 //通知
191 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']); 121 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']);
192 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]); 122 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]);
@@ -201,7 +131,6 @@ class CustomTemplateLogic extends BaseLogic @@ -201,7 +131,6 @@ class CustomTemplateLogic extends BaseLogic
201 * @time :2023/8/23 11:16 131 * @time :2023/8/23 11:16
202 */ 132 */
203 public function setTemplateLog($template_id,$html,$source_id){ 133 public function setTemplateLog($template_id,$html,$source_id){
204 - $handleInfo = $this->handleResultParam($html);  
205 $data = [ 134 $data = [
206 'template_id'=>$template_id, 135 'template_id'=>$template_id,
207 'project_id'=>$this->user['project_id'], 136 'project_id'=>$this->user['project_id'],
@@ -209,99 +138,71 @@ class CustomTemplateLogic extends BaseLogic @@ -209,99 +138,71 @@ class CustomTemplateLogic extends BaseLogic
209 'text'=>$html, 138 'text'=>$html,
210 'source'=>9, 139 'source'=>9,
211 'source_id'=>$source_id, 140 'source_id'=>$source_id,
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'] 141 + 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
  142 + 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  143 + 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  144 + 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  145 + 'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
  146 + 'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
219 ]; 147 ];
  148 + $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
  149 + $data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
220 $bTemplateLogModel = new BTemplateLog(); 150 $bTemplateLogModel = new BTemplateLog();
221 return $bTemplateLogModel->add($data); 151 return $bTemplateLogModel->add($data);
222 } 152 }
223 153
224 /** 154 /**
225 - * @remark :截取数据返回  
226 - * @name :handleResultParam 155 + * @remark :保存头部公共数据
  156 + * @name :saveCommonTemplate
227 * @author :lyh 157 * @author :lyh
228 * @method :post 158 * @method :post
229 - * @time :2024/5/6 14:14 159 + * @time :2023/10/13 14:27
230 */ 160 */
231 - public function handleResultParam($html){  
232 - $handleInfo = [ 161 + public function saveCommonTemplate($html,$template_id){
  162 + $type = $this->getType();
  163 + $templateCommonModel = new BTemplateCommon();
  164 + $info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);
  165 + $data = [
233 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'), 166 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
234 - 'head_style'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'), 167 + 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
235 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'), 168 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/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'), 169 + 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
239 ]; 170 ];
240 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 171 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
241 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 172 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
242 - $handleInfo['other'] = $other;  
243 - return $this->success($handleInfo);  
244 - }  
245 -  
246 - /**  
247 - * @remark :保存公共部分(头部。底部。连接部分)  
248 - * @name :saveTemplateCom  
249 - * @author :lyh  
250 - * @method :post  
251 - * @time :2024/4/29 10:32  
252 - */  
253 - public function saveTemplateCom($handleInfo,$template_id){  
254 - $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];  
255 - $templateComModel = new BTemplateCom();  
256 - foreach ($typeArr as $type){  
257 - if($type == BTemplate::COMMON_HEAD){  
258 - $param['html'] = $handleInfo['head_html'];  
259 - $param['html_style'] = $handleInfo['head_style'];  
260 - $typeSource = $this->getType($type);//头部是否为独立头部  
261 - }elseif ($type == BTemplate::COMMON_FOOTER){  
262 - $param['html'] = $handleInfo['footer_html'];  
263 - $param['html_style'] = $handleInfo['footer_style'];  
264 - $typeSource = $this->getType($type);  
265 - }else{  
266 - $param['html'] = $handleInfo['other'];  
267 - $param['html_style'] = null;  
268 - $type == BTemplate::COMMON_HEAD;  
269 - $typeSource = $this->getType($type);  
270 - }  
271 - //查看当前数据是否还存在  
272 - $condition = ['template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];  
273 - $info = $templateComModel->read($condition);  
274 - if($info === false){  
275 - $data = array_merge($param,$condition);  
276 - $rs = $templateComModel->add($data);  
277 - }else{  
278 - $rs = $templateComModel->edit($param,$condition);  
279 - }  
280 - if($rs === false){  
281 - $this->fail('保存错误,请联系管理员');  
282 - } 173 + if($info === false){
  174 + $data['template_id'] = $template_id;
  175 + $data['project_id'] = $this->user['project_id'];
  176 + $data['type'] = $type;
  177 + $templateCommonModel->add($data);
  178 + }else{
  179 + $templateCommonModel->edit($data,['id'=>$info['id']]);
283 } 180 }
  181 + //更新所有界面的other
  182 + $templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);
284 return $this->success(); 183 return $this->success();
285 } 184 }
286 185
287 /** 186 /**
288 - * @remark :(非定制)保存时获取获取设置的类型 187 + * @remark :获取设置的类型
289 * @name :getType 188 * @name :getType
290 * @author :lyh 189 * @author :lyh
291 * @method :post 190 * @method :post
292 * @time :2023/10/21 17:29 191 * @time :2023/10/21 17:29
293 */ 192 */
294 - public function getType($CommonType = BTemplate::COMMON_HEAD){  
295 - $type = BTemplate::SOURCE_COM;//公共头部底部  
296 - $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;  
297 - if($is_head == BTemplate::IS_NO_HEADER){  
298 - return $this->success($type);  
299 - } 193 + public function getType(){
  194 + $type = 1;//首页公共头部底部
300 //查看页面是否设置自定义头部底部 195 //查看页面是否设置自定义头部底部
301 - $pageSettingModel = new PageSetting();  
302 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);  
303 - if ($pageInfo !== false) {if ($pageInfo['page_list'] != 0) {$type = 9;}}  
304 - return $this->success($type); 196 + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
  197 + $pageSettingModel = new PageSetting();
  198 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
  199 + if ($pageInfo !== false) {
  200 + if ($pageInfo['page_list'] != 0) {
  201 + $type = 9;
  202 + }
  203 + }
  204 + }
  205 + return $type;
305 } 206 }
306 207
307 /** 208 /**
@@ -387,7 +288,7 @@ class CustomTemplateLogic extends BaseLogic @@ -387,7 +288,7 @@ class CustomTemplateLogic extends BaseLogic
387 $this->fail('请先设置模版'); 288 $this->fail('请先设置模版');
388 } 289 }
389 //获取type类型 290 //获取type类型
390 - $commonInfo = $this->getType(); 291 + $commonInfo = $this->getCommonPage($info['template_id']);
391 $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other']. 292 $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].
392 $commonInfo['head_html'].$preg_html.$commonInfo['footer_html']; 293 $commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];
393 return $this->success($html); 294 return $this->success($html);
@@ -494,44 +395,7 @@ class CustomTemplateLogic extends BaseLogic @@ -494,44 +395,7 @@ class CustomTemplateLogic extends BaseLogic
494 }else{ 395 }else{
495 $this->model->edit(['html'=>$logInfo['text']],['id'=>$logInfo['source_id']]); 396 $this->model->edit(['html'=>$logInfo['text']],['id'=>$logInfo['source_id']]);
496 } 397 }
497 - return $this->success();  
498 - }  
499 -  
500 - /**  
501 - * @remark :复制单页面  
502 - * @name :copyCustomTemplateInfo  
503 - * @author :lyh  
504 - * @method :post  
505 - * @time :2024/4/28 16:16  
506 - */  
507 - public function copyCustomTemplateInfo(){  
508 - $info = $this->model->read(['id'=>$this->param['id']]);  
509 - $param = $this->setCustomTemplateParams($info);  
510 - $save_id = $this->model->insertGetId($param);  
511 - $route = RouteMap::setRoute($param['url'], RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);  
512 - $this->model->edit(['route'=>$route],['id'=>$save_id]);  
513 - return $this->success(['id'=>$save_id]);  
514 - }  
515 398
516 - /**  
517 - * @remark :组装数据  
518 - * @name :setCustomTemplateParams  
519 - * @author :lyh  
520 - * @method :post  
521 - * @time :2024/4/28 16:18  
522 - */  
523 - public function setCustomTemplateParams($info){  
524 - return [  
525 - 'name'=>$info['name'].'-copy',  
526 - 'status'=>$info['status'],  
527 - 'url'=>$info['url'],  
528 - 'html'=>$info['html'],  
529 - 'html_style'=>$info['html_style'],  
530 - 'project_id'=>$info['project_id'],  
531 - 'section_list_id'=>$info['section_list_id'],  
532 - 'is_visualization'=>$info['is_visualization'],  
533 - 'created_at'=>date('Y-m-d H:i:s'),  
534 - 'updated_at'=>date('Y-m-d H:i:s'),  
535 - ]; 399 + return $this->success();
536 } 400 }
537 } 401 }
@@ -14,7 +14,6 @@ use App\Models\Project\PageSetting; @@ -14,7 +14,6 @@ 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;  
18 use App\Models\Template\BTemplateCommon; 17 use App\Models\Template\BTemplateCommon;
19 use App\Models\Template\BTemplateMain; 18 use App\Models\Template\BTemplateMain;
20 use App\Models\Template\Setting; 19 use App\Models\Template\Setting;
@@ -52,83 +51,14 @@ class InitHtmlLogic extends BaseLogic @@ -52,83 +51,14 @@ class InitHtmlLogic extends BaseLogic
52 $data['id'] = $mainInfo['id']; 51 $data['id'] = $mainInfo['id'];
53 $data['updated_at'] = $mainInfo['updated_at']; 52 $data['updated_at'] = $mainInfo['updated_at'];
54 } 53 }
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']; 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'];
57 $html = $this->getHeadFooter($html);//组装数据 56 $html = $this->getHeadFooter($html);//组装数据
58 $data['html'] = $html; 57 $data['html'] = $html;
59 return $this->success($data); 58 return $this->success($data);
60 } 59 }
61 60
62 /** 61 /**
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 - /**  
132 * @remark :拼接获取公共头部底部 62 * @remark :拼接获取公共头部底部
133 * @name :getHeadFooter 63 * @name :getHeadFooter
134 * @author :lyh 64 * @author :lyh
@@ -184,80 +114,93 @@ class InitHtmlLogic extends BaseLogic @@ -184,80 +114,93 @@ class InitHtmlLogic extends BaseLogic
184 ]; 114 ];
185 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]); 115 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
186 } 116 }
187 - $this->saveTemplateCom($this->param['html'],$template_id,$this->param['type'],$is_list,$is_custom); 117 + $this->saveCommonHtml($this->param['html'],$this->param['type'],$is_list,$template_id,$is_custom);
188 $route = RouteMap::getRoute('all',0,$this->user['project_id']); 118 $route = RouteMap::getRoute('all',0,$this->user['project_id']);
189 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]); 119 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]);
190 return $this->success(); 120 return $this->success();
191 } 121 }
192 122
193 /** 123 /**
194 - * @remark :保存公共部分(头部。底部。连接部分)  
195 - * @name :saveTemplateCom 124 + * @remark :保存公共头部底部
  125 + * @name :saveCommonHtml
196 * @author :lyh 126 * @author :lyh
197 * @method :post 127 * @method :post
198 - * @time :2024/4/29 10:32 128 + * @time :2023/12/13 17:05
199 */ 129 */
200 - public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){  
201 - $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER]; 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]);//查看当前头部是否存在
202 $handleInfo = $this->handleCommonParam($html); 134 $handleInfo = $this->handleCommonParam($html);
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);  
213 - }else{  
214 - $param['html'] = $handleInfo['other'];  
215 - $param['html_style'] = null;  
216 - $typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);  
217 - }  
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);  
226 - } 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);
  142 + }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']]);
227 } 148 }
228 - return $this->success(); 149 + //更新所有界面的other
  150 + return $templateCommonModel->edit(['other'=>$handleInfo['other']],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
229 } 151 }
230 152
231 /** 153 /**
232 - * @remark :(非定制)保存时获取获取设置的类型 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 + }
  173 + return $this->success($commonInfo);
  174 + }
  175 +
  176 + /**
  177 + * @remark :保存时获取获取设置的类型
233 * @name :getType 178 * @name :getType
234 * @author :lyh 179 * @author :lyh
235 * @method :post 180 * @method :post
236 * @time :2023/10/21 17:29 181 * @time :2023/10/21 17:29
237 */ 182 */
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;//公共头部底部 183 + public function getType($source,$is_list,$is_custom = 0){
  184 + $type = BTemplate::SOURCE_HOME;//首页公共头部底部
243 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 185 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
244 - if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部 186 + if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
245 return $this->success($type); 187 return $this->success($type);
246 } 188 }
247 //查看页面是否设置自定义头部底部 189 //查看页面是否设置自定义头部底部
248 - $pageSettingModel = new PageSetting();  
249 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);  
250 - if ($pageInfo === false) {  
251 - return $this->success($type); 190 + if($is_head != BTemplate::IS_NO_HEADER) {
  191 + $pageSettingModel = new PageSetting();
  192 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
  193 + if ($pageInfo === false) {
  194 + return $this->success($type);
  195 + }
  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;}}
252 } 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;}}  
261 return $this->success($type); 204 return $this->success($type);
262 } 205 }
263 206
@@ -272,8 +215,8 @@ class InitHtmlLogic extends BaseLogic @@ -272,8 +215,8 @@ class InitHtmlLogic extends BaseLogic
272 //字符串截取 215 //字符串截取
273 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'); 216 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
274 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'); 217 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/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'); 218 + $param['head_css'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
  219 + $param['footer_css'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
277 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 220 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
278 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 221 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
279 return $this->success($param); 222 return $this->success($param);
@@ -326,42 +269,24 @@ class InitHtmlLogic extends BaseLogic @@ -326,42 +269,24 @@ class InitHtmlLogic extends BaseLogic
326 if($info === false){ 269 if($info === false){
327 $html = ''; 270 $html = '';
328 }else{ 271 }else{
329 - $commonInfo = $this->getCustomizeTemplateComHtml($this->param['type'],$is_custom,$is_list);  
330 - $html = $this->handleAllHtml($commonInfo,$info['main_html']); 272 + //扩展模块获取头部
  273 + if($is_custom == BTemplate::IS_CUSTOM){
  274 + $type = $this->param['type'];
  275 + }else{
  276 + $type = $this->getCustomizedType($this->param['type'],$is_list);
  277 + }
  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 + }
  283 + $html = $info['main_html'];
331 } 284 }
332 //更新头部底部 285 //更新头部底部
333 return $this->success(['html'=>$html]); 286 return $this->success(['html'=>$html]);
334 } 287 }
335 288
336 /** 289 /**
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'];  
356 - }else{  
357 - $data['other'] = $v['html'];  
358 - }  
359 - }  
360 - }  
361 - return $this->success($data);  
362 - }  
363 -  
364 - /**  
365 * @remark :返回整个html截取代码 290 * @remark :返回整个html截取代码
366 * @name :handleAllHtml 291 * @name :handleAllHtml
367 * @author :lyh 292 * @author :lyh
@@ -404,7 +329,7 @@ class InitHtmlLogic extends BaseLogic @@ -404,7 +329,7 @@ class InitHtmlLogic extends BaseLogic
404 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 329 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
405 } 330 }
406 //更新头部底部 331 //更新头部底部
407 - $this->saveTemplateCom($this->param['html'],0,$this->param['type'],$is_list,$is_custom); 332 + $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list,$is_custom);
408 }catch (\Exception $exception){ 333 }catch (\Exception $exception){
409 $this->fail('保存失败,请联系开发人员'); 334 $this->fail('保存失败,请联系开发人员');
410 } 335 }
@@ -412,6 +337,73 @@ class InitHtmlLogic extends BaseLogic @@ -412,6 +337,73 @@ class InitHtmlLogic extends BaseLogic
412 } 337 }
413 338
414 /** 339 /**
  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 + /**
415 * @remark :前端获取设置模块(侧边栏) 407 * @remark :前端获取设置模块(侧边栏)
416 * @name :getInitModuleMain 408 * @name :getInitModuleMain
417 * @author :lyh 409 * @author :lyh