作者 lyh

gx

@@ -127,4 +127,21 @@ class CustomTemplateController extends BaseController @@ -127,4 +127,21 @@ class CustomTemplateController extends BaseController
127 $lists = $bTemplateLog->lists($this->map,$this->page,$this->row); 127 $lists = $bTemplateLog->lists($this->map,$this->page,$this->row);
128 $this->response('success',Code::SUCCESS,$lists); 128 $this->response('success',Code::SUCCESS,$lists);
129 } 129 }
  130 +
  131 + /**
  132 + * @remark :还原单页面记录
  133 + * @name :rollbackVersion
  134 + * @author :lyh
  135 + * @method :post
  136 + * @time :2024/4/23 13:58
  137 + */
  138 + public function rollbackVersion(CustomTemplateLogic $logic){
  139 + $this->request->validate([
  140 + 'id'=>['required'],
  141 + ],[
  142 + 'id.required' => '模版ID不能为空',
  143 + ]);
  144 + $logic->saveRollbackVersion();
  145 + $this->response('success');
  146 + }
130 } 147 }
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
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\Service\Service as ServiceSettingModel; 14 use App\Models\Service\Service as ServiceSettingModel;
14 use App\Models\Template\BTemplate; 15 use App\Models\Template\BTemplate;
15 use App\Models\Template\BTemplateCommon; 16 use App\Models\Template\BTemplateCommon;
@@ -43,39 +44,72 @@ class BTemplateLogLogic extends BaseLogic @@ -43,39 +44,72 @@ class BTemplateLogLogic extends BaseLogic
43 if(($this->user['project_id'] == 1) && (!in_array($this->user['mobile'],$bTemplateModel->mobile)) && ($info['source'] == 1)){ 44 if(($this->user['project_id'] == 1) && (!in_array($this->user['mobile'],$bTemplateModel->mobile)) && ($info['source'] == 1)){
44 $this->fail('演示项目仅支持演示功能,无法更改首页'); 45 $this->fail('演示项目仅支持演示功能,无法更改首页');
45 } 46 }
46 - if($info['template_id'] == 0){//todo::定制项目  
47 - $condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id'],'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];  
48 - //TODO::还原头部+底部  
49 - $bTemplateModel->edit(['html'=>$info['text']],$condition);  
50 - $commonData = $this->setCommonParam($info);  
51 - $commonTemplateModel = new BTemplateCommon();  
52 - $commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$info['type'],'project_id'=>$this->user['project_id']]);  
53 - return $this->success(); 47 + if($info['template_id'] == 0) {//todo::定制项目
  48 + return $this->rollBackCustomized($info);
54 } 49 }
55 //TODO::非定制项目,获取当前项目的模版 50 //TODO::非定制项目,获取当前项目的模版
  51 + return $this->rollBackNoCustomized($info);
  52 + }
  53 +
  54 + /**
  55 + * @remark :定制页面还原
  56 + * @name :rollBackCustomized
  57 + * @author :lyh
  58 + * @method :post
  59 + * @time :2024/4/23 14:36
  60 + */
  61 + public function rollBackCustomized($info){
  62 + $bTemplateModel = new BTemplate();
  63 + $condition = ['template_id'=>0,'source'=>$info['source'],'source_id'=>$info['source_id'],
  64 + 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
  65 + //TODO::还原头部+底部
  66 + $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']]);
  74 + return $this->success();
  75 + }
  76 +
  77 + /**
  78 + * @remark :非定制界面还原
  79 + * @name :rollBackNoCustomized
  80 + * @author :lyh
  81 + * @method :post
  82 + * @time :2024/4/23 14:38
  83 + */
  84 + public function rollBackNoCustomized($info){
56 $bSettingModel = new Setting(); 85 $bSettingModel = new Setting();
57 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); 86 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
58 if($settingInfo === false){ 87 if($settingInfo === false){
59 $this->fail('请先选择模版'); 88 $this->fail('请先选择模版');
60 } 89 }
  90 + $bTemplateModel = new BTemplate();
61 try { 91 try {
62 //切换模版 92 //切换模版
63 if($info['template_id'] != $settingInfo['template_id']){ 93 if($info['template_id'] != $settingInfo['template_id']){
64 $bSettingModel->edit(['template_id'=>$info['template_id']],['id'=>$settingInfo['id']]); 94 $bSettingModel->edit(['template_id'=>$info['template_id']],['id'=>$settingInfo['id']]);
65 } 95 }
66 - $data = $this->setParam($info);  
67 - $condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id'],'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']]; 96 + $data = ['main_html'=>$info['main_html'], 'main_css'=>$info['main_css']];
  97 + $condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],'source_id'=>$info['source_id'],
  98 + 'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
68 $bTemplateModel->edit($data,$condition); 99 $bTemplateModel->edit($data,$condition);
69 //还原头部+底部 100 //还原头部+底部
70 - $commonData = $this->setCommonParam($info); 101 + $commonData = [
  102 + 'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
  103 + ];
71 $commonTemplateModel = new BTemplateCommon(); 104 $commonTemplateModel = new BTemplateCommon();
72 - $commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$info['type'],'project_id'=>$this->user['project_id']]); 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']]);
73 if(!empty($info['other'])){ 107 if(!empty($info['other'])){
74 $commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]); 108 $commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]);
75 }else{ 109 }else{
76 $footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s')); 110 $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); 111 $other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
78 - $commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]); 112 + $commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$type]);
79 } 113 }
80 }catch (\Exception $e){ 114 }catch (\Exception $e){
81 $this->fail('系统错误,请联系管理员'); 115 $this->fail('系统错误,请联系管理员');
@@ -84,35 +118,67 @@ class BTemplateLogLogic extends BaseLogic @@ -84,35 +118,67 @@ class BTemplateLogLogic extends BaseLogic
84 } 118 }
85 119
86 /** 120 /**
87 - * @remark :设置回滚参数  
88 - * @name :setParam 121 + * @remark :定制页面头部类型---根据source获取type类型
  122 + * @name :getType
89 * @author :lyh 123 * @author :lyh
90 * @method :post 124 * @method :post
91 - * @time :2023/8/23 14:18 125 + * @time :2023/11/16 11:20
92 */ 126 */
93 - public function setParam($info){  
94 - $data = [  
95 - 'main_html'=>$info['main_html'],  
96 - 'main_css'=>$info['main_css'],  
97 - ];  
98 - return $this->success($data); 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;
  139 + }else{
  140 + $type = BTemplate::TYPE_BLOG_DETAIL;
  141 + }
  142 + }
  143 + if($source == BTemplate::SOURCE_NEWS){
  144 + if($is_list == BTemplate::IS_LIST){
  145 + $type = BTemplate::TYPE_NEWS_LIST;
  146 + }else{
  147 + $type = BTemplate::TYPE_NEWS_DETAIL;
  148 + }
  149 + }
  150 + return $type;
