作者 刘锟

Merge remote-tracking branch 'origin/master' into akun

@@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic
46 $source = $data['source']; 46 $source = $data['source'];
47 $source_id = $data['source_id']; 47 $source_id = $data['source_id'];
48 $type = $this->getType($source,$source_id); 48 $type = $this->getType($source,$source_id);
49 - $typeArray = [1,3,5,7];//单页数据 49 + $typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据
50 if(in_array($type,$typeArray)){ 50 if(in_array($type,$typeArray)){
51 $bTemplateModel = new BTemplate(); 51 $bTemplateModel = new BTemplate();
52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 52 $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
@@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic
67 return $this->success(['html'=>$html]); 67 return $this->success(['html'=>$html]);
68 } 68 }
69 69
  70 + /**
  71 + * @remark :根据type获取source类型
  72 + * @name :getSource
  73 + * @author :lyh
  74 + * @method :post
  75 + * @time :2023/12/6 11:25
  76 + */
70 public function getSource($type){ 77 public function getSource($type){
71 $source_id = 0; 78 $source_id = 0;
72 if ($type == 2){$source = 2;$source_id = 1; 79 if ($type == 2){$source = 2;$source_id = 1;
@@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic
98 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); 105 $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
99 if($templateInfo === false){ 106 if($templateInfo === false){
100 $data = [ 107 $data = [
101 - 'html'=>$this->param['html'],  
102 - 'project_id'=>$this->user['project_id'],  
103 - 'source'=>$source,  
104 - 'source_id'=>$source_id, 108 + 'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'],
  109 + 'source'=>$source, 'source_id'=>$source_id,
105 ]; 110 ];
106 $bTemplateModel->add($data); 111 $bTemplateModel->add($data);
107 }else{ 112 }else{
@@ -139,6 +144,20 @@ class VisualizationLogic extends BaseLogic @@ -139,6 +144,20 @@ class VisualizationLogic extends BaseLogic
139 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面 144 $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
140 //查看当前类型是否是定制界面 145 //查看当前类型是否是定制界面
141 if(in_array($type,$page_array)){//是定制界面 146 if(in_array($type,$page_array)){//是定制界面
  147 + return $this->getVisualizationHtml($type);
  148 + }else{//非定制界面
  149 + return $this->getTemplateHtml();
  150 + }
  151 + }
  152 +
  153 + /**
  154 + * @remark :定制界面获取html
  155 + * @name :getVisualizationHtml
  156 + * @author :lyh
  157 + * @method :post
  158 + * @time :2023/12/6 11:47
  159 + */
  160 + public function getVisualizationHtml($type){
142 if(in_array($type,[1,3,5,7])){//单页 161 if(in_array($type,[1,3,5,7])){//单页
143 $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块 162 $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
144 if($templateInfo === false){ 163 if($templateInfo === false){
@@ -155,9 +174,28 @@ class VisualizationLogic extends BaseLogic @@ -155,9 +174,28 @@ class VisualizationLogic extends BaseLogic
155 } 174 }
156 return ['html'=>$mainInfo['main_html']]; 175 return ['html'=>$mainInfo['main_html']];
157 } 176 }
158 - return ['html'=>$templateInfo['html']]; 177 + //替换为公共头部和底部
  178 + $templateCommonModel = new BTemplateCommon();
  179 + $headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  180 + $html = $templateInfo['html'];
  181 + if($headerFooterHtml !== false){
  182 + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html);
  183 + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html);
  184 + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html);
  185 + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html);
