作者 lyh

gx

@@ -7,7 +7,7 @@ use App\Models\Project\PageSetting; @@ -7,7 +7,7 @@ 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\BTemplateCommon; 10 +use App\Models\Template\BTemplateCom;
11 use App\Models\Template\BTemplateLog; 11 use App\Models\Template\BTemplateLog;
12 use App\Models\Template\Setting; 12 use App\Models\Template\Setting;
13 use App\Models\Template\BTemplate; 13 use App\Models\Template\BTemplate;
@@ -49,13 +49,81 @@ class CustomTemplateLogic extends BaseLogic @@ -49,13 +49,81 @@ class CustomTemplateLogic extends BaseLogic
49 $this->fail('当前数据不存在'); 49 $this->fail('当前数据不存在');
50 } 50 }
51 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){ 51 if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
52 - $html = $this->getBodyHeaderFooter($info['html'],$info['html_style']); 52 + $html = $this->getTemplateComHtml($info['html'],$info['html_style']);
53 $info['html'] = $this->getHeadFooter($html); 53 $info['html'] = $this->getHeadFooter($html);
54 } 54 }
55 return $this->success($info); 55 return $this->success($info);
56 } 56 }
57 57
58 /** 58 /**
  59 + * @remark :非定制获取头部+底部
  60 + * @name :getTemplateComHtml
  61 + * @author :lyh
  62 + * @method :post
  63 + * @time :2024/4/29 16:53
  64 + */
  65 + public function getTemplateComHtml($html,$html_style){
  66 + $headComInfo = $this->getHeadComHtml(['common_type'=>BTemplate::COMMON_HEAD]);
  67 + $bTemplateComModel = new BTemplateCom();
  68 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  69 + $condition['source'] = $headComInfo['source'];
  70 + $otherInfo = $bTemplateComModel->read($condition);
  71 + if($otherInfo === false){
  72 + $this->fail('获取失败,请联系管理员');
  73 + }
  74 + $footerComInfo = $this->getFooterComHtml();
  75 + $commonInfo = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
  76 + 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
  77 + $html = $commonInfo['head_style'].$html_style.$commonInfo['footer_style'].$commonInfo['other']. $commonInfo['head_html'].$html.$commonInfo['footer_html'];
  78 + return $this->success($html);
  79 + }
  80 +
  81 + /**
  82 + * @remark :公共头部
  83 + * @name :HeadComHtml
  84 + * @author :lyh
  85 + * @method :post
  86 + * @time :2024/4/29 17:20
  87 + */
  88 + public function getHeadComHtml($condition){
  89 + $bTemplateComModel = new BTemplateCom();
  90 + $condition['source'] = $this->getType();
  91 + $condition['common_type'] = BTemplate::COMMON_HEAD;
  92 + $headComInfo = $bTemplateComModel->read($condition);
  93 + if($headComInfo === false){
  94 + //取默认公共的
  95 + $condition['source'] = BTemplate::SOURCE_COM;
  96 + $headComInfo = $bTemplateComModel->read($condition);
  97 + if($headComInfo === false){
  98 + $this->fail('获取失败,请联系管理员');
  99 + }
  100 + }
  101 + return $this->success($headComInfo);
  102 + }
  103 + /**
  104 + * @remark :公共底部
  105 + * @name :footerComHtml
  106 + * @author :lyh
  107 + * @method :post
  108 + * @time :2024/4/29 17:18
  109 + */
  110 + public function getFooterComHtml(){
  111 + $bTemplateComModel = new BTemplateCom();
  112 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  113 + $condition['source'] = $this->getType(BTemplate::COMMON_FOOTER);
  114 + $footerComInfo = $bTemplateComModel->read($condition);
  115 + if($footerComInfo === false){
  116 + //取默认首页的
  117 + $condition['source'] = BTemplate::SOURCE_COM;
  118 + $footerComInfo = $bTemplateComModel->read($condition);
  119 + if($footerComInfo === false){
  120 + $this->fail('获取失败,请联系管理员');
  121 + }
  122 + }
  123 + return $this->success($footerComInfo);
  124 + }
  125 +
  126 + /**
59 * @remark :保存自定义界面 127 * @remark :保存自定义界面
60 * @name :customTemplateSave 128 * @name :customTemplateSave
61 * @author :lyh 129 * @author :lyh
@@ -115,15 +183,16 @@ class CustomTemplateLogic extends BaseLogic @@ -115,15 +183,16 @@ class CustomTemplateLogic extends BaseLogic
115 if($bSettingInfo === false){ 183 if($bSettingInfo === false){
116 $this->fail('请先选择模版'); 184 $this->fail('请先选择模版');
117 } 185 }
118 - $this->saveCommonTemplate($html,$bSettingInfo['template_id']);  
119 - $this->param['html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');  
120 - $this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'); 186 + $handleInfo = $this->handleResultParam($html);
  187 + $this->saveTemplateCom($handleInfo,$bSettingInfo['template_id']);
  188 + $this->param['html'] = $handleInfo['main_html'];
  189 + $this->param['html_style'] = $handleInfo['main_style'];
121 } 190 }
122 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]); 191 $rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]);
123 if($rs === false){ 192 if($rs === false){
124 $this->fail('系统错误,请联系管理'); 193 $this->fail('系统错误,请联系管理');
125 } 194 }
126 - $this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']); 195 + $this->setTemplateLog($bSettingInfo['template_id'],$handleInfo,$this->param['id']);
127 //通知 196 //通知
128 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']); 197 $this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']);
129 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]); 198 $this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]);
@@ -138,6 +207,7 @@ class CustomTemplateLogic extends BaseLogic @@ -138,6 +207,7 @@ class CustomTemplateLogic extends BaseLogic
138 * @time :2023/8/23 11:16 207 * @time :2023/8/23 11:16
139 */ 208 */
140 public function setTemplateLog($template_id,$html,$source_id){ 209 public function setTemplateLog($template_id,$html,$source_id){
  210 + $handleInfo = $this->handleResultParam($html);
141 $data = [ 211 $data = [
142 'template_id'=>$template_id, 212 'template_id'=>$template_id,
143 'project_id'=>$this->user['project_id'], 213 'project_id'=>$this->user['project_id'],
@@ -145,71 +215,99 @@ class CustomTemplateLogic extends BaseLogic @@ -145,71 +215,99 @@ class CustomTemplateLogic extends BaseLogic
145 'text'=>$html, 215 'text'=>$html,
146 'source'=>9, 216 'source'=>9,
147 'source_id'=>$source_id, 217 'source_id'=>$source_id,
148 - 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),  
149 - 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),  
150 - 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),  
151 - 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),  
152 - 'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),  
153 - 'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'), 218 + 'head_html'=>$handleInfo['head_html'],
  219 + 'head_css'=>$handleInfo['head_style'],
  220 + 'footer_html'=>$handleInfo['footer_html'],
  221 + 'footer_css'=>$handleInfo['footer_style'],
  222 + 'main_html' => $handleInfo['main_html'],
  223 + 'main_css' => $handleInfo['main_style'],
  224 + 'other'=>$handleInfo['other']
