作者 lyh

gx

@@ -6,7 +6,7 @@ use App\Http\Logic\Aside\BaseLogic; @@ -6,7 +6,7 @@ use App\Http\Logic\Aside\BaseLogic;
6 use App\Models\RouteMap\RouteMap; 6 use App\Models\RouteMap\RouteMap;
7 use App\Models\Service\Service as ServiceSettingModel; 7 use App\Models\Service\Service as ServiceSettingModel;
8 use App\Models\Template\BTemplate; 8 use App\Models\Template\BTemplate;
9 -use App\Models\Template\BTemplateCommon; 9 +use App\Models\Template\BTemplateCom;
10 use App\Models\Template\Template; 10 use App\Models\Template\Template;
11 use App\Models\Template\Setting; 11 use App\Models\Template\Setting;
12 use App\Services\ProjectServer; 12 use App\Services\ProjectServer;
@@ -203,25 +203,34 @@ class ATemplateLogic extends BaseLogic @@ -203,25 +203,34 @@ class ATemplateLogic extends BaseLogic
203 $templateInfo = $this->model->read(['id'=>$template_id]); 203 $templateInfo = $this->model->read(['id'=>$template_id]);
204 ProjectServer::useProject($project_id); 204 ProjectServer::useProject($project_id);
205 $bTemplateModel = new BTemplate(); 205 $bTemplateModel = new BTemplate();
206 - $info = $bTemplateModel->read(['source'=>1,'template_id'=>$template_id]); 206 + $info = $bTemplateModel->read(['source'=>BTemplate::SOURCE_HOME,'template_id'=>$template_id]);
207 if($info === false){ 207 if($info === false){
208 $data = [ 208 $data = [
209 - 'source'=>1, 'source_id'=>0, 'template_id'=>$template_id, 'main_html'=>$templateInfo['main_html'], 209 + 'source'=>BTemplate::SOURCE_HOME, 'source_id'=>0, 'template_id'=>$template_id, 'main_html'=>$templateInfo['main_html'],
210 'main_css'=>$templateInfo['main_css'], 'project_id'=>$project_id, 210 'main_css'=>$templateInfo['main_css'], 'project_id'=>$project_id,
211 ]; 211 ];
212 $bTemplateModel->add($data); 212 $bTemplateModel->add($data);
213 } 213 }
214 - //保存一次公共头部信息  
215 - $bCommonTemplateModel = new BTemplateCommon();  
216 - $commonInfo = $bCommonTemplateModel->read(['template_id'=>$template_id,'type'=>1]);  
217 - if($commonInfo === false){  
218 - $commonData = [  
219 - 'type'=>1, 'template_id'=>$template_id, 'head_html'=>$templateInfo['head_html'],  
220 - 'head_css'=>$templateInfo['head_css'], 'footer_html'=>$templateInfo['footer_html'],  
221 - 'footer_css'=>$templateInfo['footer_css'],'project_id'=>$project_id,  
222 - 'other'=>str_replace('<header','',characterTruncation($templateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s"))  
223 - ];  
224 - $bCommonTemplateModel->add($commonData); 214 + //保存一次公共头部+底部+other信息
  215 + $bComTemplateModel = new BTemplateCom();
  216 + $condition = ['template_id'=>$template_id,'common_type'=>BTemplate::COMMON_HEAD,'source'=>BTemplate::SOURCE_COM];
  217 + $headInfo = $bComTemplateModel->read($condition);
  218 + if($headInfo === false){
  219 + $headData = ['html'=>$templateInfo['head_html'], 'html_style'=>$templateInfo['head_css'], 'project_id'=>$project_id];
  220 + $bComTemplateModel->add(array_merge($condition,$headData));
  221 + }
  222 + $condition = ['template_id'=>$template_id,'common_type'=>BTemplate::COMMON_FOOTER,'source'=>BTemplate::SOURCE_COM];
  223 + $footerInfo = $bComTemplateModel->read($condition);
  224 + if($footerInfo === false){
  225 + $footerData = ['html'=>$templateInfo['head_html'], 'html_style'=>$templateInfo['head_css'], 'project_id'=>$project_id];
  226 + $bComTemplateModel->add(array_merge($condition,$footerData));
  227 + }
  228 + $condition = ['template_id'=>$template_id,'common_type'=>BTemplate::COMMON_OTHER,'source'=>BTemplate::SOURCE_COM];
  229 + $footerInfo = $bComTemplateModel->read($condition);
  230 + if($footerInfo === false){
  231 + $other = str_replace('<header','',characterTruncation($templateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s"));
  232 + $otherData = ['html'=>$other, 'html_style'=>'', 'project_id'=>$project_id];
  233 + $bComTemplateModel->add(array_merge($condition,$otherData));
225 } 234 }
226 RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $project_id); 235 RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $project_id);
227 DB::disconnect('custom_mysql'); 236 DB::disconnect('custom_mysql');
@@ -11,7 +11,7 @@ use App\Models\Product\Category; @@ -11,7 +11,7 @@ use App\Models\Product\Category;
11 use App\Models\Project\PageSetting; 11 use App\Models\Project\PageSetting;
12 use App\Models\RouteMap\RouteMap; 12 use App\Models\RouteMap\RouteMap;
13 use App\Models\Service\Service as ServiceSettingModel; 13 use App\Models\Service\Service as ServiceSettingModel;
14 -use App\Models\Template\BTemplateCommon; 14 +use App\Models\Template\BTemplateCom;
15 use App\Models\Template\BTemplateMain; 15 use App\Models\Template\BTemplateMain;
16 use App\Models\Template\Setting; 16 use App\Models\Template\Setting;
17 use App\Models\Template\BTemplate; 17 use App\Models\Template\BTemplate;
@@ -63,11 +63,11 @@ class BTemplateLogic extends BaseLogic @@ -63,11 +63,11 @@ class BTemplateLogic extends BaseLogic
63 $is_list = $this->param['is_list'] ?? 0;//是否为列表页 63 $is_list = $this->param['is_list'] ?? 0;//是否为列表页
64 $template_id = $this->getSettingTemplate($this->param['source'],$is_list,$is_custom);//设置的模版id 64 $template_id = $this->getSettingTemplate($this->param['source'],$is_list,$is_custom);//设置的模版id
65 $templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list); 65 $templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list);
66 - if($templateInfo === false){ 66 + if($templateInfo === false){//todo::无装修数据处理
67 if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据 67 if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
68 - $html = $this->customizedReturnHtml($this->param['source'],$template_id,$is_custom,$is_list);  
69 - if($html !== false){  
70 - return $this->success($html); 68 + $data = $this->customizedReturnHtml($this->param['source'],$template_id,$is_custom,$is_list);
  69 + if($data !== false){
  70 + return $this->success($data);
71 } 71 }
72 } 72 }
73 //非定制初始中间部分 73 //非定制初始中间部分
@@ -78,15 +78,87 @@ class BTemplateLogic extends BaseLogic @@ -78,15 +78,87 @@ class BTemplateLogic extends BaseLogic
78 } 78 }
79 $mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']]; 79 $mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
80 } 80 }
81 - $commonInfo = $this->getCommonHtml($this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部  
82 - $html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html']; 81 + $commonInfo = $this->getTemplateComHtml($this->param['source'],$is_list,$is_custom,$template_id);//获取非定制头部
  82 + $html = $commonInfo['head_style'].$mainInfo['main_css'].$commonInfo['footer_style'].$commonInfo['other']. $commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
83 $html = $this->getHeadFooter($html); 83 $html = $this->getHeadFooter($html);
84 $result = ['html'=>$html,'template_id'=>$template_id]; 84 $result = ['html'=>$html,'template_id'=>$template_id];
85 - if($templateInfo !== false) {$result['id'] = $templateInfo['id'];$result['updated_at'] = $templateInfo['updated_at'];} 85 + if($templateInfo !== false) {
  86 + $result['id'] = $templateInfo['id'];
  87 + $result['updated_at'] = $templateInfo['updated_at'];
  88 + }
86 return $this->success($result); 89 return $this->success($result);
87 } 90 }
88 91
89 /** 92 /**
  93 + * @remark :非定制获取头部+底部
  94 + * @name :getTemplateComHtml
  95 + * @author :lyh
  96 + * @method :post
  97 + * @time :2024/4/29 16:53
  98 + */
  99 + public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){
  100 + $condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>'','is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id];
  101 + $headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id);
  102 + $bTemplateComModel = new BTemplateCom();
  103 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  104 + $condition['source'] = $headComInfo['source'];
  105 + $otherInfo = $bTemplateComModel->read($condition);
  106 + if($otherInfo === false){
  107 + $this->fail('获取失败,请联系管理员');
  108 + }
  109 + $footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id);
  110 + $data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
  111 + 'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
  112 + return $this->success($data);
  113 + }
  114 +
  115 + /**
  116 + * @remark :公共头部
  117 + * @name :HeadComHtml
  118 + * @author :lyh
  119 + * @method :post
  120 + * @time :2024/4/29 17:20
  121 + */
  122 + public function getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id){
  123 + $commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
  124 + $bTemplateComModel = new BTemplateCom();
  125 + $condition['source'] = $commonHead;
  126 + $condition['common_type'] = BTemplate::COMMON_HEAD;
  127 + $headComInfo = $bTemplateComModel->read($condition);
  128 + if($headComInfo === false){
  129 + //取默认公共的
  130 + $condition['source'] = BTemplate::SOURCE_COM;
  131 + $headComInfo = $bTemplateComModel->read($condition);
  132 + if($headComInfo === false){
  133 + $this->fail('获取失败,请联系管理员');
  134 + }
  135 + }
  136 + return $this->success($headComInfo);
  137 + }
  138 + /**
  139 + * @remark :公共底部
  140 + * @name :footerComHtml
  141 + * @author :lyh
  142 + * @method :post
  143 + * @time :2024/4/29 17:18
  144 + */
  145 + public function getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id){
  146 + $bTemplateComModel = new BTemplateCom();
  147 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  148 + $condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER,$template_id);
  149 + $footerComInfo = $bTemplateComModel->read($condition);
  150 + if($footerComInfo === false){
  151 + //取默认首页的
  152 + $condition['source'] = BTemplate::SOURCE_COM;
  153 + $footerComInfo = $bTemplateComModel->read($condition);
  154 + if($footerComInfo === false){
  155 + $this->fail('获取失败,请联系管理员');
  156 + }
  157 + }
  158 + return $this->success($footerComInfo);
  159 + }
  160 +
  161 + /**
90 * @remark :获取整个html代码 162 * @remark :获取整个html代码
91 * @name :getCustomizeAllHtml 163 * @name :getCustomizeAllHtml
92 * @author :lyh 164 * @author :lyh
@@ -95,11 +167,11 @@ class BTemplateLogic extends BaseLogic @@ -95,11 +167,11 @@ class BTemplateLogic extends BaseLogic
95 */ 167 */
96 public function getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list){ 168 public function getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list){
97 if($is_custom == BTemplate::IS_CUSTOM){ 169 if($is_custom == BTemplate::IS_CUSTOM){
98 - $commonInfo = $this->getCustomizedCommonHtml($this->param['source'],$is_custom,$is_list);//获取定制头部 170 + $commonInfo = $this->getCustomizeTemplateComHtml($templateInfo['source'],$is_custom,$is_list);//获取定制头部
99 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']); 171 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
100 }else{ 172 }else{
101 - $type = $this->getCustomizedType($this->param['source'],$is_list);  
102 - $commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部 173 + $type = $this->getCustomizedType($templateInfo['source'],$is_list);
  174 + $commonInfo = $this->getCustomizeTemplateComHtml($type,$is_custom,$is_list);//获取定制头部
103 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']); 175 $html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
104 } 176 }
105 return $this->success(['html'=>$html,'template_id'=>$template_id,'id'=>$templateInfo['id'],'updated_at'=>$templateInfo['updated_at']]); 177 return $this->success(['html'=>$html,'template_id'=>$template_id,'id'=>$templateInfo['id'],'updated_at'=>$templateInfo['updated_at']]);
@@ -136,11 +208,12 @@ class BTemplateLogic extends BaseLogic @@ -136,11 +208,12 @@ class BTemplateLogic extends BaseLogic
136 if($info === false){ 208 if($info === false){
137 $this->fail('当前扩展模块不存在或已被删除'); 209 $this->fail('当前扩展模块不存在或已被删除');
138 } 210 }
139 - //扩展模块定制 211 + //扩展模块定制列表
140 if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){ 212 if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){
141 $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom); 213 $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
142 return $this->success(['html'=>$html,'template_id'=>$template_id]); 214 return $this->success(['html'=>$html,'template_id'=>$template_id]);
143 } 215 }
  216 + //扩展模块定制详情
