正在显示
2 个修改的文件
包含
268 行增加
和
16 行删除
| @@ -10,8 +10,13 @@ | @@ -10,8 +10,13 @@ | ||
| 10 | namespace App\Http\Logic\Bside\BTemplate; | 10 | namespace App\Http\Logic\Bside\BTemplate; |
| 11 | 11 | ||
| 12 | use App\Http\Logic\Bside\BaseLogic; | 12 | use App\Http\Logic\Bside\BaseLogic; |
| 13 | +use App\Models\Project\PageSetting; | ||
| 13 | use App\Models\Template\BTemplate; | 14 | use App\Models\Template\BTemplate; |
| 14 | use App\Models\Template\BTemplateCommon; | 15 | use App\Models\Template\BTemplateCommon; |
| 16 | +use App\Models\Template\BTemplateMain; | ||
| 17 | +use App\Models\Template\Setting; | ||
| 18 | +use App\Models\Template\Template; | ||
| 19 | +use App\Models\Template\TemplateTypeMain; | ||
| 15 | use App\Models\Visualization\Visualization; | 20 | use App\Models\Visualization\Visualization; |
| 16 | 21 | ||
| 17 | class VisualizationLogic extends BaseLogic | 22 | class VisualizationLogic extends BaseLogic |
| @@ -45,7 +50,7 @@ class VisualizationLogic extends BaseLogic | @@ -45,7 +50,7 @@ class VisualizationLogic extends BaseLogic | ||
| 45 | } | 50 | } |
| 46 | 51 | ||
| 47 | /** | 52 | /** |
| 48 | - * @remark :可视化装修获取html | 53 | + * @remark :定制页面支持可视化装修获取html |
| 49 | * @name :getHtml | 54 | * @name :getHtml |
| 50 | * @author :lyh | 55 | * @author :lyh |
| 51 | * @method :post | 56 | * @method :post |
| @@ -53,29 +58,112 @@ class VisualizationLogic extends BaseLogic | @@ -53,29 +58,112 @@ class VisualizationLogic extends BaseLogic | ||
| 53 | */ | 58 | */ |
| 54 | public function getHtml(){ | 59 | public function getHtml(){ |
| 55 | //查询可视化是否第一次保存 | 60 | //查询可视化是否第一次保存 |
| 61 | + $TemplateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']); | ||
| 62 | + $type = $this->getType($this->param['source'],$this->param['source_id']); | ||
| 63 | + $page_array = $this->user['is_visualization']['page_array']; | ||
| 64 | + if($TemplateInfo === false){ | ||
| 65 | + if(in_array($type,$page_array)){//定制页面 | ||
| 66 | + $info = $this->model->read(['source'=>$type],['html','source','id','project_id']); | ||
| 67 | + if($info === false){ | ||
| 68 | + $this->fail('请先上传定制代码块'); | ||
| 69 | + } | ||
| 70 | + return $info['html']; | ||
| 71 | + }else{//非定制界面 | ||
| 72 | + $bSettingModel = new Setting(); | ||
| 73 | + $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); | ||
| 74 | + if($settingInfo === false){ | ||
| 75 | + $this->fail('请先选择模版'); | ||
| 76 | + } | ||
| 77 | + $ATemplateModel = new Template(); | ||
| 78 | + $aTemplateInfo = $ATemplateModel->read(['id'=>$settingInfo['template_id']]); | ||
| 79 | + //保存一次公共头部底部 | ||
| 80 | + $this->saveHomeHeaderFooter($settingInfo['template_id'],$aTemplateInfo); | ||
| 81 | + //截取链接部分 | ||
| 82 | + $other = str_replace('<header','',characterTruncation($aTemplateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")); | ||
| 83 | + //根据类型在获取中间部分 | ||
| 84 | + $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']); | ||
| 85 | + //拼接数据 | ||
| 86 | + $html = $aTemplateInfo['head_css'].$mainData['main_css'].$aTemplateInfo['footer_css'].$other. | ||
| 87 | + $aTemplateInfo['head_html'].$mainData['main_html'].$aTemplateInfo['footer_html']; | ||
| 88 | + return $html; | ||
| 89 | + } | ||
| 90 | + }else{ | ||
| 91 | + if($TemplateInfo['template_id'] != 0){ | ||
| 92 | + $bSettingModel = new Setting(); | ||
| 93 | + $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); | ||
| 94 | + if($settingInfo === false){ | ||
| 95 | + $this->fail('请先选择模版'); | ||
| 96 | + } | ||
| 97 | + //获取头部信息 | ||
| 98 | + $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']); | ||
| 99 | + $html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other']. | ||
| 100 | + $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html']; | ||
| 101 | + return $html; | ||
| 102 | + }else{ | ||
| 103 | + return $TemplateInfo['html']; | ||
| 104 | + } | ||
| 105 | + } | ||
| 106 | + } | ||
| 107 | + | ||
| 108 | + /** | ||
| 109 | + * @remark :获取可视化装修记录 | ||
| 110 | + * @name :getWebTemplate | ||
| 111 | + * @author :lyh | ||
| 112 | + * @method :post | ||
| 113 | + * @time :2023/11/16 11:21 | ||
| 114 | + */ | ||
| 115 | + public function getWebTemplate($source,$source_id){ | ||
| 116 | + //查询可视化是否第一次保存 | ||
| 56 | $bTemplateModel = new BTemplate(); | 117 | $bTemplateModel = new BTemplate(); |
| 57 | - $TemplateInfo = $bTemplateModel->read([ | ||
| 58 | - 'source'=>$this->param['source'], | 118 | + return $bTemplateModel->read([ |
| 119 | + 'source'=>$source, | ||
| 59 | 'project_id'=>$this->user['project_id'], | 120 | 'project_id'=>$this->user['project_id'], |
| 60 | - 'source_id'=>$this->param['source_id'], | 121 | + 'source_id'=>$source_id, |
| 61 | ]); | 122 | ]); |
| 62 | - if($this->param['source'] == 2){ | ||
| 63 | - if($this->param['source_id'] == 0){$source = 3;}else{$source = 2;} | ||
| 64 | } | 123 | } |
| 65 | - if($this->param['source'] == 3){ | ||
| 66 | - if($this->param['source_id'] == 0){$source = 5;}else{$source = 4;} | 124 | + |
| 125 | + /** | ||
| 126 | + * @remark :获取类型 | ||
| 127 | + * @name :getType | ||
| 128 | + * @author :lyh | ||
| 129 | + * @method :post | ||
| 130 | + * @time :2023/11/16 11:20 | ||
| 131 | + */ | ||
| 132 | + public function getType($source,$source_id){ | ||
| 133 | + $type = 1; | ||
| 134 | + if($source == 2){ | ||
| 135 | + if($source_id == 0){$type = 3;}else{$type = 2;} | ||
| 136 | + } | ||
| 137 | + if($source == 3){ | ||
| 138 | + if($source_id == 0){$type = 5;}else{$type = 4;} | ||
| 67 | } | 139 | } |
| 68 | - if($this->param['source'] == 4){ | ||
| 69 | - if($this->param['source_id'] == 0){$source = 7;}else{$source = 6;} | 140 | + if($source == 4){ |
| 141 | + if($source_id == 0){$type = 7;}else{$type = 6;} | ||
| 70 | } | 142 | } |
| 71 | - if($TemplateInfo === false){ | ||
| 72 | - $info = $this->model->read(['source'=>$source],['html','source','id','project_id']); | ||
| 73 | - if($info === false){ | ||
| 74 | - $this->fail('请先上传定制代码块'); | 143 | + return $type; |
| 75 | } | 144 | } |
| 76 | - return $info['html']; | 145 | + |
| 146 | + /** | ||
| 147 | + * @remark :获取设置的类型 | ||
| 148 | + * @name :getType | ||
| 149 | + * @author :lyh | ||
| 150 | + * @method :post | ||
| 151 | + * @time :2023/10/21 17:29 | ||
| 152 | + */ | ||
| 153 | + public function getSaveType($source,$source_id){ | ||
| 154 | + $type = 1;//首页公共头部底部 | ||
| 155 | + //查看页面是否设置自定义头部底部 | ||
| 156 | + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) { | ||
| 157 | + $pageSettingModel = new PageSetting(); | ||
| 158 | + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]); | ||
| 159 | + if ($pageInfo !== false) { | ||
| 160 | + if ($source == 2) {if ($source_id != 0) {if ($pageInfo['product_details'] != 0) {$type = 2;}} else {if ($pageInfo['product_list'] != 0) {$type = 3;}}} | ||
| 161 | + if ($source == 3) {if ($source_id != 0) {if ($pageInfo['blog_details'] != 0) {$type = 4;}} else {if ($pageInfo['blog_list'] != 0) {$type = 5;}}} | ||
| 162 | + if ($source == 4) {if ($source_id != 0) {if ($pageInfo['news_details'] != 0) {$type = 6;}} else {if ($pageInfo['news_list'] != 0) {$type = 7;}}} | ||
| 163 | + if ($source == 5) {if ($pageInfo['polymerization'] != 0) {$type = 8;}} | ||
| 77 | } | 164 | } |
| 78 | - return $TemplateInfo['html']; | 165 | + } |
| 166 | + return $type; | ||
| 79 | } | 167 | } |
| 80 | 168 | ||
| 81 | /** | 169 | /** |
| @@ -86,12 +174,26 @@ class VisualizationLogic extends BaseLogic | @@ -86,12 +174,26 @@ class VisualizationLogic extends BaseLogic | ||
| 86 | * @time :2023/11/15 11:47 | 174 | * @time :2023/11/15 11:47 |
| 87 | */ | 175 | */ |
| 88 | public function saveHtml(){ | 176 | public function saveHtml(){ |
| 177 | + $page_array = $this->user['is_visualization']['page_array']; | ||
| 178 | + $type = $this->getType($this->param['source'],$this->param['source_id']); | ||
| 179 | + if(in_array($type,$page_array)){//定制页面 | ||
| 180 | + $bTemplateModel = new BTemplate(); | ||
| 181 | + $templateInfo = $bTemplateModel->read([ | ||
| 182 | + 'source'=>$this->param['source'], | ||
| 183 | + 'project_id'=>$this->user['project_id'], | ||
| 184 | + 'source_id'=>$this->param['source_id'], | ||
| 185 | + ]); | ||
| 186 | + }else{ | ||
| 89 | $bTemplateModel = new BTemplate(); | 187 | $bTemplateModel = new BTemplate(); |
| 90 | $templateInfo = $bTemplateModel->read([ | 188 | $templateInfo = $bTemplateModel->read([ |
| 91 | 'source'=>$this->param['source'], | 189 | 'source'=>$this->param['source'], |
| 92 | 'project_id'=>$this->user['project_id'], | 190 | 'project_id'=>$this->user['project_id'], |
| 93 | 'source_id'=>$this->param['source_id'], | 191 | 'source_id'=>$this->param['source_id'], |
| 192 | + 'template_id'=>$this->param['template_id'], | ||
| 94 | ]); | 193 | ]); |
| 194 | + $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 195 | + $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 196 | + } | ||
| 95 | try { | 197 | try { |
| 96 | if($templateInfo === false){ | 198 | if($templateInfo === false){ |
| 97 | $this->param['project_id'] = $this->user['project_id']; | 199 | $this->param['project_id'] = $this->user['project_id']; |
| @@ -106,6 +208,155 @@ class VisualizationLogic extends BaseLogic | @@ -106,6 +208,155 @@ class VisualizationLogic extends BaseLogic | ||
| 106 | 208 | ||
| 107 | } | 209 | } |
| 108 | 210 | ||
| 211 | + /** | ||
| 212 | + * @remark :保存头部公共数据 | ||
| 213 | + * @name :saveCommonTemplate | ||
| 214 | + * @author :lyh | ||
| 215 | + * @method :post | ||
| 216 | + * @time :2023/10/13 14:27 | ||
| 217 | + */ | ||
| 218 | + public function saveCommonTemplate($param){ | ||
| 219 | + $type = $this->getSaveType($param['source'],$param['source_id']); | ||
| 220 | + $templateCommonModel = new BTemplateCommon(); | ||
| 221 | + $info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id'],'type'=>$type]); | ||
| 222 | + $data = [ | ||
| 223 | + 'head_html'=>$param['head_html'], | ||
| 224 | + 'head_css'=>$param['head_css'], | ||
| 225 | + 'footer_html'=>$param['footer_html'], | ||
| 226 | + 'footer_css'=>$param['footer_css'], | ||
| 227 | + ]; | ||
| 228 | + $other = str_replace('<header','',characterTruncation($param['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")); | ||
| 229 | + if($info === false){ | ||
| 230 | + $data['template_id'] = $param['template_id']; | ||
| 231 | + $data['project_id'] = $this->user['project_id']; | ||
| 232 | + $data['type'] = $type; | ||
| 233 | + $templateCommonModel->add($data); | ||
| 234 | + }else{ | ||
| 235 | + $templateCommonModel->edit($data,['id'=>$info['id']]); | ||
| 236 | + } | ||
| 237 | + //更新所有界面的other | ||
| 238 | + $templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]); | ||
| 239 | + return $this->success(); | ||
| 240 | + } | ||
| 109 | 241 | ||
| 242 | + /** | ||
| 243 | + * @remark :字符串处理 | ||
| 244 | + * @name :StringProcessing | ||
| 245 | + * @author :lyh | ||
| 246 | + * @method :post | ||
| 247 | + * @time :2023/6/29 15:35 | ||
| 248 | + */ | ||
| 249 | + public function stringProcessing($param){ | ||
| 250 | + //字符串截取 | ||
| 251 | + $param['head_html'] = characterTruncation($param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'); | ||
| 252 | + $param['main_html'] = characterTruncation($param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 253 | + $param['footer_html'] = characterTruncation($param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'); | ||
| 254 | + $param['head_css'] = characterTruncation($param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'); | ||
| 255 | + $param['main_css'] = characterTruncation($param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 256 | + $param['footer_css'] = characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'); | ||
| 257 | + return $this->success($param); | ||
| 258 | + } | ||
| 259 | + | ||
| 260 | + /** | ||
| 261 | + * @remark :保存首页头部底部信息 | ||
| 262 | + * @name :saveHomeHeaderFooter | ||
| 263 | + * @author :lyh | ||
| 264 | + * @method :post | ||
| 265 | + * @time :2023/11/16 11:14 | ||
| 266 | + */ | ||
| 267 | + public function saveHomeHeaderFooter($template_id,$aTemplateInfo){ | ||
| 268 | + $data = [ | ||
| 269 | + 'other'=>str_replace('<header','',characterTruncation($aTemplateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s")), | ||
| 270 | + 'head_html'=>$aTemplateInfo['head_html'], | ||
| 271 | + 'footer_html'=>$aTemplateInfo['footer_html'], | ||
| 272 | + 'head_css'=>$aTemplateInfo['head_css'], | ||
| 273 | + 'footer_css'=>$aTemplateInfo['footer_css'], | ||
| 274 | + 'template_id'=>$template_id, | ||
| 275 | + 'project_id'=>$this->user['project_id'], | ||
| 276 | + 'type'=>1, | ||
| 277 | + ]; | ||
| 278 | + //保存首页头部信息 | ||
| 279 | + $templateCommonModel = new BTemplateCommon(); | ||
| 280 | + $templateCommonModel->add($data); | ||
| 281 | + return $this->success(); | ||
| 282 | + } | ||
| 110 | 283 | ||
| 284 | + /** | ||
| 285 | + * @remark :获取中间公共部分 | ||
| 286 | + * @name :getCommonMain | ||
| 287 | + * @author :lyh | ||
| 288 | + * @method :post | ||
| 289 | + * @time :2023/10/24 15:58 | ||
| 290 | + */ | ||
| 291 | + public function getCommonMain($source,$source_id){ | ||
| 292 | + $data = []; | ||
| 293 | + if ($source == 2) {if ($source_id != 0) {$type = 2;} else {$type = 3;}} | ||
| 294 | + if ($source == 3) {if ($source_id != 0) {$type = 4;} else {$type = 5;}} | ||
| 295 | + if ($source == 4) {if ($source_id != 0) {$type = 6;} else {$type = 7;}} | ||
| 296 | + if ($source == 5) {$type = 8;} | ||
| 297 | + //查询有没有公共详情模板 | ||
| 298 | + $bTemplateMainModel = new BTemplateMain(); | ||
| 299 | + $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$type]); | ||
| 300 | + if($mainInfo === false){ | ||
| 301 | + $data['main_html'] = $this->getModule($type); | ||
| 302 | + $data['main_css'] = "<style id='globalsojs-styles'></style>"; | ||
| 303 | + }else{ | ||
| 304 | + $data['main_html'] = $mainInfo['main_html']; | ||
| 305 | + $data['main_css'] = $mainInfo['main_css']; | ||
| 306 | + } | ||
| 307 | + return $data; | ||
| 308 | + } | ||
| 309 | + | ||
| 310 | + /** | ||
| 311 | + * @remark :默认产品模块 | ||
| 312 | + * @name :getProductModule | ||
| 313 | + * @author :lyh | ||
| 314 | + * @method :post | ||
| 315 | + * @time :2023/7/27 15:08 | ||
| 316 | + */ | ||
| 317 | + public function getModule($type){ | ||
| 318 | + //获取公共主题头部底部 | ||
| 319 | + $mainModel = new TemplateTypeMain(); | ||
| 320 | + $info = $mainModel->read(['type'=>$type]); | ||
| 321 | + return $info['main_html']; | ||
| 322 | + } | ||
| 323 | + | ||
| 324 | + /** | ||
| 325 | + * @remark :根据类型获取公共头和底 | ||
| 326 | + * @name :getCommonPage | ||
| 327 | + * @author :lyh | ||
| 328 | + * @method :post | ||
| 329 | + * @time :2023/10/21 16:55 | ||
| 330 | + */ | ||
| 331 | + public function getCommonPage($source,$source_id,$template_id){ | ||
| 332 | + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) { | ||
| 333 | + //查看页面是否设置自定义头部底部 | ||
| 334 | + $pageSettingModel = new PageSetting(); | ||
| 335 | + $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]); | ||
| 336 | + if ($pageInfo != false) { | ||
| 337 | + $commonTemplateModel = new BTemplateCommon(); | ||
| 338 | + $data = [ | ||
| 339 | + 'template_id' => $template_id, | ||
| 340 | + 'project_id' => $this->user['project_id'] | ||
| 341 | + ]; | ||
| 342 | + if ($source == 2) {//产品页 | ||
| 343 | + if($source_id != 0){$data['type'] = 2;if ($pageInfo['product_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}} | ||
| 344 | + else {$data['type'] = 3;if ($pageInfo['product_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}} | ||
| 345 | + if ($source == 3) {//博客页 | ||
| 346 | + if ($source_id != 0) {$data['type'] = 4;if ($pageInfo['blog_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}} | ||
| 347 | + else {$data['type'] = 5;if ($pageInfo['blog_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}} | ||
| 348 | + if ($source == 4) {//新闻页 | ||
| 349 | + if ($source_id != 0) {$data['type'] = 6;if ($pageInfo['news_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}} | ||
| 350 | + else {$data['type'] = 7;if ($pageInfo['news_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}} | ||
| 351 | + if ($source == 5) {//聚合页 | ||
| 352 | + $data['type'] = 8;if ($pageInfo['polymerization'] != 0) {$commonInfo = $commonTemplateModel->read($data);}} | ||
| 353 | + } | ||
| 354 | + } | ||
| 355 | + //获取首页公共的头部和底部 | ||
| 356 | + if(!isset($commonInfo) || $commonInfo === false){ | ||
| 357 | + $commonTemplateModel = new BTemplateCommon(); | ||
| 358 | + $commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>1]); | ||
| 359 | + } | ||
| 360 | + return $commonInfo; | ||
| 361 | + } | ||
| 111 | } | 362 | } |
-
请 注册 或 登录 后发表评论