作者 lyh

gx

@@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController; @@ -7,6 +7,7 @@ use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\BTemplate\BTemplateLogic; 7 use App\Http\Logic\Bside\BTemplate\BTemplateLogic;
8 use App\Http\Requests\Bside\Template\TemplateRequest; 8 use App\Http\Requests\Bside\Template\TemplateRequest;
9 use App\Models\Template\BTemplate; 9 use App\Models\Template\BTemplate;
  10 +use App\Models\Template\BTemplateMain;
10 use App\Models\Template\Template; 11 use App\Models\Template\Template;
11 12
12 class BTemplateController extends BaseController 13 class BTemplateController extends BaseController
@@ -141,4 +142,28 @@ class BTemplateController extends BaseController @@ -141,4 +142,28 @@ class BTemplateController extends BaseController
141 $BTemplateLogic->savePublicTemplateHtml(); 142 $BTemplateLogic->savePublicTemplateHtml();
142 $this->response('模板保存成功'); 143 $this->response('模板保存成功');
143 } 144 }
  145 +
  146 + /**
  147 + * @remark :获取可视化详情页模板数据
  148 + * @name :getDetailInfo
  149 + * @author :lyh
  150 + * @method :post
  151 + * @time :2023/10/24 11:27
  152 + */
  153 + public function getDetailInfo(BTemplateLogic $BTemplateLogic){
  154 + $info = $BTemplateLogic->getDetail();
  155 + $this->response('success',Code::SUCCESS,$info);
  156 + }
  157 +
  158 + /**
  159 + * @remark :保存数据
  160 + * @name :saveDetail
  161 + * @author :lyh
  162 + * @method :post
  163 + * @time :2023/10/24 14:47
  164 + */
  165 + public function saveDetail(BTemplateLogic $BTemplateLogic){
  166 + $BTemplateLogic->saveDetail();
  167 + $this->response('success');
  168 + }
144 } 169 }
@@ -11,6 +11,7 @@ use App\Models\Project\PageSetting; @@ -11,6 +11,7 @@ use App\Models\Project\PageSetting;
11 use App\Models\RouteMap\RouteMap; 11 use App\Models\RouteMap\RouteMap;
12 use App\Models\Service\Service as ServiceSettingModel; 12 use App\Models\Service\Service as ServiceSettingModel;
13 use App\Models\Template\BTemplateCommon; 13 use App\Models\Template\BTemplateCommon;
  14 +use App\Models\Template\BTemplateMain;