144 if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){ 217 if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){
145 $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom); 218 $html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
146 return $this->success(['html'=>$html,'template_id'=>$template_id]); 219 return $this->success(['html'=>$html,'template_id'=>$template_id]);
@@ -169,7 +242,7 @@ class BTemplateLogic extends BaseLogic @@ -169,7 +242,7 @@ class BTemplateLogic extends BaseLogic
169 if($customHtmlInfo === false){ 242 if($customHtmlInfo === false){
170 $this->fail('定制页面,请先上传代码块'); 243 $this->fail('定制页面,请先上传代码块');
171 } 244 }
172 - $commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部 245 + $commonInfo = $this->getCustomizeTemplateComHtml($source,$is_custom,$is_list);//获取定制头部
173 if($commonInfo !== false){ 246 if($commonInfo !== false){
174 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']); 247 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
175 } 248 }
@@ -249,7 +322,7 @@ class BTemplateLogic extends BaseLogic @@ -249,7 +322,7 @@ class BTemplateLogic extends BaseLogic
249 if($customHtmlInfo === false){ 322 if($customHtmlInfo === false){
250 $this->fail('定制页面,请先上传代码块'); 323 $this->fail('定制页面,请先上传代码块');
251 } 324 }
252 - $commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部 325 + $commonInfo = $this->getCustomizeTemplateComHtml($type,$is_custom,$is_list);//获取定制头部
253 if($commonInfo !== false){ 326 if($commonInfo !== false){
254 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']); 327 $customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
255 } 328 }
@@ -265,49 +338,25 @@ class BTemplateLogic extends BaseLogic @@ -265,49 +338,25 @@ class BTemplateLogic extends BaseLogic
265 * @method :post 338 * @method :post
266 * @time :2023/12/29 13:13 339 * @time :2023/12/29 13:13
267 */ 340 */
268 - public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){  
269 - $data = [  
270 - 'template_id' => 0,  
271 - 'project_id' => $this->user['project_id'],  
272 - 'type'=>$type,  
273 - 'is_custom'=>$is_custom,  
274 - 'is_list'=>$is_list  
275 - ];  
276 - $commonTemplateModel = new BTemplateCommon();  
277 - return $commonTemplateModel->read($data);  
278 - }  
279 -  
280 - /**  
281 - * @remark :定制页面头部类型---根据source获取type类型  
282 - * @name :getType  
283 - * @author :lyh  
284 - * @method :post  
285 - * @time :2023/11/16 11:20  
286 - */  
287 - public function getCustomizedType($source,$is_list){  
288 - $type = BTemplate::TYPE_HOME;  
289 - if($source == BTemplate::SOURCE_PRODUCT){  
290 - if($is_list == BTemplate::IS_LIST){  
291 - $type = BTemplate::TYPE_PRODUCT_LIST;  
292 - }else{  
293 - $type = BTemplate::TYPE_PRODUCT_DETAIL;  
294 - }  
295 - }  
296 - if($source == BTemplate::SOURCE_BLOG){  
297 - if($is_list == BTemplate::IS_LIST){  
298 - $type = BTemplate::TYPE_BLOG_LIST;  
299 - }else{  
300 - $type = BTemplate::TYPE_BLOG_DETAIL;  
301 - }  
302 - }  
303 - if($source == BTemplate::SOURCE_NEWS){  
304 - if($is_list == BTemplate::IS_LIST){  
305 - $type = BTemplate::TYPE_NEWS_LIST;  
306 - }else{  
307 - $type = BTemplate::TYPE_NEWS_DETAIL; 341 + public function getCustomizeTemplateComHtml($type,$is_custom,$is_list,$template_id = 0){
  342 + $data = ['head_html'=>'','head_style'=>'','footer_html'=>'','footer_style'=>'','other'=>''];
  343 + $param = ['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list];
  344 + $commonTemplateModel = new BTemplateCom();
  345 + $commonList = $commonTemplateModel->list($param);
  346 + if(!empty($commonList)){
  347 + foreach ($commonList as $v){
  348 + if($v['common_type'] == BTemplate::COMMON_HEAD){
  349 + $data['head_html'] = $v['html'];
  350 + $data['head_style'] = $v['html_style'];
  351 + }elseif ($v['common_type'] == BTemplate::COMMON_FOOTER){
  352 + $data['footer_html'] = $v['html'];
  353 + $data['footer_style'] = $v['html_style'];
  354 + }else{
  355 + $data['other'] = $v['html'];
  356 + }
308 } 357 }
309 } 358 }
310 - return $type; 359 + return $this->success($data);
311 } 360 }
312 361
313 /** 362 /**
@@ -346,38 +395,10 @@ class BTemplateLogic extends BaseLogic @@ -346,38 +395,10 @@ class BTemplateLogic extends BaseLogic
346 if($info === false){ 395 if($info === false){
347 $this->fail('请先选择模版'); 396 $this->fail('请先选择模版');
348 } 397 }
349 - $template_id = $info['template_id'];  
350 - return $this->success($template_id); 398 + return $this->success($info['template_id']);
351 } 399 }
352 400
353 /** 401 /**
354 - * @remark :根据类型获取公共头和底  
355 - * @name :getCommonPage  
356 - * @author :lyh  
357 - * @method :post  
358 - * @time :2023/10/21 16:55  
359 - */  
360 - public function getCommonHtml($source,$is_list,$template_id,$is_custom = 0){  
361 - $type = $this->getType($source,$is_list,$is_custom);  
362 - $data = [  
363 - 'template_id' => $template_id,  
364 - 'project_id' => $this->user['project_id'],  
365 - 'type'=>$type,  
366 - 'is_custom'=>0,  
367 - ];  
368 - $commonTemplateModel = new BTemplateCommon();  
369 - $commonInfo = $commonTemplateModel->read($data);  
370 - if($commonInfo === false){  
371 - $data['type'] = BTemplate::SOURCE_HOME;  
372 - $commonInfo = $commonTemplateModel->read($data);  
373 - }  
374 - return $this->success($commonInfo);  
375 - }  
376 -  
377 -  
378 -  
379 -  
380 - /**  
381 * @remark :保存修改后的模版 402 * @remark :保存修改后的模版
382 * @name :templateSave 403 * @name :templateSave
383 * @author :lyh 404 * @author :lyh
@@ -404,14 +425,12 @@ class BTemplateLogic extends BaseLogic @@ -404,14 +425,12 @@ class BTemplateLogic extends BaseLogic
404 'is_custom'=>$this->param['is_custom'], 'template_id'=>$this->param['template_id'], 425 'is_custom'=>$this->param['is_custom'], 'template_id'=>$this->param['template_id'],
405 'is_list'=>$this->param['is_list'] 426 'is_list'=>$this->param['is_list']
406 ]; 427 ];
407 - $data = [  
408 - 'section_list_id'=>$this->param['section_list_id']  
409 - ]; 428 + $data = ['section_list_id'=>$this->param['section_list_id']];
410 $data = $this->handleVisualizationParam($this->param['html'],$this->param['source'],$this->param['is_list'],$this->param['is_custom'],$data); 429 $data = $this->handleVisualizationParam($this->param['html'],$this->param['source'],$this->param['is_list'],$this->param['is_custom'],$data);
411 $this->model->edit($data,$condition); 430 $this->model->edit($data,$condition);
412 } 431 }
413 //更新头部信息 432 //更新头部信息
414 - $this->saveCommonHtml($this->param['html'],$this->param['source'],$this->param['is_list'],$this->param['template_id'],$this->param['is_custom']); 433 + $this->saveTemplateCom($this->param['html'],$this->param['template_id'],$this->param['source'],$this->param['is_list'],$this->param['is_custom']);
415 $this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom'],$this->param['is_list']); 434 $this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom'],$this->param['is_list']);
416 //通知更新 435 //通知更新
417 $this->homeOrProduct($this->param['source'],$this->param['source_id'],$this->param['is_custom'],$this->param['is_list']); 436 $this->homeOrProduct($this->param['source'],$this->param['source_id'],$this->param['is_custom'],$this->param['is_list']);
@@ -441,119 +460,70 @@ class BTemplateLogic extends BaseLogic @@ -441,119 +460,70 @@ class BTemplateLogic extends BaseLogic
441 * @time :2023/12/15 10:59 460 * @time :2023/12/15 10:59
442 */ 461 */
443 public function handleVisualizationParam($html,$source, $is_list,$is_custom,$data){ 462 public function handleVisualizationParam($html,$source, $is_list,$is_custom,$data){
444 - if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){//定制项目 463 + //TODO::扩展模块定制单独处理
  464 + if($is_custom == BTemplate::IS_CUSTOM){
  465 + $customModuleModel = new CustomModule();
  466 + $info = $customModuleModel->read(['id'=>$source]);
  467 + if($info === false){
  468 + $this->fail('当前扩展模块不存在或已被删除');
  469 + }
  470 + //todo::扩展模块(列表页/详情页)定制
  471 + if($info['list_customized'] == BTemplate::IS_VISUALIZATION || $info['detail_customized'] == BTemplate::IS_VISUALIZATION) {
  472 + $data['html'] = $html;
  473 + $data['type'] = BTemplate::ALL_HTML;
  474 + return $this->success($data);
  475 + }
  476 + }
  477 + if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){
445 $type = $this->getCustomizedType($source, $is_list);//获取定制界面类型 478 $type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
446 - //查看当前页面是否定制,是否开启可视化  
447 $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面 479 $page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
448 - if (in_array($type, $page_array)) {//当前页面是定制界面 480 + if(in_array($type, $page_array)){
449 $data['html'] = $html; 481 $data['html'] = $html;
450 $data['type'] = BTemplate::ALL_HTML; 482 $data['type'] = BTemplate::ALL_HTML;
451 - }else{  
452 - //TODO::扩展模块定制单独处理  
453 - if($is_custom == BTemplate::IS_CUSTOM){  
454 - $customModuleModel = new CustomModule();  
455 - $info = $customModuleModel->read(['id'=>$source]);  
456 - if($info === false){  
457 - $this->fail('当前扩展模块不存在或已被删除');  
458 - }  
459 - //todo::扩展模块(列表页/详情页)定制  
460 - if($info['list_customized'] == BTemplate::IS_VISUALIZATION || $info['detail_customized'] == BTemplate::IS_VISUALIZATION) {  
461 - $data['html'] = $html;  
462 - $data['type'] = BTemplate::ALL_HTML;  
463 - }  
464 - }  
465 - $mainInfo = $this->handleTemplateHtml($html);  
466 - $data['main_html'] = $mainInfo['main_html'];  
467 - $data['main_css'] = $mainInfo['main_css']; 483 + return $this->success($data);
468 } 484 }
469 - }else{  
470 - $mainInfo = $this->handleTemplateHtml($html);  
471 - $data['main_html'] = $mainInfo['main_html'];  
472 - $data['main_css'] = $mainInfo['main_css'];  
473 } 485 }
474 - return $data; 486 + $data['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
  487 + $data['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
  488 + return $this->success($data);
475 } 489 }
476 490
477 /** 491 /**
478 - * @remark :保存公共头部底部  
479 - * @name :saveCommonHtml 492 + * @remark :保存公共部分(头部。底部。连接部分)
  493 + * @name :saveTemplateCom
480 * @author :lyh 494 * @author :lyh
481 * @method :post 495 * @method :post
482 - * @time :2023/12/13 17:05 496 + * @time :2024/4/29 10:32
483 */ 497 */
484 - public function saveCommonHtml($html,$source,$is_list,$template_id,$is_custom){  
485 - //TODO::定制扩展模块单独处理  
486 - if($is_custom == BTemplate::IS_CUSTOM){  
487 - $code = $this->saveCustomModuleCommonHtml($html,$source,$is_custom,$is_list,$template_id);  
488 - if($code === false){  
489 - return $this->success();  
490 - }  
491 - }  
492 - //todo::其他情况  
493 - $type = $this->getType($source,$is_list,$is_custom);//获取头部类型1-9(首页到自定义页面)  
494 - if($template_id == 0){//定制页面默认为独立头部  
495 - $type = $this->getCustomizedType($source,$is_list);//定制默认独立头部  
496 - }  
497 - $templateCommonModel = new BTemplateCommon();  
498 - $commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type,'is_custom'=>0]);//查看当前头部是否存在 498 + public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){
  499 + $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
