作者 lyh

gx

... ... @@ -66,11 +66,16 @@ class BTemplateLogic extends BaseLogic
if($info === false){
$this->fail('请先选择模版');
}
//自定义模块单独处理
if(isset($this->param['is_custom']) && $this->param['is_custom'] == 1){
$TemplateInfo = $this->customHtml($info,$this->param['source'],$this->param['source_id'],$this->param['is_custom']);
}else{//系统页面
if($this->param['source'] == $this->model::SOURCE_HOME){//首页
$TemplateInfo = $this->homeHtml($info,$this->param['source'],$this->param['source_id']);
}else{
$TemplateInfo = $this->otherHtml($info,$this->param['source'],$this->param['source_id']);
}
}
return $this->success($TemplateInfo);
}
... ... @@ -81,13 +86,14 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/7/25 16:41
*/
public function webTemplateInfo($template_id,$source,$source_id){
public function webTemplateInfo($template_id,$source,$source_id,$is_custom = 0){
//查看当前模板是否已编辑保存web_template
$TemplateInfo = $this->model->read([
'template_id'=>$template_id,
'source'=>$source,
'project_id'=>$this->user['project_id'],
'source_id'=>$source_id,
'is_custom'=>$is_custom
]);
return $this->success($TemplateInfo);
}
... ... @@ -109,10 +115,8 @@ class BTemplateLogic extends BaseLogic
}else{
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);
if($commonInfo !== false){
$TemplateInfo['html'] = $commonInfo['head_css'].$TemplateInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$TemplateInfo['main_html'].$commonInfo['footer_html'];
}
$ATemplateModel = new Template();
$ATemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']],['name','image']);
$TemplateInfo['name'] = $ATemplateInfo['name'];
... ... @@ -158,6 +162,35 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :获取自定义模块的html
* @name :customHtml
* @author :lyh
* @method :post
* @time :2023/12/12 9:39
*/
public function customHtml($info,$source,$source_id,$is_custom){
$templateInfo = $this->webTemplateInfo($info['template_id'],$source,$source_id,$is_custom);
if($templateInfo === false){
//TODO::取新闻的默认页,后期如果更新,修改此处
$news_source = 3;
$mainInfo = $this->getCommonMain($news_source,$source_id);
$main_html = $mainInfo['main_html'];
$main_style = $mainInfo['main_css'];
$templateInfo['template_id'] = $info['template_id'];
}else{
$main_html = $templateInfo['main_html'];
$main_style = $templateInfo['main_css'];
}
//TODO::无独立头部时,取首页的头部和底部
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$info['template_id'],'project_id'=>$this->user['project_id'],'type'=>1]);
$html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
$templateInfo['html'] = $this->getHeadFooter($html);//组装数据
return $this->success($templateInfo);
}
/**
* @remark :获取中间公共部分
* @name :getCommonMain
* @author :lyh
... ... @@ -237,19 +270,16 @@ class BTemplateLogic extends BaseLogic
//查询当前模版是否已保存
DB::beginTransaction();
try {
$info = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],$this->param['source_id']);
//字符串截取
$this->param = $this->stringProcessing($this->param);
//保存头部信息
$this->saveCommonTemplate($this->param);
$param = $this->templateSaveParam($this->param);//组装数据
if($info === false){
$this->model->add($param);
//自定义模块单独处理
if(isset($this->param['is_custom']) && ($this->param['is_custom'] == 1)){
}else{
$this->model->edit($param,['id'=>$info['id']]);
}
$this->saveTemplateHtml($this->param);
//写入操作模版记录
$this->setTemplateLog($this->param);
}
DB::commit();
}catch (\Exception $e){
DB::rollBack();
... ... @@ -261,6 +291,27 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :保存可视化数据
* @name :saveTemplateHtml
* @author :lyh
* @method :post
* @time :2023/12/12 10:23
*/
public function saveTemplateHtml($param){
$info = $this->webTemplateInfo($this->param['template_id'],$param['source'],$param['source_id']);
//保存头部信息
$this->saveCommonTemplate($param);
$param['project_id'] = $this->user['project_id'];
unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
if($info === false){
$this->model->add($param);
}else{
$this->model->edit($param,['id'=>$info['id']]);
}
return true;//组装数据
}
/**
* @remark :保存头部公共数据
* @name :saveCommonTemplate
* @author :lyh
... ... @@ -383,19 +434,6 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :处理保存模版数据
* @name :templateParam
* @author :lyh
* @method :post
* @time :2023/7/21 16:30
*/
public function templateSaveParam($param){
$param['project_id'] = $this->user['project_id'];
unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
return $this->success($param);
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
... ...
... ... @@ -126,7 +126,6 @@ class KeywordLogic extends BaseLogic
*/
public function batchAdd(){
try {
$idArr = [];
foreach ($this->param['title'] as $v){
$this->model = new Keyword();
$info = $this->model->read(['title'=>$v]);
... ... @@ -136,16 +135,11 @@ class KeywordLogic extends BaseLogic
$param['updated_at'] = $param['created_at'];
$param['title'] = $v;
$id = $this->model->insertGetId($param);
$idArr[] = ['id'=>$id,'title'=>$v];
}
}
//批量生成路由
foreach ($idArr as $v){
$this->model = new Keyword();
$route = RouteMap::setRoute($v['title'], RouteMap::SOURCE_PRODUCT_KEYWORD, $v['id'], $this->user['project_id']);
$route = RouteMap::setRoute($v, RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $this->user['project_id']);
$this->curlDelRoute(['new_route'=>$route]);
$this->model->edit(['route'=>$route],['id'=>$v['id']]);
}
}
}catch (\Exception $e){
$this->fail('error');
}
... ...
... ... @@ -17,6 +17,8 @@ class BTemplate extends Base
const SOURCE_BLOG = 3;//博客
const SOURCE_NEWS = 4;//新闻详情页
const SOURCE_KEYWORD = 5;//聚合页
const SOURCE_CUSTOM = 1;//自定义模块
const STATUS = 0;
const TYPE_ONE = 1;
... ...