154 ]; 225 ];
155 - $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));  
156 - $data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);  
157 $bTemplateLogModel = new BTemplateLog(); 226 $bTemplateLogModel = new BTemplateLog();
158 return $bTemplateLogModel->add($data); 227 return $bTemplateLogModel->add($data);
159 } 228 }
160 229
161 /** 230 /**
162 - * @remark :保存头部公共数据  
163 - * @name :saveCommonTemplate 231 + * @remark :截取数据返回
  232 + * @name :handleResultParam
164 * @author :lyh 233 * @author :lyh
165 * @method :post 234 * @method :post
166 - * @time :2023/10/13 14:27 235 + * @time :2024/5/6 14:14
167 */ 236 */
168 - public function saveCommonTemplate($html,$template_id){  
169 - $type = $this->getType();  
170 - $templateCommonModel = new BTemplateCommon();  
171 - $info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);  
172 - $data = [ 237 + public function handleResultParam($html){
  238 + $handleInfo = [
173 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'), 239 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
174 - 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'), 240 + 'head_style'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
175 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'), 241 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
176 - 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'), 242 + 'footer_style'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  243 + 'main_html' => characterTruncationStr($html,"<main","</main>"),
  244 + 'main_style' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
177 ]; 245 ];
178 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 246 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
179 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 247 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
180 - if($info === false){  
181 - $data['template_id'] = $template_id;  
182 - $data['project_id'] = $this->user['project_id'];  
183 - $data['type'] = $type;  
184 - $templateCommonModel->add($data);  
185 - }else{  
186 - $templateCommonModel->edit($data,['id'=>$info['id']]); 248 + $handleInfo['other'] = $other;
  249 + return $this->success($handleInfo);
  250 + }
  251 +
  252 + /**
  253 + * @remark :保存公共部分(头部。底部。连接部分)
  254 + * @name :saveTemplateCom
  255 + * @author :lyh
  256 + * @method :post
  257 + * @time :2024/4/29 10:32
  258 + */
  259 + public function saveTemplateCom($handleInfo,$template_id){
  260 + $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
  261 + $templateComModel = new BTemplateCom();
  262 + foreach ($typeArr as $type){
  263 + if($type == BTemplate::COMMON_HEAD){
  264 + $param['html'] = $handleInfo['head_html'];
  265 + $param['html_style'] = $handleInfo['head_style'];
  266 + $typeSource = $this->getType($type);//头部是否为独立头部
  267 + }elseif ($type == BTemplate::COMMON_FOOTER){
  268 + $param['html'] = $handleInfo['footer_html'];
  269 + $param['html_style'] = $handleInfo['footer_style'];
  270 + $typeSource = $this->getType($type);
  271 + }else{
  272 + $param['html'] = $handleInfo['other'];
  273 + $param['html_style'] = null;
  274 + $type == BTemplate::COMMON_HEAD;
  275 + $typeSource = $this->getType($type);
  276 + }
  277 + //查看当前数据是否还存在
  278 + $condition = ['template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];
  279 + $info = $templateComModel->read($condition);
  280 + if($info === false){
  281 + $data = array_merge($param,$condition);
  282 + $rs = $templateComModel->add($data);
  283 + }else{
  284 + $rs = $templateComModel->edit($param,$condition);
  285 + }
  286 + if($rs === false){
  287 + $this->fail('保存错误,请联系管理员');
  288 + }
187 } 289 }
188 - //更新所有界面的other  
189 - $templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);  
190 return $this->success(); 290 return $this->success();
191 } 291 }
192 292
193 /** 293 /**
194 - * @remark :获取设置的类型 294 + * @remark :(非定制)保存时获取获取设置的类型
195 * @name :getType 295 * @name :getType
196 * @author :lyh 296 * @author :lyh
197 * @method :post 297 * @method :post
198 * @time :2023/10/21 17:29 298 * @time :2023/10/21 17:29
199 */ 299 */
200 - public function getType(){  
201 - $type = 1;//首页公共头部底部  
202 - //查看页面是否设置自定义头部底部  
203 - if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {  
204 - $pageSettingModel = new PageSetting();  
205 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);  
206 - if ($pageInfo !== false) {  
207 - if ($pageInfo['page_list'] != 0) {  
208 - $type = 9;  
209 - }  
210 - } 300 + public function getType($CommonType = BTemplate::COMMON_HEAD){
  301 + $type = BTemplate::SOURCE_COM;//公共头部底部
  302 + $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
  303 + if($is_head == BTemplate::IS_NO_HEADER){
  304 + return $this->success($type);
211 } 305 }
212 - return $type; 306 + //查看页面是否设置自定义头部底部
  307 + $pageSettingModel = new PageSetting();
  308 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
  309 + if ($pageInfo !== false) {if ($pageInfo['page_list'] != 0) {$type = 9;}}
  310 + return $this->success($type);
213 } 311 }
214 312
215 /** 313 /**
@@ -277,59 +375,6 @@ class CustomTemplateLogic extends BaseLogic @@ -277,59 +375,6 @@ class CustomTemplateLogic extends BaseLogic
277 } 375 }
278 376
279 /** 377 /**
280 - * @remark :获取body的详情  
281 - * @name :getBodyHeaderFooter  
282 - * @author :lyh  
283 - * @method :post  
284 - * @time :2023/7/21 18:08  
285 - */  
286 - public function getBodyHeaderFooter($preg_html,$html_style){  
287 - if(empty($preg_html)){  
288 - $preg_html = "<main></main>";  
289 - $html_style = "<style id='globalsojs-styles'></style>";  
290 - }  
291 - //获取设置的默认模版  
292 - $bSettingModel = new Setting();  
293 - $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);  
294 - if($info === false){  
295 - $this->fail('请先设置模版');  
296 - }  
297 - //获取type类型  
298 - $commonInfo = $this->getCommonPage($info['template_id']);  
299 - $html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].  
300 - $commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];  
301 - return $this->success($html);  
302 - }  
303 -  
304 - /**  
305 - * @remark :根据类型获取公共头和底  
306 - * @name :getCommonPage  
307 - * @author :lyh  
308 - * @method :post  
309 - * @time :2023/10/21 16:55  
310 - */  
311 - public function getCommonPage($template_id){  
312 - if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {  
313 - //查看页面是否设置自定义头部底部  
314 - $pageSettingModel = new PageSetting();  
315 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);  
316 - if ($pageInfo !== false) {  
317 - $commonTemplateModel = new BTemplateCommon();  
318 - if ($pageInfo['page_list'] != 0) {  
319 - //使用独立头和底  
320 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 9]);  
321 - }  
322 - }  
323 - }  
324 - if(!isset($commonInfo) || $commonInfo === false){  
325 - //获取首页公共的头部和底部  
326 - $commonTemplateModel = new BTemplateCommon();  
327 - $commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>1]);  
328 - }  
329 - return $commonInfo;  
330 - }  
331 -  
332 - /**  
333 * @remark :拼接获取公共头部底部 378 * @remark :拼接获取公共头部底部
334 * @name :getHeadFooter 379 * @name :getHeadFooter
335 * @author :lyh 380 * @author :lyh
@@ -404,4 +449,42 @@ class CustomTemplateLogic extends BaseLogic @@ -404,4 +449,42 @@ class CustomTemplateLogic extends BaseLogic
404 } 449 }
405 return $this->success(); 450 return $this->success();
406 } 451 }
  452 +
  453 + /**
  454 + * @remark :复制单页面
  455 + * @name :copyCustomTemplateInfo
  456 + * @author :lyh
  457 + * @method :post
  458 + * @time :2024/4/28 16:16
  459 + */
  460 + public function copyCustomTemplateInfo(){
  461 + $info = $this->model->read(['id'=>$this->param['id']]);
  462 + $param = $this->setCustomTemplateParams($info);
  463 + $save_id = $this->model->insertGetId($param);
  464 + $route = RouteMap::setRoute($param['url'], RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
  465 + $this->model->edit(['route'=>$route],['id'=>$save_id]);
  466 + return $this->success(['id'=>$save_id]);
  467 + }
  468 +
  469 + /**
  470 + * @remark :组装数据
  471 + * @name :setCustomTemplateParams
  472 + * @author :lyh
  473 + * @method :post
  474 + * @time :2024/4/28 16:18
  475 + */
  476 + public function setCustomTemplateParams($info){
  477 + return [
  478 + 'name'=>$info['name'].'-copy',
  479 + 'status'=>$info['status'],
  480 + 'url'=>$info['url'],
  481 + 'html'=>$info['html'],
  482 + 'html_style'=>$info['html_style'],
  483 + 'project_id'=>$info['project_id'],
  484 + 'section_list_id'=>$info['section_list_id'],
  485 + 'is_visualization'=>$info['is_visualization'],
  486 + 'created_at'=>date('Y-m-d H:i:s'),
  487 + 'updated_at'=>date('Y-m-d H:i:s'),
  488 + ];
  489 + }
407 } 490 }
@@ -14,7 +14,7 @@ use App\Models\Project\PageSetting; @@ -14,7 +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\BTemplateCommon; 17 +use App\Models\Template\BTemplateCom;
18 use App\Models\Template\BTemplateMain; 18 use App\Models\Template\BTemplateMain;
19 use App\Models\Template\Setting; 19 use App\Models\Template\Setting;
20 use App\Models\Template\TemplateTypeMain; 20 use App\Models\Template\TemplateTypeMain;
@@ -51,14 +51,83 @@ class InitHtmlLogic extends BaseLogic @@ -51,14 +51,83 @@ class InitHtmlLogic extends BaseLogic
51 $data['id'] = $mainInfo['id']; 51 $data['id'] = $mainInfo['id'];
52 $data['updated_at'] = $mainInfo['updated_at']; 52 $data['updated_at'] = $mainInfo['updated_at'];
53 } 53 }
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']; 54 + $commonInfo = $this->getTemplateComHtml($this->param['type'],$is_list,$is_custom,$template_id); //获取头部
  55 + $html = $commonInfo['head_style'].$main_style.$commonInfo['footer_style'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
56 $html = $this->getHeadFooter($html);//组装数据 56 $html = $this->getHeadFooter($html);//组装数据
57 $data['html'] = $html; 57 $data['html'] = $html;
58 return $this->success($data); 58 return $this->success($data);
59 } 59 }
60 60
61 /** 61 /**
  62 + * @remark :非定制获取头部+底部
  63 + * @name :getTemplateComHtml
  64 + * @author :lyh
  65 + * @method :post
  66 + * @time :2024/4/29 16:53
  67 + */
  68 + public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){
  69 + $condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id];
  70 + $headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id);
  71 + $bTemplateComModel = new BTemplateCom();
  72 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  73 + $condition['source'] = $headComInfo['source'];
  74 + $otherInfo = $bTemplateComModel->read($condition);
  75 + if($otherInfo === false){
  76 + $this->fail('获取失败,请联系管理员');
  77 + }
  78 + $footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id);
  79 + $data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
  80 + 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
  81 + return $this->success($data);
  82 + }
  83 +
  84 + /**
  85 + * @remark :公共头部
  86 + * @name :HeadComHtml
  87 + * @author :lyh
  88 + * @method :post
  89 + * @time :2024/4/29 17:20
  90 + */
  91 + public function getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id){
  92 + $commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
  93 + $bTemplateComModel = new BTemplateCom();
  94 + $condition['source'] = $commonHead;
  95 + $condition['common_type'] = BTemplate::COMMON_HEAD;
  96 + $headComInfo = $bTemplateComModel->read($condition);
  97 + if($headComInfo === false){
  98 + //取默认公共的
  99 + $condition['source'] = BTemplate::SOURCE_COM;
  100 + $headComInfo = $bTemplateComModel->read($condition);
  101 + if($headComInfo === false){
  102 + $this->fail('获取失败,请联系管理员');
  103 + }
  104 + }
  105 + return $this->success($headComInfo);
  106 + }
  107 + /**
  108 + * @remark :公共底部
  109 + * @name :footerComHtml
  110 + * @author :lyh
  111 + * @method :post
  112 + * @time :2024/4/29 17:18
  113 + */
  114 + public function getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id){
  115 + $bTemplateComModel = new BTemplateCom();
  116 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  117 + $condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER,$template_id);
  118 + $footerComInfo = $bTemplateComModel->read($condition);
  119 + if($footerComInfo === false){
  120 + //取默认首页的
  121 + $condition['source'] = BTemplate::SOURCE_COM;
  122 + $footerComInfo = $bTemplateComModel->read($condition);
  123 + if($footerComInfo === false){
  124 + $this->fail('获取失败,请联系管理员');
  125 + }
  126 + }
  127 + return $this->success($footerComInfo);
  128 + }
  129 +
  130 + /**
62 * @remark :拼接获取公共头部底部 131 * @remark :拼接获取公共头部底部
63 * @name :getHeadFooter 132 * @name :getHeadFooter
64 * @author :lyh 133 * @author :lyh
@@ -97,7 +166,7 @@ class InitHtmlLogic extends BaseLogic @@ -97,7 +166,7 @@ class InitHtmlLogic extends BaseLogic
97 $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom,'is_list'=>$is_list]); 166 $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom,'is_list'=>$is_list]);
98 if($mainInfo === false){ 167 if($mainInfo === false){
99 $data = [ 168 $data = [
100 - 'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'), 169 + 'main_html'=>characterTruncationStr($this->param['html'],"<main","</main>"),
101 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'), 170 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
102 'section_list_id'=>$this->param['section_list_id'] ?? '', 171 'section_list_id'=>$this->param['section_list_id'] ?? '',
103 'project_id'=>$this->user['project_id'], 172 'project_id'=>$this->user['project_id'],
@@ -108,99 +177,86 @@ class InitHtmlLogic extends BaseLogic @@ -108,99 +177,86 @@ class InitHtmlLogic extends BaseLogic
108 $bTemplateMainModel->add($data); 177 $bTemplateMainModel->add($data);
109 }else{ 178 }else{
110 $data = [ 179 $data = [
111 - 'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'), 180 + 'main_html'=>characterTruncationStr($this->param['html'],"<main","</main>"),
112 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'), 181 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
113 'section_list_id'=>$this->param['section_list_id'] ?? '', 182 'section_list_id'=>$this->param['section_list_id'] ?? '',
114 ]; 183 ];
115 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]); 184 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
116 } 185 }
117 - $this->saveCommonHtml($this->param['html'],$this->param['type'],$is_list,$template_id,$is_custom); 186 + $this->saveTemplateCom($this->param['html'],$template_id,$this->param['type'],$is_list,$is_custom);
118 $route = RouteMap::getRoute('all',0,$this->user['project_id']); 187 $route = RouteMap::getRoute('all',0,$this->user['project_id']);
119 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]); 188 $this->curlDelRoute(['route'=>$route,'new_route'=>$route]);
120 return $this->success(); 189 return $this->success();
121 } 190 }
122 191
123 /** 192 /**
124 - * @remark :保存公共头部底部  
125 - * @name :saveCommonHtml 193 + * @remark :保存公共部分(头部。底部。连接部分)
  194 + * @name :saveTemplateCom
126 * @author :lyh 195 * @author :lyh
127 * @method :post 196 * @method :post
128 - * @time :2023/12/13 17:05 197 + * @time :2024/4/29 10:32
129 */ 198 */
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]);//查看当前头部是否存在 199 + public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){
  200 + $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
