作者 lyh

gx

@@ -50,23 +50,6 @@ class BTemplateController extends BaseController @@ -50,23 +50,6 @@ class BTemplateController extends BaseController
50 } 50 }
51 51
52 /** 52 /**
53 - * @remark :设置默认模板  
54 - * @name :setModuleTemplate  
55 - * @author :lyh  
56 - * @method :post  
57 - * @time :2023/6/29 9:39  
58 - */  
59 - public function setPublicTemplate(BTemplateLogic $BTemplateLogic){  
60 - $this->request->validate([  
61 - 'template_id'=>['required'],  
62 - ],[  
63 - 'template_id.required' => '模版ID不能为空',  
64 - ]);  
65 - $BTemplateLogic->setTemplate();  
66 - $this->response('success');  
67 - }  
68 -  
69 - /**  
70 * @remark :保存编辑后的模板 53 * @remark :保存编辑后的模板
71 * @name :save 54 * @name :save
72 * @author :lyh 55 * @author :lyh
@@ -31,8 +31,7 @@ class VisualizationController extends BaseController @@ -31,8 +31,7 @@ class VisualizationController extends BaseController
31 * @time :2023/11/15 10:26 31 * @time :2023/11/15 10:26
32 */ 32 */
33 public function info(Visualization $visualization){ 33 public function info(Visualization $visualization){
34 - //查看当前模板是否在可视化中保存  
35 - $info = $visualization->read(['source'=>$this->map['source']],['html','source','id','project_id']); 34 + $info = $visualization->read(['type'=>$this->map['type']],['main_html','type','id','project_id']);
36 if($info === false){ 35 if($info === false){
37 $info = []; 36 $info = [];
38 } 37 }
@@ -48,11 +47,11 @@ class VisualizationController extends BaseController @@ -48,11 +47,11 @@ class VisualizationController extends BaseController
48 */ 47 */
49 public function save(VisualizationLogic $logic){ 48 public function save(VisualizationLogic $logic){
50 $this->request->validate([ 49 $this->request->validate([
51 - 'source'=>'required',  
52 - 'html'=>'required', 50 + 'type'=>'required',
  51 + 'main_html'=>'required',
53 ],[ 52 ],[
54 - 'source.required' => '类型不能为空',  
55 - 'html.required' => 'html不能为空', 53 + 'type.required' => '类型不能为空',
  54 + 'main_html.required' => 'main_html不能为空',
56 ]); 55 ]);
57 $logic->saveVisualization(); 56 $logic->saveVisualization();
58 $this->response('success'); 57 $this->response('success');
@@ -4,8 +4,11 @@ namespace App\Http\Logic\Aside\Template; @@ -4,8 +4,11 @@ namespace App\Http\Logic\Aside\Template;
4 4
5 use App\Http\Logic\Aside\BaseLogic; 5 use App\Http\Logic\Aside\BaseLogic;
6 use App\Models\Service\Service as ServiceSettingModel; 6 use App\Models\Service\Service as ServiceSettingModel;
  7 +use App\Models\Template\BTemplate;
  8 +use App\Models\Template\BTemplateCommon;
7 use App\Models\Template\Template; 9 use App\Models\Template\Template;
8 use App\Models\Template\Setting; 10 use App\Models\Template\Setting;
  11 +use App\Services\ProjectServer;
9 use Illuminate\Support\Facades\DB; 12 use Illuminate\Support\Facades\DB;
10 13
11 class ATemplateLogic extends BaseLogic 14 class ATemplateLogic extends BaseLogic
@@ -180,6 +183,8 @@ class ATemplateLogic extends BaseLogic @@ -180,6 +183,8 @@ class ATemplateLogic extends BaseLogic
180 }else{ 183 }else{
181 $rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['id'=>$info['id']]); 184 $rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['id'=>$info['id']]);
182 } 185 }
  186 + $this->saveTemplate($this->param['project_id'],$this->param['template_id']);
  187 + //保存一条装修数据