499 $handleInfo = $this->handleCommonParam($html); 500 $handleInfo = $this->handleCommonParam($html);
500 - if($commonInfo === false){  
501 - $data = [  
502 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
503 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
504 - 'type'=>$type,'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],  
505 - ];  
506 - $templateCommonModel->add($data);  
507 - }else{  
508 - $data = [  
509 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
510 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
511 - ];  
512 - $templateCommonModel->edit($data,['id'=>$commonInfo['id']]);  
513 - }  
514 - //更新所有界面的other  
515 - if($template_id != 0){  
516 - return $templateCommonModel->edit(['other'=>$handleInfo['other']],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]);  
517 - }  
518 - }  
519 -  
520 - /**  
521 - * @remark :扩展模块定制保存头部处理  
522 - * @name :saveCustomModuleCommonHtml  
523 - * @author :lyh  
524 - * @method :post  
525 - * @time :2024/1/10 11:33  
526 - */  
527 - public function saveCustomModuleCommonHtml($html,$source,$is_custom,$is_list,$template_id){  
528 - $customModuleModel = new CustomModule();  
529 - $info = $customModuleModel->read(['id'=>$source]);  
530 - if($info === false){  
531 - $this->fail('当前扩展模块不存在或已被删除');  
532 - }  
533 - //todo::扩展模块(列表页/详情页)定制  
534 - if($info['list_customized'] == BTemplate::IS_VISUALIZATION || $info['detail_customized'] == BTemplate::IS_VISUALIZATION) {  
535 - $data = ['type'=>$source,'is_custom'=>$is_custom,'is_list'=>$is_list,'template_id'=>$template_id];  
536 - $templateCommonModel = new BTemplateCommon();  
537 - $commonInfo = $templateCommonModel->read($data);//查看当前头部是否存在  
538 - $handleInfo = $this->handleCommonParam($html);  
539 - if($commonInfo === false){  
540 - $data = [  
541 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
542 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
543 - 'type'=>$source,'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],  
544 - 'is_custom'=>$is_custom,'is_list'=>$is_list,  
545 - ];  
546 - $templateCommonModel->add($data); 501 + $templateComModel = new BTemplateCom();
  502 + foreach ($typeArr as $type){
  503 + if($type == BTemplate::COMMON_HEAD){
  504 + $param['html'] = $handleInfo['head_html'];
  505 + $param['html_style'] = $handleInfo['head_style'];
  506 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
  507 + }elseif ($type == BTemplate::COMMON_FOOTER){
  508 + $param['html'] = $handleInfo['footer_html'];
  509 + $param['html_style'] = $handleInfo['footer_style'];
  510 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
547 }else{ 511 }else{
548 - $data = [  
549 - 'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],  
550 - 'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],  
551 - ];  
552 - $templateCommonModel->edit($data,['id'=>$commonInfo['id']]); 512 + $param['html'] = $handleInfo['other'];
  513 + $param['html_style'] = null;
  514 + $typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
  515 + }
  516 + //查看当前数据是否还存在
  517 + $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
  518 + $info = $templateComModel->read($condition);
  519 + if($info === false){
  520 + $data = array_merge($param,$condition);
  521 + $templateComModel->add($data);
  522 + }else{
  523 + $templateComModel->edit($param,$condition);
553 } 524 }
554 - return false;  
555 } 525 }
556 - return true; 526 + return $this->success();
557 } 527 }
558 528
559 /** 529 /**
@@ -582,55 +552,43 @@ class BTemplateLogic extends BaseLogic @@ -582,55 +552,43 @@ class BTemplateLogic extends BaseLogic
582 //字符串截取 552 //字符串截取
583 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'); 553 $param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
584 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'); 554 $param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
585 - $param['head_css'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');  
586 - $param['footer_css'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'); 555 + $param['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
  556 + $param['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
587 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s')); 557 $footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
588 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other); 558 $param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
589 return $this->success($param); 559 return $this->success($param);
590 } 560 }
591 561
592 /** 562 /**
593 - * @remark :保存时字符串处理  
594 - * @name :handleSaveParam  
595 - * @author :lyh  
596 - * @method :post  
597 - * @time :2023/6/29 15:35  
598 - */  
599 - public function handleTemplateHtml($html){  
600 - //字符串截取  
601 - $param['main_html'] = characterTruncationStr($html,"<main","</main>");  
602 - $param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
603 - return $this->success($param);  
604 - }  
605 -  
606 - /**  
607 * @remark :(非定制)保存时获取获取设置的类型 563 * @remark :(非定制)保存时获取获取设置的类型
608 * @name :getType 564 * @name :getType
609 * @author :lyh 565 * @author :lyh
610 * @method :post 566 * @method :post
611 * @time :2023/10/21 17:29 567 * @time :2023/10/21 17:29
612 */ 568 */
613 - public function getType($source,$is_list,$is_custom = 0){  
614 - $type = BTemplate::SOURCE_HOME;//首页公共头部底部 569 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  570 + if($template_id == 0){
  571 + return $this->success($source);
  572 + }
  573 + $type = BTemplate::SOURCE_COM;//公共头部底部