14 use App\Models\Template\Setting; 15 use App\Models\Template\Setting;
15 use App\Models\Template\BTemplate; 16 use App\Models\Template\BTemplate;
16 use App\Models\Template\BTemplateLog; 17 use App\Models\Template\BTemplateLog;
@@ -165,51 +166,22 @@ class BTemplateLogic extends BaseLogic @@ -165,51 +166,22 @@ class BTemplateLogic extends BaseLogic
165 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]); 166 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
166 if ($pageInfo != false) { 167 if ($pageInfo != false) {
167 $commonTemplateModel = new BTemplateCommon(); 168 $commonTemplateModel = new BTemplateCommon();
  169 + $data = [
  170 + 'template_id' => $template_id,
  171 + 'project_id' => $this->user['project_id']
  172 + ];
168 if ($source == 2) {//产品页 173 if ($source == 2) {//产品页
169 - if ($source_id != 0) {//产品详情页  
170 - if ($pageInfo['product_list'] != 0) {  
171 - //使用独立头和底  
172 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 3]);  
173 - }  
174 - } else {//产品列表页  
175 - if ($pageInfo['product_details'] != 0) {  
176 - //使用独立头和底  
177 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 2]);  
178 - }  
179 - }  
180 - } 174 + if($source_id != 0){$data['type'] = 2;if ($pageInfo['product_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
  175 + else {$data['type'] = 3;if ($pageInfo['product_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
181 if ($source == 3) {//博客页 176 if ($source == 3) {//博客页
182 - if ($source_id != 0) {//博客详情页  
183 - if ($pageInfo['blog_lists'] != 0) {  
184 - //使用独立头和底  
185 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 4]);  
186 - }  
187 - } else {//产品列表页  
188 - if ($pageInfo['blog_details'] != 0) {  
189 - //使用独立头和底  
190 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 5]);  
191 - }  
192 - }  
193 - } 177 + if ($source_id != 0) {$data['type'] = 4;if ($pageInfo['blog_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
  178 + else {$data['type'] = 5;if ($pageInfo['blog_lists'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
194 if ($source == 4) {//新闻页 179 if ($source == 4) {//新闻页
195 - if ($source_id != 0) {//新闻详情页  
196 - if ($pageInfo['news_lists'] != 0) {  
197 - //使用独立头和底  
198 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 6]);  
199 - }  
200 - } else {//新闻列表页  
201 - if ($pageInfo['news_details'] != 0) {  
202 - //使用独立头和底  
203 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 7]);  
204 - }  
205 - }  
206 - } 180 + if ($source_id != 0) {$data['type'] = 6;if ($pageInfo['news_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
  181 + else {$data['type'] = 7;if ($pageInfo['news_lists'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
207 if ($source == 5) {//聚合页 182 if ($source == 5) {//聚合页
208 - if ($pageInfo['polymerization'] != 0) {  
209 - //使用独立头和底  
210 - $commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $this->user['project_id'], 'type' => 8]);  
211 - }  
212 - } 183 + $data['type'] = 8;
  184 + if ($pageInfo['polymerization'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
213 } 185 }
214 } 186 }
215 //获取首页公共的头部和底部 187 //获取首页公共的头部和底部
@@ -327,44 +299,10 @@ class BTemplateLogic extends BaseLogic @@ -327,44 +299,10 @@ class BTemplateLogic extends BaseLogic
327 $pageSettingModel = new PageSetting(); 299 $pageSettingModel = new PageSetting();
328 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]); 300 $pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
329 if ($pageInfo !== false) { 301 if ($pageInfo !== false) {
330 - if ($source == 2) {  
331 - if ($source_id != 0) {  
332 - if ($pageInfo['product_list'] != 0) {  
333 - $type = 3;  
334 - }  
335 - } else {  
336 - if ($pageInfo['product_details'] != 0) {  
337 - $type = 2;  
338 - }  
339 - }  
340 - }  
341 - if ($source == 3) {  
342 - if ($source_id != 0) {  
343 - if ($pageInfo['blog_list'] != 0) {  
344 - $type = 4;  
345 - }  
346 - } else {  
347 - if ($pageInfo['blog_details'] != 0) {  
348 - $type = 5;  
349 - }  
350 - }  
351 - }  
352 - if ($source == 4) {  
353 - if ($source_id != 0) {  
354 - if ($pageInfo['news_list'] != 0) {  
355 - $type = 6;  
356 - }  
357 - } else {  
358 - if ($pageInfo['news_details'] != 0) {  
359 - $type = 7;  
360 - }  
361 - }  
362 - }  
363 - if ($source == 5) {  
364 - if ($pageInfo['polymerization'] != 0) {  
365 - $type = 8;  
366 - }  
367 - } 302 + if ($source == 2) {if ($source_id != 0) {if ($pageInfo['product_details'] != 0) {$type = 2;}} else {if ($pageInfo['product_list'] != 0) {$type = 3;}}}
  303 + if ($source == 3) {if ($source_id != 0) {if ($pageInfo['blog_details'] != 0) {$type = 4;}} else {if ($pageInfo['blog_list'] != 0) {$type = 5;}}}
  304 + if ($source == 4) {if ($source_id != 0) {if ($pageInfo['news_details'] != 0) {$type = 6;}} else {if ($pageInfo['news_list'] != 0) {$type = 7;}}}
  305 + if ($source == 5) {if ($pageInfo['polymerization'] != 0) {$type = 8;}}
368 } 306 }
369 } 307 }
370 return $type; 308 return $type;
@@ -545,19 +483,13 @@ class BTemplateLogic extends BaseLogic @@ -545,19 +483,13 @@ class BTemplateLogic extends BaseLogic
545 $newCategory = NewsCategory::where($map)->get(); 483 $newCategory = NewsCategory::where($map)->get();
546 $blogCategory = BlogCategory::where($map)->get(); 484 $blogCategory = BlogCategory::where($map)->get();
547 if (!empty($productCategory)){ 485 if (!empty($productCategory)){
548 - foreach ($productCategory as $item){  
549 - $data["products"]["category"][] =$item;  
550 - } 486 + foreach ($productCategory as $item){$data["products"]["category"][] =$item;}
551 } 487 }
552 if (!empty($newCategory)){ 488 if (!empty($newCategory)){
553 - foreach ($newCategory as $item){  
554 - $data["news"]["category"][] =$item;  
555 - } 489 + foreach ($newCategory as $item){$data["news"]["category"][] =$item;}
556 } 490 }
557 if (!empty($blogCategory)){ 491 if (!empty($blogCategory)){
558 - foreach ($blogCategory as $item){  
559 - $data["blogs"]["category"][] =$item;  
560 - } 492 + foreach ($blogCategory as $item){$data["blogs"]["category"][] =$item;}
561 } 493 }
562 //返回 494 //返回
563 return $this->success($data); 495 return $this->success($data);
@@ -581,4 +513,99 @@ class BTemplateLogic extends BaseLogic @@ -581,4 +513,99 @@ class BTemplateLogic extends BaseLogic
581 } 513 }
582 return $this->success(); 514 return $this->success();
583 } 515 }
  516 +
  517 + /**
  518 + * @remark :获取详情模板详情
  519 + * @name :getDetail
  520 + * @author :lyh
  521 + * @method :post
  522 + * @time :2023/10/24 11:29
  523 + */
  524 + public function getDetail(){
  525 + $bSettingModel = new Setting();
  526 + $bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
  527 + if($bSettingInfo === false){
  528 + $this->fail('请先设置模板');
  529 + }
  530 + //获取首页公共部分
  531 + $templateCommonModel = new BTemplateCommon();
  532 + $commonInfo = $templateCommonModel->read(['template_id'=>$bSettingInfo['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);
  533 + if($commonInfo === false){
  534 + $this->fail('已装修的项目使用当前功能时,可视化保存首页数据一次,未装修首页请先装修首页');
  535 + }
  536 + //判断当前项目是否有设置独立头部的权限是
  537 + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
  538 + //有权限时,获取独立头部
  539 + $commonTypeInfo = $templateCommonModel->read(['template_id'=>$bSettingInfo['template_id'],'project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
  540 + if($commonTypeInfo !== false){
  541 + $commonInfo = $commonTypeInfo;
  542 + }
  543 + }
  544 + //获取设置的默认中间部分
  545 + $bTemplateMainModel = new BTemplateMain();
  546 + $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
  547 + if($mainInfo === false){
  548 + $main_html = "<main>{$this->getProductModule()}</main>";
  549 + $main_style = "<style id='globalsojs-styles'></style>";
  550 + }else{
  551 + $main_html = $mainInfo['main_html'];
  552 + $main_style = $mainInfo['main_style'];
  553 + }
  554 + $html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].
  555 + $commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
  556 + $html = $this->getHeadFooter($html);//组装数据
  557 + return $this->success($html);
  558 + }
  559 +
  560 + /**
  561 + * @remark :保存详情模板数据
  562 + * @name :saveDetail
  563 + * @author :lyh
  564 + * @method :post
  565 + * @time :2023/10/24 11:53
  566 + */
  567 + public function saveDetail(){
  568 + $bSettingModel = new Setting();
  569 + $bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
  570 + if($bSettingInfo === false){
  571 + $this->fail('请先设置模板');
  572 + }
  573 + $data = [
  574 + 'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
  575 + 'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
  576 + ];
  577 + //保存中间部分
  578 + $bTemplateMainModel = new BTemplateMain();
  579 + $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type']]);
  580 + if($mainInfo === false){
  581 + $data['project_id'] = $this->user['project_id'];
  582 + $data['type'] = $this->param['type'];
  583 + $bTemplateMainModel->add($data);
  584 + }else{
  585 + $bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
  586 + }
  587 + $publicData = [
  588 + 'head_html' => characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
  589 + 'head_css' => characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
  590 + 'footer_html' => characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
  591 + 'footer_css' => characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
  592 + ];
  593 + //查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
  594 + $templateCommonModel = new BTemplateCommon();
  595 + if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
  596 + $templateCommonInfo = $templateCommonModel->read(['type'=>$this->param['type'],'project_id'=>$this->user['project_id'],'template_id'=>$bSettingInfo['template_id']]);
  597 + if($templateCommonInfo === false){
  598 + $publicData['type'] = $this->param['type'];
  599 + $publicData['project_id'] = $this->user['project_id'];
  600 + $publicData['template_id'] = $bSettingInfo['template_id'];
  601 + $templateCommonModel->add($publicData);
  602 + }else{
  603 + $templateCommonModel->edit($publicData,['id'=>$templateCommonInfo['id']]);
  604 + }
  605 + }else{
  606 + //更新首页头部底部
  607 + $templateCommonModel->edit($publicData,['type'=>1,'project_id'=>$this->user['project_id'],'template_id'=>$bSettingInfo['template_id']]);
  608 + }
  609 + return $this->success();
  610 + }
584 } 611 }
  1 +<?php
  2 +/**
  3 + * @remark :
  4 + * @name :BTemplateMain.php
  5 + * @author :lyh
  6 + * @method :post
  7 + * @time :2023/10/24 11:19
  8 + */
  9 +
  10 +namespace App\Models\Template;
  11 +
  12 +use App\Models\Base;
  13 +
  14 +class BTemplateMain extends Base
  15 +{
  16 + protected $table = 'gl_web_template_main';
  17 + //连接数据库
  18 + protected $connection = 'custom_mysql';
  19 +}
@@ -301,6 +301,8 @@ Route::middleware(['bloginauth'])->group(function () { @@ -301,6 +301,8 @@ Route::middleware(['bloginauth'])->group(function () {
301 Route::any('/getHeadFooter', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'getHeadFooter'])->name('template_getHeadFooter'); 301 Route::any('/getHeadFooter', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'getHeadFooter'])->name('template_getHeadFooter');
302 Route::any('/setHeadFooter', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'setHeadFooter'])->name('template_setHeadFooter'); 302 Route::any('/setHeadFooter', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'setHeadFooter'])->name('template_setHeadFooter');
303 Route::any('/savePublicTemplate', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'savePublicTemplate'])->name('template_savePublicTemplate'); 303 Route::any('/savePublicTemplate', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'savePublicTemplate'])->name('template_savePublicTemplate');
  304 + Route::any('/getDetailInfo', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'getDetailInfo'])->name('template_getDetailInfo');
  305 + Route::any('/saveDetail', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'saveDetail'])->name('template_saveDetail');
304 // 模板 306 // 模板
305 Route::prefix('module')->group(function () { 307 Route::prefix('module')->group(function () {
306 //获取所有左侧模版 308 //获取所有左侧模版