作者 lyh

gx

@@ -13,6 +13,7 @@ use App\Http\Logic\Bside\BaseLogic; @@ -13,6 +13,7 @@ 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;
16 use App\Models\Template\BTemplateCommon; 17 use App\Models\Template\BTemplateCommon;
17 use App\Models\Template\BTemplateLog; 18 use App\Models\Template\BTemplateLog;
18 use App\Models\Template\Setting; 19 use App\Models\Template\Setting;
@@ -64,13 +65,18 @@ class BTemplateLogLogic extends BaseLogic @@ -64,13 +65,18 @@ class BTemplateLogLogic extends BaseLogic
64 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']]; 65 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
65 //TODO::还原头部+底部 66 //TODO::还原头部+底部
66 $bTemplateModel->edit(['html'=>$info['text']],$condition); 67 $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']);  
72 - $commonTemplateModel = new BTemplateCommon();  
73 - $commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]); 68 + $commonTemplateModel = new BTemplateCom();
  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(['html'=>$info['head_html'], 'html_style'=>$info['head_css']],$condition);
  74 + $condition['common_type'] = BTemplate::COMMON_FOOTER;
  75 + $commonTemplateModel->edit(['html'=>$info['footer_html'], 'html_style'=>$info['footer_css']],$condition);
  76 + $footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s'));
  77 + $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
  78 + $condition['common_type'] = BTemplate::COMMON_OTHER;
  79 + $commonTemplateModel->edit(['html'=>$other, 'html_style'=>''],$condition);
74 return $this->success(); 80 return $this->success();
75 } 81 }
76 82
@@ -99,18 +105,9 @@ class BTemplateLogLogic extends BaseLogic @@ -99,18 +105,9 @@ class BTemplateLogLogic extends BaseLogic
99 $bTemplateModel->edit($data,$condition); 105 $bTemplateModel->edit($data,$condition);
100 //还原头部+底部 106 //还原头部+底部
101 $commonData = [ 107 $commonData = [
102 - 'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css'] 108 + 'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_style'=>$info['footer_css'],'other'=>$info['other']
103 ]; 109 ];
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 - } 110 + $this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']);
114 }catch (\Exception $e){ 111 }catch (\Exception $e){
115 $this->fail('系统错误,请联系管理员'); 112 $this->fail('系统错误,请联系管理员');
116 } 113 }
@@ -118,36 +115,40 @@ class BTemplateLogLogic extends BaseLogic @@ -118,36 +115,40 @@ class BTemplateLogLogic extends BaseLogic
118 } 115 }
119 116
120 /** 117 /**
121 - * @remark :定制页面头部类型---根据source获取type类型  
122 - * @name :getType 118 + * @remark :保存公共部分(头部。底部。连接部分)
  119 + * @name :saveTemplateCom
123 * @author :lyh 120 * @author :lyh
124 * @method :post 121 * @method :post
125 - * @time :2023/11/16 11:20 122 + * @time :2024/4/29 10:32
126 */ 123 */
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{  
133 - $type = BTemplate::TYPE_PRODUCT_DETAIL;  
134 - }  
135 - }  
136 - if($source == BTemplate::SOURCE_BLOG){  
137 - if($is_list == BTemplate::IS_LIST){  
138 - $type = BTemplate::TYPE_BLOG_LIST; 124 + public function saveTemplateCom($handleInfo,$template_id,$source,$is_list,$is_custom){
  125 + $typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
  126 + $templateComModel = new BTemplateCom();
  127 + foreach ($typeArr as $type){
  128 + if($type == BTemplate::COMMON_HEAD){
  129 + $param['html'] = $handleInfo['head_html'];
  130 + $param['html_style'] = $handleInfo['head_style'];
  131 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
  132 + }elseif ($type == BTemplate::COMMON_FOOTER){
  133 + $param['html'] = $handleInfo['footer_html'];
  134 + $param['html_style'] = $handleInfo['footer_style'];
  135 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
139 }else{ 136 }else{
140 - $type = BTemplate::TYPE_BLOG_DETAIL; 137 + $param['html'] = $handleInfo['other'];
  138 + $param['html_style'] = null;
  139 + $typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
141 } 140 }
142 - }  
143 - if($source == BTemplate::SOURCE_NEWS){  
144 - if($is_list == BTemplate::IS_LIST){  
145 - $type = BTemplate::TYPE_NEWS_LIST; 141 + //查看当前数据是否还存在
  142 + $condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
  143 + $info = $templateComModel->read($condition);
  144 + if($info === false){
  145 + $data = array_merge($param,$condition);
  146 + $templateComModel->add($data);
146 }else{ 147 }else{
147 - $type = BTemplate::TYPE_NEWS_DETAIL; 148 + $templateComModel->edit($param,$condition);
148 } 149 }
149 } 150 }
150 - return $type; 151 + return $this->success();
151 } 152 }
152 153
153 /** 154 /**
@@ -157,27 +158,30 @@ class BTemplateLogLogic extends BaseLogic @@ -157,27 +158,30 @@ class BTemplateLogLogic extends BaseLogic
157 * @method :post 158 * @method :post
158 * @time :2023/10/21 17:29 159 * @time :2023/10/21 17:29
159 */ 160 */
160 - public function getType($source,$is_list,$is_custom = 0){  
161 - $type = BTemplate::SOURCE_HOME;//首页公共头部底部 161 + public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
  162 + if($template_id == 0){//定制全为独立头部和底部
  163 + $type = $source;
  164 + return $this->success($type);
  165 + }
  166 + $type = BTemplate::SOURCE_COM;//公共头部底部
162 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER; 167 $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
163 - if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部 168 + if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
164 return $this->success($type); 169 return $this->success($type);
165 } 170 }
166 //查看页面是否设置自定义头部底部 171 //查看页面是否设置自定义头部底部
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 + $pageSettingModel = new PageSetting();
  173 + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
  174 + if ($pageInfo === false) {
  175 + return $this->success($type);
180 } 176 }
  177 + if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
  178 + if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
  179 + else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
  180 + if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
  181 + else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
  182 + if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
  183 + else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
  184 + if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
181 return $this->success($type); 185 return $this->success($type);
182 } 186 }
183 187