134 $handleInfo = $this->handleCommonParam($html); 201 $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);  
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']]);  
148 - }  
149 - //更新所有界面的other  
150 - return $templateCommonModel->edit(['other'=>$handleInfo['other']],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]);  
151 - }  
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); 202 + $templateComModel = new BTemplateCom();
  203 + foreach ($typeArr as $type){
  204 + if($type == BTemplate::COMMON_HEAD){
  205 + $param['html'] = $handleInfo['head_html'];
  206 + $param['html_style'] = $handleInfo['head_style'];
  207 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
  208 + }elseif ($type == BTemplate::COMMON_FOOTER){
  209 + $param['html'] = $handleInfo['footer_html'];
  210 + $param['html_style'] = $handleInfo['footer_style'];
  211 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
  212 + }else{
  213 + $param['html'] = $handleInfo['other'];
  214 + $param['html_style'] = null;
  215 + $typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
  216 + }
  217 + //查看当前数据是否还存在
  218 + $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
  219 + $info = $templateComModel->read($condition);
  220 + if($info === false){
  221 + $data = array_merge($param,$condition);
  222 + $templateComModel->add($data);
  223 + }else{
  224 + $templateComModel->edit($param,$condition);
  225 + }
172 } 226 }
173 - return $this->success($commonInfo); 227 + return $this->success();
174 } 228 }
175 229
176 /** 230 /**
177 - * @remark :保存时获取获取设置的类型 231 + * @remark :(非定制)保存时获取获取设置的类型
178 * @name :getType 232 * @name :getType
179 * @author :lyh 233 * @author :lyh
180 * @method :post 234 * @method :post
181 * @time :2023/10/21 17:29 235 * @time :2023/10/21 17:29
182 */ 236 */
183 - public function getType($source,$is_list,$is_custom = 0){  
184 - $type = BTemplate::SOURCE_HOME;//首页公共头部底部 237 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  238 + if($template_id == 0){
  239 + return $this->success($source);
  240 + }
  241 + $type = BTemplate::SOURCE_COM;//公共头部底部
