正在显示
1 个修改的文件
包含
46 行增加
和
61 行删除
| @@ -57,10 +57,9 @@ class VisualizationLogic extends BaseLogic | @@ -57,10 +57,9 @@ class VisualizationLogic extends BaseLogic | ||
| 57 | * @time :2023/11/15 11:30 | 57 | * @time :2023/11/15 11:30 |
| 58 | */ | 58 | */ |
| 59 | public function getHtml(){ | 59 | public function getHtml(){ |
| 60 | - //查询可视化是否第一次保存 | ||
| 61 | $TemplateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']); | 60 | $TemplateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']); |
| 62 | $type = $this->getType($this->param['source'],$this->param['source_id']); | 61 | $type = $this->getType($this->param['source'],$this->param['source_id']); |
| 63 | - $page_array = $this->user['is_visualization']['page_array']; | 62 | + $page_array = (array)$this->user['is_visualization']->page_array; |
| 64 | if($TemplateInfo === false){ | 63 | if($TemplateInfo === false){ |
| 65 | if(in_array($type,$page_array)){//定制页面 | 64 | if(in_array($type,$page_array)){//定制页面 |
| 66 | $info = $this->model->read(['source'=>$type],['html','source','id','project_id']); | 65 | $info = $this->model->read(['source'=>$type],['html','source','id','project_id']); |
| @@ -74,15 +73,19 @@ class VisualizationLogic extends BaseLogic | @@ -74,15 +73,19 @@ class VisualizationLogic extends BaseLogic | ||
| 74 | if($settingInfo === false){ | 73 | if($settingInfo === false){ |
| 75 | $this->fail('请先选择模版'); | 74 | $this->fail('请先选择模版'); |
| 76 | } | 75 | } |
| 77 | - $ATemplateModel = new Template(); | ||
| 78 | - $aTemplateInfo = $ATemplateModel->read(['id'=>$settingInfo['template_id']]); | ||
| 79 | - //截取链接部分 | ||
| 80 | - $other = str_replace('<header','',characterTruncation($aTemplateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")); | 76 | + //获取公共头部底部 |
| 77 | + $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']); | ||
| 78 | + if($commonInfo === false){ | ||
| 79 | + //保存一次首页头部底部 | ||
| 80 | + $ATemplateModel = new Template(); | ||
| 81 | + $aTemplateInfo = $ATemplateModel->read(['id'=>$settingInfo['template_id']]); | ||
| 82 | + $commonInfo = $this->saveHomeHeaderFooter($settingInfo['template_id'],$aTemplateInfo); | ||
| 83 | + } | ||
| 81 | //根据类型在获取中间部分 | 84 | //根据类型在获取中间部分 |
| 82 | $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']); | 85 | $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']); |
| 83 | //拼接数据 | 86 | //拼接数据 |
| 84 | - $html = $aTemplateInfo['head_css'].$mainData['main_css'].$aTemplateInfo['footer_css'].$other. | ||
| 85 | - $aTemplateInfo['head_html'].$mainData['main_html'].$aTemplateInfo['footer_html']; | 87 | + $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other']. |
| 88 | + $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html']; | ||
| 86 | return $html; | 89 | return $html; |
| 87 | } | 90 | } |
| 88 | }else{ | 91 | }else{ |
| @@ -172,7 +175,6 @@ class VisualizationLogic extends BaseLogic | @@ -172,7 +175,6 @@ class VisualizationLogic extends BaseLogic | ||
| 172 | * @time :2023/11/15 11:47 | 175 | * @time :2023/11/15 11:47 |
| 173 | */ | 176 | */ |
| 174 | public function saveHtml(){ | 177 | public function saveHtml(){ |
| 175 | - @file_put_contents(storage_path('logs/lyh_error.log'), var_export(11111, true) . PHP_EOL, FILE_APPEND); | ||
| 176 | $page_array = (array)$this->user['is_visualization']->page_array; | 178 | $page_array = (array)$this->user['is_visualization']->page_array; |
| 177 | $type = $this->getType($this->param['source'],$this->param['source_id']); | 179 | $type = $this->getType($this->param['source'],$this->param['source_id']); |
| 178 | if(in_array($type,$page_array)){//定制页面 | 180 | if(in_array($type,$page_array)){//定制页面 |
| @@ -192,6 +194,8 @@ class VisualizationLogic extends BaseLogic | @@ -192,6 +194,8 @@ class VisualizationLogic extends BaseLogic | ||
| 192 | ]); | 194 | ]); |
| 193 | $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | 195 | $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); |
| 194 | $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | 196 | $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); |
| 197 | + //保存头部 | ||
| 198 | + $this->saveCommonTemplate($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id']); | ||
| 195 | } | 199 | } |
| 196 | try { | 200 | try { |
| 197 | if($templateInfo === false){ | 201 | if($templateInfo === false){ |
| @@ -214,19 +218,19 @@ class VisualizationLogic extends BaseLogic | @@ -214,19 +218,19 @@ class VisualizationLogic extends BaseLogic | ||
| 214 | * @method :post | 218 | * @method :post |
| 215 | * @time :2023/10/13 14:27 | 219 | * @time :2023/10/13 14:27 |
| 216 | */ | 220 | */ |
| 217 | - public function saveCommonTemplate($param){ | ||
| 218 | - $type = $this->getSaveType($param['source'],$param['source_id']); | 221 | + public function saveCommonTemplate($html,$source,$source_id,$template_id){ |
| 222 | + $type = $this->getSaveType($source,$source_id); | ||
| 219 | $templateCommonModel = new BTemplateCommon(); | 223 | $templateCommonModel = new BTemplateCommon(); |
| 220 | - $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id'],'type'=>$type]); | 224 | + $info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]); |
| 221 | $data = [ | 225 | $data = [ |
| 222 | - 'head_html'=>$param['head_html'], | ||
| 223 | - 'head_css'=>$param['head_css'], | ||
| 224 | - 'footer_html'=>$param['footer_html'], | ||
| 225 | - 'footer_css'=>$param['footer_css'], | 226 | + 'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'), |
| 227 | + 'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'), | ||
| 228 | + 'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'), | ||
| 229 | + 'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'), | ||
| 226 | ]; | 230 | ]; |
| 227 | - $other = str_replace('<header','',characterTruncation($param['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")); | 231 | + $other = str_replace('<header','',characterTruncation($html,"/<link id=\"google-fonts-link\"(.*?)<header/s")); |
| 228 | if($info === false){ | 232 | if($info === false){ |
| 229 | - $data['template_id'] = $param['template_id']; | 233 | + $data['template_id'] = $template_id; |
| 230 | $data['project_id'] = $this->user['project_id']; | 234 | $data['project_id'] = $this->user['project_id']; |
| 231 | $data['type'] = $type; | 235 | $data['type'] = $type; |
| 232 | $templateCommonModel->add($data); | 236 | $templateCommonModel->add($data); |
| @@ -239,49 +243,6 @@ class VisualizationLogic extends BaseLogic | @@ -239,49 +243,6 @@ class VisualizationLogic extends BaseLogic | ||
| 239 | } | 243 | } |
| 240 | 244 | ||
| 241 | /** | 245 | /** |
| 242 | - * @remark :字符串处理 | ||
| 243 | - * @name :StringProcessing | ||
| 244 | - * @author :lyh | ||
| 245 | - * @method :post | ||
| 246 | - * @time :2023/6/29 15:35 | ||
| 247 | - */ | ||
| 248 | - public function stringProcessing($param){ | ||
| 249 | - //字符串截取 | ||
| 250 | - $param['head_html'] = characterTruncation($param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'); | ||
| 251 | - $param['main_html'] = characterTruncation($param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 252 | - $param['footer_html'] = characterTruncation($param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'); | ||
| 253 | - $param['head_css'] = characterTruncation($param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'); | ||
| 254 | - $param['main_css'] = characterTruncation($param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 255 | - $param['footer_css'] = characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'); | ||
| 256 | - return $this->success($param); | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - /** | ||
| 260 | - * @remark :保存首页头部底部信息 | ||
| 261 | - * @name :saveHomeHeaderFooter | ||
| 262 | - * @author :lyh | ||
| 263 | - * @method :post | ||
| 264 | - * @time :2023/11/16 11:14 | ||
| 265 | - */ | ||
| 266 | - public function saveHomeHeaderFooter($template_id,$aTemplateInfo){ | ||
| 267 | - $data = [ | ||
| 268 | - 'other'=>str_replace('<header','',characterTruncation($aTemplateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")), | ||
| 269 | - 'head_html'=>$aTemplateInfo['head_html'], | ||
| 270 | - 'footer_html'=>$aTemplateInfo['footer_html'], | ||
| 271 | - 'head_css'=>$aTemplateInfo['head_css'], | ||
| 272 | - 'footer_css'=>$aTemplateInfo['footer_css'], | ||
| 273 | - 'template_id'=>$template_id, | ||
| 274 | - 'project_id'=>$this->user['project_id'], | ||
| 275 | - 'type'=>1, | ||
| 276 | - ]; | ||
| 277 | - //保存首页头部信息 | ||
| 278 | - $templateCommonModel = new BTemplateCommon(); | ||
| 279 | - //查询头部是否存在 | ||
| 280 | - $templateCommonModel->add($data); | ||
| 281 | - return $this->success(); | ||
| 282 | - } | ||
| 283 | - | ||
| 284 | - /** | ||
| 285 | * @remark :获取中间公共部分 | 246 | * @remark :获取中间公共部分 |
| 286 | * @name :getCommonMain | 247 | * @name :getCommonMain |
| 287 | * @author :lyh | 248 | * @author :lyh |
| @@ -359,4 +320,28 @@ class VisualizationLogic extends BaseLogic | @@ -359,4 +320,28 @@ class VisualizationLogic extends BaseLogic | ||
| 359 | } | 320 | } |
| 360 | return $commonInfo; | 321 | return $commonInfo; |
| 361 | } | 322 | } |
| 323 | + | ||
| 324 | + /** | ||
| 325 | + * @remark :保存首页头部底部信息 | ||
| 326 | + * @name :saveHomeHeaderFooter | ||
| 327 | + * @author :lyh | ||
| 328 | + * @method :post | ||
| 329 | + * @time :2023/11/16 11:14 | ||
| 330 | + */ | ||
| 331 | + public function saveHomeHeaderFooter($template_id,$aTemplateInfo){ | ||
| 332 | + $data = [ | ||
| 333 | + 'other'=>str_replace('<header','',characterTruncation($aTemplateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")), | ||
| 334 | + 'head_html'=>$aTemplateInfo['head_html'], | ||
| 335 | + 'footer_html'=>$aTemplateInfo['footer_html'], | ||
| 336 | + 'head_css'=>$aTemplateInfo['head_css'], | ||
| 337 | + 'footer_css'=>$aTemplateInfo['footer_css'], | ||
| 338 | + 'template_id'=>$template_id, | ||
| 339 | + 'project_id'=>$this->user['project_id'], | ||
| 340 | + 'type'=>1, | ||
| 341 | + ]; | ||
| 342 | + //保存首页头部信息 | ||
| 343 | + $templateCommonModel = new BTemplateCommon(); | ||
| 344 | + $templateCommonModel->add($data); | ||
| 345 | + return $this->success($data); | ||
| 346 | + } | ||
| 362 | } | 347 | } |
-
请 注册 或 登录 后发表评论