615 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 574 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
616 - if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部 575 + if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为公共头+底
617 return $this->success($type); 576 return $this->success($type);
618 } 577 }
619 //查看页面是否设置自定义头部底部 578 //查看页面是否设置自定义头部底部
620 - if($is_head != BTemplate::IS_NO_HEADER) {  
621 - $pageSettingModel = new PageSetting();  
622 - $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);  
623 - if ($pageInfo === false) {  
624 - return $this->success($type);  
625 - }  
626 - if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}  
627 - else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}  
628 - if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}  
629 - else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}  
630 - if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}  
631 - else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}  
632 - if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}} 579 + $pageSettingModel = new PageSetting();
  580 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
  581 + if ($pageInfo === false) {
  582 + return $this->success($type);
633 } 583 }
  584 + if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
  585 + if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
  586 + else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
  587 + if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
  588 + else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
  589 + if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
  590 + else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
  591 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::SOURCE_KEYWORD;}}
634 return $this->success($type); 592 return $this->success($type);
635 } 593 }
636 594
@@ -949,4 +907,37 @@ class BTemplateLogic extends BaseLogic @@ -949,4 +907,37 @@ class BTemplateLogic extends BaseLogic
949 } 907 }
950 return $this->success(); 908 return $this->success();
951 } 909 }
  910 +
  911 + /**
  912 + * @remark :定制页面头部类型---根据source获取type类型
  913 + * @name :getType
  914 + * @author :lyh
  915 + * @method :post
  916 + * @time :2023/11/16 11:20
  917 + */
  918 + public function getCustomizedType($source,$is_list){
  919 + $type = BTemplate::TYPE_HOME;
  920 + if($source == BTemplate::SOURCE_PRODUCT){
  921 + if($is_list == BTemplate::IS_LIST){
  922 + $type = BTemplate::TYPE_PRODUCT_LIST;
  923 + }else{
  924 + $type = BTemplate::TYPE_PRODUCT_DETAIL;
  925 + }
  926 + }
  927 + if($source == BTemplate::SOURCE_BLOG){
  928 + if($is_list == BTemplate::IS_LIST){
  929 + $type = BTemplate::TYPE_BLOG_LIST;
  930 + }else{
  931 + $type = BTemplate::TYPE_BLOG_DETAIL;
  932 + }
  933 + }
  934 + if($source == BTemplate::SOURCE_NEWS){
  935 + if($is_list == BTemplate::IS_LIST){
  936 + $type = BTemplate::TYPE_NEWS_LIST;
  937 + }else{
  938 + $type = BTemplate::TYPE_NEWS_DETAIL;
  939 + }
  940 + }
  941 + return $type;
  942 + }
952 } 943 }