183 if($rs === false){ 188 if($rs === false){
184 $this->fail('error'); 189 $this->fail('error');
185 } 190 }
@@ -187,6 +192,41 @@ class ATemplateLogic extends BaseLogic @@ -187,6 +192,41 @@ class ATemplateLogic extends BaseLogic
187 } 192 }
188 193
189 /** 194 /**
  195 + * @remark :设置模版保存装修首页记录
  196 + * @name :saveTemplate
  197 + * @author :lyh
  198 + * @method :post
  199 + * @time :2023/11/17 11:04
  200 + */
  201 + public function saveTemplate($project_id,$template_id){
  202 + $templateInfo = $this->model->read(['id'=>$template_id]);
  203 + ProjectServer::useProject($project_id);
  204 + $bTemplateModel = new BTemplate();
  205 + $info = $bTemplateModel->read(['source'=>1,'template_id'=>$template_id]);
  206 + if($info === false){
  207 + $data = [
  208 + 'source'=>1, 'source_id'=>0, 'template_id'=>$template_id, 'main_html'=>$templateInfo['main_html'],
  209 + 'main_css'=>$templateInfo['main_css'], 'project_id'=>$project_id,
  210 + ];
  211 + $bTemplateModel->add($data);
  212 + }
  213 + //保存一次公共头部信息
  214 + $bCommonTemplateModel = new BTemplateCommon();
  215 + $commonInfo = $bCommonTemplateModel->read(['template_id'=>$template_id,'type'=>1]);
  216 + if($commonInfo === false){
  217 + $commonData = [
  218 + 'type'=>1, 'template_id'=>$template_id, 'head_html'=>$templateInfo['head_html'],
  219 + 'head_css'=>$templateInfo['head_css'], 'footer_html'=>$templateInfo['footer_html'],
  220 + 'footer_css'=>$templateInfo['footer_css'],'project_id'=>$project_id,
  221 + 'other'=>str_replace('<header','',characterTruncation($templateInfo['html'],"/<link id=\"google-fonts-link\"(.*?)<header/s"))
  222 + ];
  223 + $bCommonTemplateModel->add($commonData);
  224 + }
  225 + DB::disconnect('custom_mysql');
  226 + return $this->success();
  227 + }
  228 +
  229 + /**
190 * @remark :获取选择的模版 230 * @remark :获取选择的模版
191 * @name :getSettingInfo 231 * @name :getSettingInfo
192 * @author :lyh 232 * @author :lyh
@@ -222,32 +222,6 @@ class BTemplateLogic extends BaseLogic @@ -222,32 +222,6 @@ class BTemplateLogic extends BaseLogic
222 return $commonInfo; 222 return $commonInfo;
223 } 223 }
224 224
225 -  
226 - /**  
227 - * @remark :设置模板  
228 - * @name :setTemplate  
229 - * @author :lyh  
230 - * @method :post  
231 - * @time :2023/6/29 9:47  
232 - */  
233 - public function setTemplate(){  
234 - $bSettingModel = new Setting();  
235 - $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);  
236 - if($info === false){  
237 - $param = [  
238 - 'project_id'=>$this->user['project_id'],  
239 - 'template_id'=>$this->param['template_id'],  
240 - ];  
241 - $rs = $bSettingModel->add($param);  
242 - }else{  
243 - $rs = $bSettingModel->edit(['template_id'=>$this->param['template_id']],['project_id'=>$this->user['project_id']]);  
244 - }  
245 - if($rs === false){  
246 - $this->fail('error');  
247 - }  
248 - return $this->success();  
249 - }  
250 -  
251 /** 225 /**
252 * @remark :保存修改后的模版 226 * @remark :保存修改后的模版
253 * @name :templateSave 227 * @name :templateSave
@@ -25,7 +25,7 @@ class VisualizationLogic extends BaseLogic @@ -25,7 +25,7 @@ class VisualizationLogic extends BaseLogic
25 public function __construct() 25 public function __construct()
26 { 26 {
27 parent::__construct(); 27 parent::__construct();
28 - $this->model = new Visualization(); 28 + $this->model = new BTemplateMain();
29 $this->param = $this->requestAll; 29 $this->param = $this->requestAll;
30 } 30 }
31 31
@@ -38,11 +38,36 @@ class VisualizationLogic extends BaseLogic @@ -38,11 +38,36 @@ class VisualizationLogic extends BaseLogic
38 */ 38 */
39 public function saveVisualization(){ 39 public function saveVisualization(){
40 try { 40 try {
41 - if(isset($this->param['id']) && !empty($this->param['id'])){  
42 - $this->model->edit($this->param,['id'=>$this->param['id']]); 41 + $type = $this->getType($this->param['source'],$this->param['source_id']);
  42 + $typeArray = [1,3,5,7];//单页数据
  43 + if(in_array($type,$typeArray)){
  44 + $bTemplateModel = new BTemplate();
  45 + $templateInfo = $bTemplateModel->read(['source'=>$this->param['source'],'template_id'=>0]);
  46 + if($templateInfo === false){
  47 + $data = [
  48 + 'html'=>$this->param['html'],
  49 + 'project_id'=>$this->user['project_id'],
  50 + 'source'=>$this->param['source'],
  51 + 'source_id'=>$this->param['source_id'],
  52 + 'section_list_id'=>$this->param['section_list_id'],
  53 + ];
  54 + $bTemplateModel->add($data);
43 }else{ 55 }else{
44 - $this->param['project_id'] = $this->user['project_id'];  
45 - $this->model->add($this->param); 56 + $bTemplateModel->edit(['html'=>$this->param['html']],['id'=>$templateInfo['id']]);
  57 + }
  58 + }else{//模块数据
  59 + $bTemplateMainModel = new BTemplateMain();
  60 + $mainInfo = $bTemplateMainModel->read(['type'=>$type]);
  61 + if($mainInfo === false){
  62 + $mainData = [
  63 + 'project_id'=>$this->user['project_id'],
  64 + 'type'=>$type,
  65 + 'main_html'=>$this->param['html']
  66 + ];
  67 + $bTemplateMainModel->add($mainData);
  68 + }else{
  69 + $bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
  70 + }
46 } 71 }
47 }catch (\Exception $e){ 72 }catch (\Exception $e){
48 $this->fail('系统错误,请联系管理员'); 73 $this->fail('系统错误,请联系管理员');
@@ -58,54 +83,51 @@ class VisualizationLogic extends BaseLogic @@ -58,54 +83,51 @@ class VisualizationLogic extends BaseLogic
58 * @time :2023/11/15 11:30 83 * @time :2023/11/15 11:30
59 */ 84 */
60 public function getHtml(){ 85 public function getHtml(){
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 = (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){ 86 + $type = $this->getType($this->param['source'],$this->param['source_id']);//获取类型
  87 + $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
  88 + //查看当前类型是否是定制界面
  89 + if(in_array($type,$page_array)){//是定制界面
  90 + if(in_array($type,[1,3,5,7])){//单页
  91 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
  92 + if($templateInfo === false){
68 $this->fail('请先上传定制代码块'); 93 $this->fail('请先上传定制代码块');
69 } 94 }
70 - return $info['html']; 95 + return ['html'=>$templateInfo['html']];
  96 + }else{//模块页
  97 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
  98 + if($templateInfo === false){//获取代码块
  99 + $bTemplateMainModel = new BTemplateMain();
  100 + $mainInfo = $bTemplateMainModel->read(['type'=>$type]);
  101 + if($mainInfo === false){
  102 + $this->fail('请先上传定制代码块');
  103 + }
  104 + return ['html'=>$mainInfo['main_html']];
  105 + }
  106 + return ['html'=>$templateInfo['html']];
  107 + }
71 }else{//非定制界面 108 }else{//非定制界面
72 $bSettingModel = new Setting(); 109 $bSettingModel = new Setting();
73 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); 110 $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
74 if($settingInfo === false){ 111 if($settingInfo === false){
75 $this->fail('请先选择模版'); 112 $this->fail('请先选择模版');
76 } 113 }
77 - //获取公共头部底部  
78 - $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);  
79 - if($commonInfo === false){  
80 - //保存一次首页头部底部  
81 - $ATemplateModel = new Template();  
82 - $aTemplateInfo = $ATemplateModel->read(['id'=>$settingInfo['template_id']]);  
83 - $commonInfo = $this->saveHomeHeaderFooter($settingInfo['template_id'],$aTemplateInfo);  
84 - } 114 + $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
  115 + if($templateInfo === false){
85 //根据类型在获取中间部分 116 //根据类型在获取中间部分
86 $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']); 117 $mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
87 - //拼接数据  
88 - $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].  
89 - $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];  
90 - $html = $this->getHeadFooter($html);  
91 - return ['html'=>$html,'template_id'=>$settingInfo['template_id']];  
92 - }  
93 }else{ 118 }else{
94 - if($TemplateInfo['template_id'] != 0){  
95 - $bSettingModel = new Setting();  
96 - $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);  
97 - if($settingInfo === false){  
98 - $this->fail('请先选择模版'); 119 + $mainData = [
  120 + 'main_html'=>$templateInfo['main_html'],
  121 + 'main_css'=>$templateInfo['main_css']
  122 + ];
99 } 123 }
100 - //获取头部信息 124 + //获取公共头部底部
101 $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']); 125 $commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
102 - $html = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].  
103 - $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html']; 126 + //拼接数据
  127 + $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
  128 + $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
104 $html = $this->getHeadFooter($html); 129 $html = $this->getHeadFooter($html);
105 return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; 130 return ['html'=>$html,'template_id'=>$settingInfo['template_id']];
106 - }else{  
107 - return $TemplateInfo['html'];  
108 - }  
109 } 131 }
110 } 132 }
111 133
@@ -139,14 +161,16 @@ class VisualizationLogic extends BaseLogic @@ -139,14 +161,16 @@ class VisualizationLogic extends BaseLogic
139 * @method :post 161 * @method :post
140 * @time :2023/11/16 11:21 162 * @time :2023/11/16 11:21
141 */ 163 */
142 - public function getWebTemplate($source,$source_id){ 164 + public function getWebTemplate($source,$source_id,$template_id = 0){
143 //查询可视化是否第一次保存 165 //查询可视化是否第一次保存
144 $bTemplateModel = new BTemplate(); 166 $bTemplateModel = new BTemplate();
145 - return $bTemplateModel->read([ 167 + $param = [
146 'source'=>$source, 168 'source'=>$source,
147 'project_id'=>$this->user['project_id'], 169 'project_id'=>$this->user['project_id'],
148 'source_id'=>$source_id, 170 'source_id'=>$source_id,
149 - ]); 171 + 'template_id'=>$template_id
  172 + ];
  173 + return $bTemplateModel->read($param);
150 } 174 }
151 175
152 /** 176 /**
@@ -203,6 +227,7 @@ class VisualizationLogic extends BaseLogic @@ -203,6 +227,7 @@ class VisualizationLogic extends BaseLogic
203 public function saveHtml(){ 227 public function saveHtml(){
204 $page_array = (array)$this->user['is_visualization']->page_array; 228 $page_array = (array)$this->user['is_visualization']->page_array;
205 $type = $this->getType($this->param['source'],$this->param['source_id']); 229 $type = $this->getType($this->param['source'],$this->param['source_id']);
  230 + try {
206 if(in_array($type,$page_array)){//定制页面 231 if(in_array($type,$page_array)){//定制页面
207 $bTemplateModel = new BTemplate(); 232 $bTemplateModel = new BTemplate();
208 $templateInfo = $bTemplateModel->read([ 233 $templateInfo = $bTemplateModel->read([
@@ -210,6 +235,12 @@ class VisualizationLogic extends BaseLogic @@ -210,6 +235,12 @@ class VisualizationLogic extends BaseLogic
210 'project_id'=>$this->user['project_id'], 235 'project_id'=>$this->user['project_id'],
211 'source_id'=>$this->param['source_id'], 236 'source_id'=>$this->param['source_id'],
212 ]); 237 ]);
  238 + if($templateInfo === false){
  239 + $this->param['project_id'] = $this->user['project_id'];
  240 + $bTemplateModel->add($this->param);
  241 + }else{
  242 + $bTemplateModel->edit(['html'=>$this->param['html']],['source'=>$this->param['source'],'source_id'=>$this->param['source_id']]);
  243 + }
213 }else{ 244 }else{
214 $bTemplateModel = new BTemplate(); 245 $bTemplateModel = new BTemplate();
215 $templateInfo = $bTemplateModel->read([ 246 $templateInfo = $bTemplateModel->read([
@@ -222,17 +253,17 @@ class VisualizationLogic extends BaseLogic @@ -222,17 +253,17 @@ class VisualizationLogic extends BaseLogic
222 $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); 253 $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
223 //保存头部 254 //保存头部
224 $this->saveCommonTemplate($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id']); 255 $this->saveCommonTemplate($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id']);
225 - }  
226 - try {  
227 if($templateInfo === false){ 256 if($templateInfo === false){
228 $this->param['project_id'] = $this->user['project_id']; 257 $this->param['project_id'] = $this->user['project_id'];
229 $bTemplateModel->add($this->param); 258 $bTemplateModel->add($this->param);
230 }else{ 259 }else{
231 $bTemplateModel->edit($this->param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id']]); 260 $bTemplateModel->edit($this->param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id']]);
232 } 261 }
  262 + }
233 }catch (\Exception $e){ 263 }catch (\Exception $e){
234 - $this->fail('系统错误请联系管理员'); 264 + $this->fail('系统错误请联系管理员');
235 } 265 }
  266 +
236 return $this->success(); 267 return $this->success();
237 268
238 } 269 }
@@ -282,8 +313,7 @@ class VisualizationLogic extends BaseLogic @@ -282,8 +313,7 @@ class VisualizationLogic extends BaseLogic
282 if ($source == 4) {if ($source_id != 0) {$type = 6;} else {$type = 7;}} 313 if ($source == 4) {if ($source_id != 0) {$type = 6;} else {$type = 7;}}
283 if ($source == 5) {$type = 8;} 314 if ($source == 5) {$type = 8;}
284 //查询有没有公共详情模板 315 //查询有没有公共详情模板
285 - $bTemplateMainModel = new BTemplateMain();  
286 - $mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$type]); 316 + $mainInfo = $this->model->read(['type'=>$type]);
287 if($mainInfo === false){ 317 if($mainInfo === false){
288 $data['main_html'] = $this->getModule($type); 318 $data['main_html'] = $this->getModule($type);
289 $data['main_css'] = "<style id='globalsojs-styles'></style>"; 319 $data['main_css'] = "<style id='globalsojs-styles'></style>";
@@ -301,8 +301,6 @@ Route::middleware(['bloginauth'])->group(function () { @@ -301,8 +301,6 @@ Route::middleware(['bloginauth'])->group(function () {
301 Route::any('/publicTemplateLists', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'publicTemplateLists'])->name('template_publicTemplateLists'); 301 Route::any('/publicTemplateLists', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'publicTemplateLists'])->name('template_publicTemplateLists');
302 //获取选中的主题模版 302 //获取选中的主题模版
303 Route::any('/getPublicTemplate', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'getPublicTemplate'])->name('template_getPublicTemplate'); 303 Route::any('/getPublicTemplate', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'getPublicTemplate'])->name('template_getPublicTemplate');
304 - //设置默认主题模版  
305 - Route::any('/setPublicTemplate', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'setPublicTemplate'])->name('template_setPublicTemplate');  
306 //保存修改后的模版 304 //保存修改后的模版
307 Route::any('/save', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'save'])->name('template_save'); 305 Route::any('/save', [\App\Http\Controllers\Bside\Template\BTemplateController::class, 'save'])->name('template_save');
308 //可视化保存获取数据类型 306 //可视化保存获取数据类型