作者 lyh

gx

@@ -66,10 +66,15 @@ class BTemplateLogic extends BaseLogic @@ -66,10 +66,15 @@ class BTemplateLogic extends BaseLogic
66 if($info === false){ 66 if($info === false){
67 $this->fail('请先选择模版'); 67 $this->fail('请先选择模版');
68 } 68 }
69 - if($this->param['source'] == $this->model::SOURCE_HOME){//首页  
70 - $TemplateInfo = $this->homeHtml($info,$this->param['source'],$this->param['source_id']);  
71 - }else{  
72 - $TemplateInfo = $this->otherHtml($info,$this->param['source'],$this->param['source_id']); 69 + //自定义模块单独处理
  70 + if(isset($this->param['is_custom']) && $this->param['is_custom'] == 1){
  71 + $TemplateInfo = $this->customHtml($info,$this->param['source'],$this->param['source_id'],$this->param['is_custom']);
  72 + }else{//系统页面
  73 + if($this->param['source'] == $this->model::SOURCE_HOME){//首页
  74 + $TemplateInfo = $this->homeHtml($info,$this->param['source'],$this->param['source_id']);
  75 + }else{
  76 + $TemplateInfo = $this->otherHtml($info,$this->param['source'],$this->param['source_id']);
  77 + }
73 } 78 }
74 return $this->success($TemplateInfo); 79 return $this->success($TemplateInfo);
75 } 80 }
@@ -81,13 +86,14 @@ class BTemplateLogic extends BaseLogic @@ -81,13 +86,14 @@ class BTemplateLogic extends BaseLogic
81 * @method :post 86 * @method :post
82 * @time :2023/7/25 16:41 87 * @time :2023/7/25 16:41
83 */ 88 */
84 - public function webTemplateInfo($template_id,$source,$source_id){ 89 + public function webTemplateInfo($template_id,$source,$source_id,$is_custom = 0){
85 //查看当前模板是否已编辑保存web_template 90 //查看当前模板是否已编辑保存web_template
86 $TemplateInfo = $this->model->read([ 91 $TemplateInfo = $this->model->read([
87 'template_id'=>$template_id, 92 'template_id'=>$template_id,
88 'source'=>$source, 93 'source'=>$source,
89 'project_id'=>$this->user['project_id'], 94 'project_id'=>$this->user['project_id'],
90 'source_id'=>$source_id, 95 'source_id'=>$source_id,
  96 + 'is_custom'=>$is_custom
91 ]); 97 ]);
92 return $this->success($TemplateInfo); 98 return $this->success($TemplateInfo);
93 } 99 }
@@ -109,10 +115,8 @@ class BTemplateLogic extends BaseLogic @@ -109,10 +115,8 @@ class BTemplateLogic extends BaseLogic
109 }else{ 115 }else{
110 $commonTemplateModel = new BTemplateCommon(); 116 $commonTemplateModel = new BTemplateCommon();
111 $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]); 117 $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);
112 - if($commonInfo !== false){  
113 - $TemplateInfo['html'] = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].  
114 - $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];  
115 - } 118 + $TemplateInfo['html'] = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
  119 + $commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
