作者 lyh

gx

@@ -169,8 +169,10 @@ class CustomModuleContentController extends BaseController @@ -169,8 +169,10 @@ class CustomModuleContentController extends BaseController
169 public function sort(CustomModuleContentLogic $logic){ 169 public function sort(CustomModuleContentLogic $logic){
170 $this->request->validate([ 170 $this->request->validate([
171 'id'=>['required'], 171 'id'=>['required'],
  172 + 'sort'=>['required']
172 ],[ 173 ],[
173 'id.required' => 'ID不能为空', 174 'id.required' => 'ID不能为空',
  175 + 'sort.required' => '排序不能为空',
174 ]); 176 ]);
175 $logic->contentSort(); 177 $logic->contentSort();
176 $this->response('success'); 178 $this->response('success');
@@ -718,20 +718,8 @@ class BTemplateLogic extends BaseLogic @@ -718,20 +718,8 @@ class BTemplateLogic extends BaseLogic
718 if($bSettingInfo === false){ 718 if($bSettingInfo === false){
719 $this->fail('请先设置模板'); 719 $this->fail('请先设置模板');
720 } 720 }
721 - //获取首页公共部分  
722 - $templateCommonModel = new BTemplateCommon();  
723 - $commonInfo = $templateCommonModel->read(['template_id'=>$bSettingInfo['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);  
724 - if($commonInfo === false){  
725 - $this->fail('已装修的项目使用当前功能时,可视化保存首页数据一次,未装修首页请先装修首页');  
726 - }  
727 - //判断当前项目是否有设置独立头部的权限  
728 - if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {  
729 - //有权限时,获取独立头部  
730 - $commonTypeInfo = $templateCommonModel->read(['template_id'=>$bSettingInfo['template_id'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);  
731 - if($commonTypeInfo !== false){  
732 - $commonInfo = $commonTypeInfo;  
733 - }  
734 - } 721 + $is_custom = $this->param['is_custom'] ?? 0;//扩展模块详情模版
  722 + $commonInfo = $this->getTypeCommonHtml($bSettingInfo['template_id'],$is_custom);
735 //获取设置的默认中间部分 723 //获取设置的默认中间部分
736 $bTemplateMainModel = new BTemplateMain(); 724 $bTemplateMainModel = new BTemplateMain();
737 $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']]); 725 $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
@@ -749,6 +737,31 @@ class BTemplateLogic extends BaseLogic @@ -749,6 +737,31 @@ class BTemplateLogic extends BaseLogic
749 } 737 }
750 738
751 /** 739 /**
  740 + * @remark :根据type获取html
  741 + * @name :getHeaderFooter
  742 + * @author :lyh
  743 + * @method :post
  744 + * @time :2023/12/15 18:06
  745 + */
  746 + public function getTypeCommonHtml($template_id,$is_custom){
  747 + //获取首页公共部分
  748 + $templateCommonModel = new BTemplateCommon();
  749 + $commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>1]);
  750 + //判断当前项目是否有设置独立头部的权限
  751 + if($is_custom == BTemplate::SOURCE_CUSTOM){
  752 + return $this->success($commonInfo);
  753 + }
  754 + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
  755 + //有权限时,获取独立头部
  756 + $commonTypeInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
  757 + if($commonTypeInfo !== false){
  758 + $commonInfo = $commonTypeInfo;
  759 + }
  760 + }
  761 + return $this->success($commonInfo);
  762 + }
  763 +
  764 + /**
752 * @remark :保存详情模板数据 765 * @remark :保存详情模板数据
753 * @name :saveDetail 766 * @name :saveDetail
754 * @author :lyh 767 * @author :lyh
@@ -761,6 +774,7 @@ class BTemplateLogic extends BaseLogic @@ -761,6 +774,7 @@ class BTemplateLogic extends BaseLogic
761 if($bSettingInfo === false){ 774 if($bSettingInfo === false){
762 $this->fail('请先设置模板'); 775 $this->fail('请先设置模板');
763 } 776 }
  777 + $is_custom = $this->param['is_custom'] ?? 0;//扩展模块详情模版
764 $data = [ 778 $data = [
765 'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'), 779 'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
766 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'), 780 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
@@ -768,37 +782,53 @@ class BTemplateLogic extends BaseLogic @@ -768,37 +782,53 @@ class BTemplateLogic extends BaseLogic
768 $data['section_list_id'] = $this->param['section_list_id']; 782 $data['section_list_id'] = $this->param['section_list_id'];
769 //保存中间部分 783 //保存中间部分
770 $bTemplateMainModel = new BTemplateMain(); 784 $bTemplateMainModel = new BTemplateMain();
771 - $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']]); 785 + $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom]);
772 if($mainInfo === false){ 786 if($mainInfo === false){
773 $data['project_id'] = $this->user['project_id']; 787 $data['project_id'] = $this->user['project_id'];
774 $data['type'] = $this->param['type']; 788 $data['type'] = $this->param['type'];
  789 + $data['is_custom'] = $is_custom;
775 $bTemplateMainModel->add($data); 790 $bTemplateMainModel->add($data);
776 }else{ 791 }else{
777 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]); 792 $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
778 } 793 }
  794 + $this->saveDetailCommonHtml($is_custom,$this->param['type'],$bSettingInfo['template_id'],$this->param['html']);
  795 + return $this->success();
  796 + }
  797 +
  798 + /**
  799 + * @remark :保存详情页模版头部底部
  800 + * @name :saveDetailCommonHtml
  801 + * @author :lyh
  802 + * @method :post
  803 + * @time :2023/12/15 18:12
  804 + */
  805 + public function saveDetailCommonHtml($is_custom,$type,$template_id,$html){
779 $publicData = [ 806 $publicData = [
780 - 'head_html' => characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),  
781 - 'head_css' => characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),  
782 - 'footer_html' => characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),  
783 - 'footer_css' => characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),  
784 - 'other'=>str_replace('<header','',characterTruncation($this->param['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")), 807 + 'head_html' => characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
  808 + 'head_css' => characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  809 + 'footer_html' => characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  810 + 'footer_css' => characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  811 + 'other'=>str_replace('<header','',characterTruncation($html,"/<link id=\"google-fonts-link\"(.*?)<header/s")),
785 ]; 812 ];
786 //查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部 813 //查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
  814 + if($is_custom == BTemplate::SOURCE_CUSTOM){//扩展模块
  815 + $this->user['configuration']['is_head'] = BTemplate::SOURCE_NO_CUSTOM;
  816 + }
787 $templateCommonModel = new BTemplateCommon(); 817 $templateCommonModel = new BTemplateCommon();
788 if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) { 818 if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
789 - $templateCommonInfo = $templateCommonModel->read(['type'=>$this->param['type'],'project_id'=>$this->user['project_id'],'template_id'=>$bSettingInfo['template_id']]); 819 + $templateCommonInfo = $templateCommonModel->read(['type'=>$type,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
790 if($templateCommonInfo === false){ 820 if($templateCommonInfo === false){
791 - $publicData['type'] = $this->param['type']; 821 + $publicData['type'] = $type;
792 $publicData['project_id'] = $this->user['project_id']; 822 $publicData['project_id'] = $this->user['project_id'];
793 - $publicData['template_id'] = $bSettingInfo['template_id']; 823 + $publicData['template_id'] = $template_id;
794 $templateCommonModel->add($publicData); 824 $templateCommonModel->add($publicData);
795 }else{ 825 }else{
796 $templateCommonModel->edit($publicData,['id'=>$templateCommonInfo['id']]); 826 $templateCommonModel->edit($publicData,['id'=>$templateCommonInfo['id']]);
797 } 827 }
798 }else{ 828 }else{
799 //更新首页头部底部 829 //更新首页头部底部
800 - $templateCommonModel->edit($publicData,['type'=>1,'project_id'=>$this->user['project_id'],'template_id'=>$bSettingInfo['template_id']]); 830 + $templateCommonModel->edit($publicData,['type'=>1,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
801 } 831 }
802 - return $this->success(); 832 + return true;
803 } 833 }
804 } 834 }