99 } 151 }
100 152
101 /** 153 /**
102 - * @remark :设置回滚公共参数参数  
103 - * @name :setParam 154 + * @remark :(非定制)保存时获取获取设置的类型
  155 + * @name :getType
104 * @author :lyh 156 * @author :lyh
105 * @method :post 157 * @method :post
106 - * @time :2023/8/23 14:18 158 + * @time :2023/10/21 17:29
107 */ 159 */
108 - public function setCommonParam($info){  
109 - $data = [  
110 - 'head_html'=>$info['head_html'],  
111 - 'head_css'=>$info['head_css'],  
112 - 'footer_html'=>$info['footer_html'],  
113 - 'footer_css'=>$info['footer_css']  
114 - ];  
115 - return $this->success($data); 160 + public function getType($source,$is_list,$is_custom = 0){
  161 + $type = BTemplate::SOURCE_HOME;//首页公共头部底部
  162 + $is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
  163 + if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
  164 + return $this->success($type);
  165 + }
  166 + //查看页面是否设置自定义头部底部
  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;}}
  180 + }
  181 + return $this->success($type);
116 } 182 }
117 183
118 /** 184 /**
@@ -607,6 +607,7 @@ class BTemplateLogic extends BaseLogic @@ -607,6 +607,7 @@ class BTemplateLogic extends BaseLogic
607 $param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'); 607 $param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
608 return $this->success($param); 608 return $this->success($param);
609 } 609 }
  610 +
610 /** 611 /**
611 * @remark :(非定制)保存时获取获取设置的类型 612 * @remark :(非定制)保存时获取获取设置的类型
612 * @name :getType 613 * @name :getType
@@ -365,4 +365,36 @@ class CustomTemplateLogic extends BaseLogic @@ -365,4 +365,36 @@ class CustomTemplateLogic extends BaseLogic
365 return $this->success($data); 365 return $this->success($data);
366 } 366 }
367 367
  368 + /**
  369 + * @remark :单页面还原
  370 + * @name :saveRollbackVersion
  371 + * @author :lyh
  372 + * @method :post
  373 + * @time :2024/4/23 14:00
  374 + */
  375 + public function saveRollbackVersion(){
  376 + //获取当前数据记录详情
  377 + $log = new BTemplateLog();
  378 + $logInfo = $log->read(['id'=>$this->param['id']]);
  379 + if($logInfo === false){
  380 + $this->fail('未获取到当前记录');
  381 + }
  382 + //获取当前数据详情
  383 + $info = $this->model->read(['id'=>$logInfo['source_id']],['is_visualization']);
  384 + if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
  385 + //还原头部底部
  386 + $type = $this->getType();
  387 + //还原头部+底部
  388 + $commonData = [
  389 + 'head_html'=>$logInfo['head_html'],
  390 + 'head_css'=>$logInfo['head_css'],
  391 + 'footer_html'=>$logInfo['footer_html'],
  392 + 'footer_css'=>$logInfo['footer_css']
  393 + ];
  394 + $commonTemplateModel = new BTemplateCommon();
  395 + $commonTemplateModel->edit($commonData,['template_id'=>$logInfo['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
  396 + }
  397 + $this->model->edit(['html'=>$logInfo['main_html'],'html_style'=>$logInfo['main_css']],['id'=>$logInfo['source_id']]);
  398 + return $this->success();
  399 + }
368 } 400 }
@@ -396,6 +396,7 @@ Route::middleware(['bloginauth'])->group(function () { @@ -396,6 +396,7 @@ Route::middleware(['bloginauth'])->group(function () {
396 Route::any('/saveHtml', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'saveHtml'])->name('custom_saveHtml'); 396 Route::any('/saveHtml', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'saveHtml'])->name('custom_saveHtml');
397 Route::any('/statusNum', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'statusNumber'])->name('custom_statusNum'); 397 Route::any('/statusNum', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'statusNumber'])->name('custom_statusNum');
398 Route::any('/del', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'del'])->name('custom_del'); 398 Route::any('/del', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'del'])->name('custom_del');
  399 + Route::any('/rollbackVersion', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'rollbackVersion'])->name('custom_rollbackVersion');
399 Route::any('/getCustomTemplateLog', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'getCustomTemplateLog'])->name('custom_getCustomTemplateLog'); 400 Route::any('/getCustomTemplateLog', [\App\Http\Controllers\Bside\Template\CustomTemplateController::class, 'getCustomTemplateLog'])->name('custom_getCustomTemplateLog');
400 }); 401 });
401 // 菜单组 402 // 菜单组