116 $ATemplateModel = new Template(); 120 $ATemplateModel = new Template();
117 $ATemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']],['name','image']); 121 $ATemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']],['name','image']);
118 $TemplateInfo['name'] = $ATemplateInfo['name']; 122 $TemplateInfo['name'] = $ATemplateInfo['name'];
@@ -158,6 +162,35 @@ class BTemplateLogic extends BaseLogic @@ -158,6 +162,35 @@ class BTemplateLogic extends BaseLogic
158 } 162 }
159 163
160 /** 164 /**
  165 + * @remark :获取自定义模块的html
  166 + * @name :customHtml
  167 + * @author :lyh
  168 + * @method :post
  169 + * @time :2023/12/12 9:39
  170 + */
  171 + public function customHtml($info,$source,$source_id,$is_custom){
  172 + $templateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id,$is_custom);
  173 + if($templateInfo === false){
  174 + //TODO::取新闻的默认页,后期如果更新,修改此处
  175 + $news_source = 3;
  176 + $mainInfo = $this->getCommonMain($news_source,$source_id);
  177 + $main_html = $mainInfo['main_html'];
  178 + $main_style = $mainInfo['main_css'];
  179 + $templateInfo['template_id'] = $info['template_id'];
  180 + }else{
  181 + $main_html = $templateInfo['main_html'];
  182 + $main_style = $templateInfo['main_css'];
  183 + }
  184 + //TODO::无独立头部时,取首页的头部和底部
  185 + $commonTemplateModel = new BTemplateCommon();
  186 + $commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);
  187 + $html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].
  188 + $commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
  189 + $templateInfo['html'] = $this->getHeadFooter($html);//组装数据
  190 + return $this->success($templateInfo);
  191 + }
  192 +
  193 + /**
161 * @remark :获取中间公共部分 194 * @remark :获取中间公共部分
162 * @name :getCommonMain 195 * @name :getCommonMain
163 * @author :lyh 196 * @author :lyh
@@ -237,19 +270,16 @@ class BTemplateLogic extends BaseLogic @@ -237,19 +270,16 @@ class BTemplateLogic extends BaseLogic
237 //查询当前模版是否已保存 270 //查询当前模版是否已保存
238 DB::beginTransaction(); 271 DB::beginTransaction();
239 try { 272 try {
240 - $info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);  
241 //字符串截取 273 //字符串截取
242 $this->param = $this->stringProcessing($this->param); 274 $this->param = $this->stringProcessing($this->param);
243 - //保存头部信息  
244 - $this->saveCommonTemplate($this->param);  
245 - $param = $this->templateSaveParam($this->param);//组装数据  
246 - if($info === false){  
247 - $this->model->add($param); 275 + //自定义模块单独处理
  276 + if(isset($this->param['is_custom']) && ($this->param['is_custom'] == 1)){
  277 +
248 }else{ 278 }else{
249 - $this->model->edit($param,['id'=>$info['id']]); 279 + $this->saveTemplateHtml($this->param);
  280 + //写入操作模版记录
  281 + $this->setTemplateLog($this->param);
250 } 282 }
251 - //写入操作模版记录  
252 - $this->setTemplateLog($this->param);  
253 DB::commit(); 283 DB::commit();
254 }catch (\Exception $e){ 284 }catch (\Exception $e){
255 DB::rollBack(); 285 DB::rollBack();
@@ -261,6 +291,27 @@ class BTemplateLogic extends BaseLogic @@ -261,6 +291,27 @@ class BTemplateLogic extends BaseLogic
261 } 291 }
262 292
263 /** 293 /**
  294 + * @remark :保存可视化数据
  295 + * @name :saveTemplateHtml
  296 + * @author :lyh
  297 + * @method :post
  298 + * @time :2023/12/12 10:23
  299 + */
  300 + public function saveTemplateHtml($param){
  301 + $info = $this->webTemplateInfo($this->param['template_id'],$param['source'],$param['source_id']);
  302 + //保存头部信息
  303 + $this->saveCommonTemplate($param);
  304 + $param['project_id'] = $this->user['project_id'];
  305 + unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
  306 + if($info === false){
  307 + $this->model->add($param);
  308 + }else{
  309 + $this->model->edit($param,['id'=>$info['id']]);
  310 + }
  311 + return true;//组装数据
  312 + }
  313 +
  314 + /**
264 * @remark :保存头部公共数据 315 * @remark :保存头部公共数据
265 * @name :saveCommonTemplate 316 * @name :saveCommonTemplate
266 * @author :lyh 317 * @author :lyh
@@ -383,19 +434,6 @@ class BTemplateLogic extends BaseLogic @@ -383,19 +434,6 @@ class BTemplateLogic extends BaseLogic
383 } 434 }
384 435
385 /** 436 /**
386 - * @remark :处理保存模版数据  
387 - * @name :templateParam  
388 - * @author :lyh  
389 - * @method :post  
390 - * @time :2023/7/21 16:30  
391 - */  
392 - public function templateSaveParam($param){  
393 - $param['project_id'] = $this->user['project_id'];  
394 - unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);  
395 - return $this->success($param);  
396 - }  
397 -  
398 - /**  
399 * @remark :拼接获取公共头部底部 437 * @remark :拼接获取公共头部底部
400 * @name :getHeadFooter 438 * @name :getHeadFooter
401 * @author :lyh 439 * @author :lyh
@@ -126,7 +126,6 @@ class KeywordLogic extends BaseLogic @@ -126,7 +126,6 @@ class KeywordLogic extends BaseLogic
126 */ 126 */
127 public function batchAdd(){ 127 public function batchAdd(){
128 try { 128 try {
129 - $idArr = [];  
130 foreach ($this->param['title'] as $v){ 129 foreach ($this->param['title'] as $v){
131 $this->model = new Keyword(); 130 $this->model = new Keyword();
132 $info = $this->model->read(['title'=>$v]); 131 $info = $this->model->read(['title'=>$v]);
@@ -136,16 +135,11 @@ class KeywordLogic extends BaseLogic @@ -136,16 +135,11 @@ class KeywordLogic extends BaseLogic
136 $param['updated_at'] = $param['created_at']; 135 $param['updated_at'] = $param['created_at'];
137 $param['title'] = $v; 136 $param['title'] = $v;
138 $id = $this->model->insertGetId($param); 137 $id = $this->model->insertGetId($param);
139 - $idArr[] = ['id'=>$id,'title'=>$v]; 138 + $route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
  139 + $this->curlDelRoute(['new_route'=>$route]);
  140 + $this->model->edit(['route'=>$route],['id'=>$v['id']]);
140 } 141 }
141 } 142 }
142 - //批量生成路由  
143 - foreach ($idArr as $v){  
144 - $this->model = new Keyword();  
145 - $route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);  
146 - $this->curlDelRoute(['new_route'=>$route]);  
147 - $this->model->edit(['route'=>$route],['id'=>$v['id']]);  
148 - }  
149 }catch (\Exception $e){ 143 }catch (\Exception $e){
150 $this->fail('error'); 144 $this->fail('error');
151 } 145 }
@@ -17,6 +17,8 @@ class BTemplate extends Base @@ -17,6 +17,8 @@ class BTemplate extends Base
17 const SOURCE_BLOG = 3;//博客 17 const SOURCE_BLOG = 3;//博客
18 const SOURCE_NEWS = 4;//新闻详情页 18 const SOURCE_NEWS = 4;//新闻详情页
19 const SOURCE_KEYWORD = 5;//聚合页 19 const SOURCE_KEYWORD = 5;//聚合页
  20 +
  21 + const SOURCE_CUSTOM = 1;//自定义模块
20 const STATUS = 0; 22 const STATUS = 0;
21 23
22 const TYPE_ONE = 1; 24 const TYPE_ONE = 1;