159 } 186 }
160 - }else{//非定制界面 187 + return ['html'=>$html];
  188 + }
  189 + }
  190 +
  191 + /**
  192 + * @remark :非定制项目获取html
  193 + * @name :getTemplateHtml
  194 + * @author :lyh
  195 + * @method :post
  196 + * @time :2023/12/6 11:44
  197 + */
  198 + public function getTemplateHtml(){
161 $bSettingModel = new Setting(); 199 $bSettingModel = new Setting();
162 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); 200 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
163 if($settingInfo === false){ 201 if($settingInfo === false){
@@ -179,8 +217,7 @@ class VisualizationLogic extends BaseLogic @@ -179,8 +217,7 @@ class VisualizationLogic extends BaseLogic
179 $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other']. 217 $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
180 $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html']; 218 $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
181 $html = $this->getHeadFooter($html); 219 $html = $this->getHeadFooter($html);
182 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']];  
183 - } 220 + return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]);
184 } 221 }
185 222
186 /** 223 /**
@@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic
226 } 263 }
227 264
228 /** 265 /**
229 - * @remark :获取类型 266 + * @remark :定制界面根据source+source_id获取type类型
230 * @name :getType 267 * @name :getType
231 * @author :lyh 268 * @author :lyh
232 * @method :post 269 * @method :post
@@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic
247 } 284 }
248 285
249 /** 286 /**
250 - * @remark :获取设置的类型 287 + * @remark :非定制获取设置头部底部的类型
251 * @name :getType 288 * @name :getType
252 * @author :lyh 289 * @author :lyh
253 * @method :post 290 * @method :post
@@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic
284 $type = $this->getType($this->param['source'],$this->param['source_id']); 321 $type = $this->getType($this->param['source'],$this->param['source_id']);
285 try { 322 try {
286 if(in_array($type,$page_array)){//定制页面 323 if(in_array($type,$page_array)){//定制页面
287 - $this->saveVisualizationHtml(); 324 + $this->saveVisualizationHtml($type);
288 }else{ 325 }else{
289 $this->saveTemplateHtml(); 326 $this->saveTemplateHtml();
290 } 327 }
@@ -301,24 +338,54 @@ class VisualizationLogic extends BaseLogic @@ -301,24 +338,54 @@ class VisualizationLogic extends BaseLogic
301 * @method :post 338 * @method :post
302 * @time :2023/12/5 15:42 339 * @time :2023/12/5 15:42
303 */ 340 */
304 - public function saveVisualizationHtml(){ 341 + public function saveVisualizationHtml($type){
305 $bTemplateModel = new BTemplate(); 342 $bTemplateModel = new BTemplate();
306 $templateInfo = $bTemplateModel->read([ 343 $templateInfo = $bTemplateModel->read([
307 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'], 344 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'],
308 'source_id'=>$this->param['source_id'], 'template_id'=>0 345 'source_id'=>$this->param['source_id'], 'template_id'=>0
309 ]); 346 ]);
  347 + try {
  348 + //更新头部底部
  349 + $this->visualizationSaveHeaderFooter($type);
310 if($templateInfo === false){ 350 if($templateInfo === false){
311 $this->param['project_id'] = $this->user['project_id']; 351 $this->param['project_id'] = $this->user['project_id'];
312 $this->param['template_id'] = 0; 352 $this->param['template_id'] = 0;
313 -// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
314 -// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
315 $bTemplateModel->add($this->param); 353 $bTemplateModel->add($this->param);
316 }else{ 354 }else{
317 -// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');  
318 -// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');  
319 $param['html'] = $this->param['html']; 355 $param['html'] = $this->param['html'];
320 $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]); 356 $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
321 } 357 }
  358 + }catch (\Exception $e){
  359 + $this->fail('系统错误,请联系管理员');
  360 + }
  361 + return $this->success();
  362 + }
  363 +
  364 + /**
  365 + * @remark :定制界面保存头部底部
  366 + * @name :visualizationSaveHeaderFooter
  367 + * @author :lyh
  368 + * @method :post
  369 + * @time :2023/12/6 10:41
  370 + */
  371 + public function visualizationSaveHeaderFooter($type){
  372 + //更新头部底部代码
  373 + $header_footer = [
  374 + 'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
  375 + 'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  376 + 'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  377 + 'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  378 + ];
  379 + $templateCommonModel = new BTemplateCommon();
  380 + $info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  381 + if($info === false){
  382 + $header_footer['template_id'] = 0;
  383 + $header_footer['project_id'] = $this->user['project_id'];
  384 + $header_footer['type'] = $type;
  385 + $templateCommonModel->add($header_footer);
  386 + }else{
  387 + $templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
  388 + }
322 return $this->success(); 389 return $this->success();
323 } 390 }
324 391