185 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 242 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
186 - if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部 243 + if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
187 return $this->success($type); 244 return $this->success($type);
188 } 245 }
189 //查看页面是否设置自定义头部底部 246 //查看页面是否设置自定义头部底部
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;}} 247 + $pageSettingModel = new PageSetting();
  248 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
  249 + if ($pageInfo === false) {
  250 + return $this->success($type);
203 } 251 }
  252 + if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
  253 + if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
  254 + else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
  255 + if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
  256 + else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
  257 + if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
  258 + else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
  259 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::SOURCE_KEYWORD;}}
204 return $this->success($type); 260 return $this->success($type);
205 } 261 }
206 262
@@ -215,8 +271,8 @@ class InitHtmlLogic extends BaseLogic @@ -215,8 +271,8 @@ class InitHtmlLogic extends BaseLogic
215 //字符串截取 271 //字符串截取
216 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'); 272 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
217 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'); 273 $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'); 274 + $param['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
  275 + $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')); 276 $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); 277 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
222 return $this->success($param); 278 return $this->success($param);
@@ -269,24 +325,42 @@ class InitHtmlLogic extends BaseLogic @@ -269,24 +325,42 @@ class InitHtmlLogic extends BaseLogic
269 if($info === false){ 325 if($info === false){
270 $html = ''; 326 $html = '';
271 }else{ 327 }else{
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']; 328 + $commonInfo = $this->getCustomizeTemplateComHtml($this->param['type'],$is_custom,$is_list);
  329 + $html = $this->handleAllHtml($commonInfo,$info['main_html']);
284 } 330 }
285 //更新头部底部 331 //更新头部底部
286 return $this->success(['html'=>$html]); 332 return $this->success(['html'=>$html]);
287 } 333 }
288 334
289 /** 335 /**
  336 + * @remark :定制获取头部底部
  337 + * @name :getCustomizedCommonHtml
  338 + * @author :lyh
  339 + * @method :post
  340 + * @time :2023/12/29 13:13
  341 + */
  342 + public function getCustomizeTemplateComHtml($type,$is_custom,$is_list,$template_id = 0){
  343 + $data = ['head_html'=>'','head_style'=>'','footer_html'=>'','footer_style'=>'','other'=>''];
  344 + $param = ['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list];
  345 + $commonTemplateModel = new BTemplateCom();
  346 + $commonList = $commonTemplateModel->list($param);
  347 + if(!empty($commonList)){
  348 + foreach ($commonList as $v){
  349 + if($v['common_type'] == BTemplate::COMMON_HEAD){
  350 + $data['head_html'] = $v['html'];
  351 + $data['head_style'] = $v['html_style'];
  352 + }elseif ($v['common_type'] == BTemplate::COMMON_FOOTER){
  353 + $data['footer_html'] = $v['html'];
  354 + $data['footer_style'] = $v['html_style'];
  355 + }else{
  356 + $data['other'] = $v['html'];
  357 + }
  358 + }
  359 + }
  360 + return $this->success($data);
  361 + }
  362 +
  363 + /**
290 * @remark :返回整个html截取代码 364 * @remark :返回整个html截取代码
291 * @name :handleAllHtml 365 * @name :handleAllHtml
292 * @author :lyh 366 * @author :lyh
@@ -329,7 +403,7 @@ class InitHtmlLogic extends BaseLogic @@ -329,7 +403,7 @@ class InitHtmlLogic extends BaseLogic
329 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]); 403 $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
330 } 404 }
331 //更新头部底部 405 //更新头部底部
332 - $this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list,$is_custom); 406 + $this->saveTemplateCom($this->param['html'],0,$this->param['type'],$is_list,$is_custom);
333 }catch (\Exception $exception){ 407 }catch (\Exception $exception){
334 $this->fail('保存失败,请联系开发人员'); 408 $this->fail('保存失败,请联系开发人员');
335 } 409 }
@@ -337,73 +411,6 @@ class InitHtmlLogic extends BaseLogic @@ -337,73 +411,6 @@ class InitHtmlLogic extends BaseLogic
337 } 411 }
338 412
339 /** 413 /**
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 :前端获取设置模块(侧边栏) 414 * @remark :前端获取设置模块(侧边栏)
408 * @name :getInitModuleMain 415 * @name :getInitModuleMain
409 * @author :lyh 416 * @author :lyh