作者 lyh

gx

... ... @@ -45,7 +45,7 @@ class BTemplateController extends BaseController
'source.required' => 'source不能为空',
'source_id.required' => 'source_id不能为空',
]);
$info = $BTemplateLogic->getTemplate();
$info = $BTemplateLogic->getTemplateHtml();
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -57,21 +57,6 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :获取当前选择使用的模板
* @name :getModuleTemplate
* @author :lyh
* @method :post
* @time :2023/6/29 9:44
*/
public function getTemplate(){
$template_id = $this->getSettingTemplate($this->param['source'],$this->param['source_id']);//设置的模版id
$is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块
$is_list = $this->param['is_list'] ?? 0;//是否为
$data = $this->getHtml($template_id,$this->param['source'],$this->param['source_id'],$is_custom);
return $this->success($data);
}
/**
* @remark :获取可视化html
* @name :getTemplateHtml
* @author :lyh
... ... @@ -79,20 +64,41 @@ class BTemplateLogic extends BaseLogic
* @time :2023/12/27 14:48
*/
public function getTemplateHtml(){
$template_id = $this->getSettingTemplate($this->param['source'],$this->param['source_id']);//设置的模版id
$is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块
$is_list = $this->param['is_list'] ?? 0;//是否为列表页
$templateInfo = $this->model->read(['template_id'=>$template_id, 'source'=>$this->param['source'],'project_id'=>$this->user['project_id'],
'source_id'=>$this->param['source_id'], 'is_custom'=>$is_custom, 'is_list'=>$is_list]);
$template_id = $this->getSettingTemplate($this->param['source'],$is_list);//设置的模版id
$templateInfo = $this->model->read([
'template_id'=>$template_id, 'source'=>$this->param['source'],
'project_id'=>$this->user['project_id'], 'source_id'=>$this->param['source_id'],
'is_custom'=>$is_custom, 'is_list'=>$is_list
]);
if($templateInfo === false){
if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//处理定制页面初始数据
$html = $this->isCustomizedPage($this->param['source'],$this->param['source_id']);//查看当前页面是否定制
$html = $this->isCustomizedPage($this->param['source'],$is_list);//获取定制页面的html
return $this->success(['html'=>$html,'template_id'=>$template_id]);
}
$mainInfo = $this->getMAinHtml($this->param['source'],$this->param['source_id'],$is_custom);//获取中间部分代码
$mainInfo = $this->getMAinHtml($this->param['source'],$is_custom,$is_list);//获取中间部分代码
}else{
if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码
$type = $this->getHeaderType($this->param['source'], $is_list);//获取头部底部类型
$commonInfo = $this->getCommonHtml($type,$is_list,0);//获取定制头部
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
return $this->success(['html'=>$html,'template_id'=>$template_id,'id'=>$templateInfo['id'],'updated_at'=>$templateInfo['updated_at']]);
}
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
}
$data = $this->getHtml($template_id,$this->param['source'],$this->param['source_id'],$is_custom);
return $this->success($data);
$type = $this->getHeaderType($this->param['source'], $is_list);//获取头部底部类型
$commonInfo = $this->getCommonHtml($type,$is_list,$template_id);//获取定制头部
$html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
$result = ['html'=>$html,'template_id'=>$template_id];
if($templateInfo !== false)
{
$result['id'] = $templateInfo['id'];
$result['updated_at'] = $templateInfo['updated_at'];
}
return $this->success($result);
}
/**
... ... @@ -102,50 +108,34 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/12/27 15:00
*/
public function getMAinHtml($source,$source_id,$is_custom,$is_list){
//查询有没有公共详情模板
public function getMAinHtml($type,$is_custom,$is_list){
//获取设置的默认中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$type]);
$mainInfo = $bTemplateMainModel->read(['type'=>$type,'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($mainInfo === false){
$data['main_html'] = $this->getModule($type);
$data['main_css'] = "<style id='globalsojs-styles'></style>";
$main_html = $this->getInitModule($type,$is_custom,$is_list);
$main_css = "<style id='globalsojs-styles'></style>";
}else{
$data['main_html'] = $mainInfo['main_html'];
$data['main_css'] = $mainInfo['main_css'];
$main_html = $mainInfo['main_html'];
$main_css = $mainInfo['main_css'];
}
return ['main_html'=>$main_html,'main_css'=>$main_css];
}
/**
* @remark :获取可视化装修的html
* @name :getTemplateHtml
* @remark :默认复合页数据
* @name :getProductModule
* @author :lyh
* @method :post
* @time :2023/12/13 10:47
* @time :2023/7/27 15:08
*/
public function getHtml($template_id,$source,$source_id,$is_custom){
$templateInfo = $this->webTemplateInfo($template_id,$source,$source_id,$is_custom);
if($templateInfo === false){
if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//处理定制页面初始数据
$html = $this->isCustomizedPage($source,$source_id);//查看当前页面是否定制
return $this->success(['html'=>$html,'template_id'=>$template_id]);
}
$mainInfo = $this->getCommonMain($source,$source_id,$is_custom);//获取中间部分代码
}else{
if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码
$type = $this->getCustomizedType($source, $source_id);//定制获取头部底部类型
$commonInfo = $this->getCommonPage($type,$this->user['project_id'],0);//获取定制头部
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
return $this->success(['html'=>$html,'template_id'=>$template_id,'id'=>$templateInfo['id'],'updated_at'=>$templateInfo['updated_at']]);
}
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
public function getInitModule($type,$is_custom,$is_list){
if($is_custom == BTemplate::SOURCE_CUSTOM) {
$type = BTemplate::TYPE_CUSTOM;
}
$commonInfo = $this->getCommonPage($source,$source_id,$template_id);//获取头部
$html = $commonInfo['head_css'].$mainInfo['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$mainInfo['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
$result = ['html'=>$html,'template_id'=>$template_id];
if($templateInfo !== false){$result['id'] = $templateInfo['id'];$result['updated_at'] = $templateInfo['updated_at'];}
return $this->success($result);
$mainModel = new TemplateTypeMain();
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
return $info['main_html'];
}
/**
... ... @@ -172,19 +162,19 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/12/13 10:55
*/
public function isCustomizedPage($source,$source_id)
public function isCustomizedPage($source,$is_list)
{
$type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
//TODO::获取初始代码
$bTemplateMainModel = new BTemplateMain();
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$type]);
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list]);
if($customHtmlInfo === false){
$this->fail('定制页面,请先上传代码块');
}
$commonInfo = $this->getCommonPage($type,$this->user['project_id'],0);//获取定制头部
$commonInfo = $this->getCommonHtml($type,$is_list,0);//获取定制头部
if($commonInfo !== false){
$customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
}
... ... @@ -194,22 +184,70 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :定制界面根据source+source_id获取type类型
* @remark :独立头部获取头部底部类型
* @name :getHeaderType
* @author :lyh
* @method :post
* @time :2023/12/27 11:36
*/
public function getHeaderType($type,$is_list){
$resultType = BTemplate::SOURCE_HOME;
if($type == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_THREE;
}else{
$resultType = BTemplate::TYPE_TWO;
}
}
if($type == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_FIVE;
}else{
$resultType = BTemplate::TYPE_FOUR;
}
}
if($type == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_SEVEN;
}else{
$resultType = BTemplate::TYPE_SIX;
}
}
if($type == BTemplate::SOURCE_KEYWORD){
$resultType = BTemplate::TYPE_EIGHT;
}
return $this->success($resultType);
}
/**
* @remark :定制界面根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/11/16 11:20
*/
public function getCustomizedType($source,$source_id){
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_ONE;
if($source == BTemplate::SOURCE_PRODUCT){
if($source_id == 0){$type = BTemplate::TYPE_THREE;}else{$type = BTemplate::TYPE_TWO;}
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_THREE;
}else{
$type = BTemplate::TYPE_TWO;
}
}
if($source == BTemplate::SOURCE_BLOG){
if($source_id == 0){$type = BTemplate::TYPE_FIVE;}else{$type = BTemplate::TYPE_FOUR;}
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_FIVE;
}else{
$type = BTemplate::TYPE_FOUR;
}
}
if($source == BTemplate::SOURCE_NEWS){
if($source_id == 0){$type = BTemplate::TYPE_SEVEN;}else{$type = BTemplate::TYPE_SIX;}
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_SEVEN;
}else{
$type = BTemplate::TYPE_SIX;
}
}
return $type;
}
... ... @@ -221,13 +259,14 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/12/13 10:48
*/
public function getSettingTemplate($source,$source_id){
public function getSettingTemplate($source,$is_list){
$template_id = 0;
if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION) {//定制项目
$type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//是定制界面
return $this->success(0);
return $this->success($template_id);
}
}
$bSettingModel = new Setting();
... ... @@ -235,95 +274,172 @@ class BTemplateLogic extends BaseLogic
if($info === false){
$this->fail('请先选择模版');
}
return $this->success($info['template_id']);
$template_id = $info['template_id'];
return $this->success($template_id);
}
/**
* @remark :根据参数获取数据详情
* @name :webTemplateInfo
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @author :lyh
* @method :post
* @time :2023/7/25 16:41
* @time :2023/10/21 16:55
*/
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);
public function getCommonHtml($source,$is_list,$template_id){
$is_head = $this->user['configuration']['is_head'] ?? 0;
$data = [
'template_id' => $template_id,
'project_id' => $this->user['project_id']
];
if($is_head != BTemplate::IS_NO_HEADER) {
//查看页面是否设置自定义头部底部
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if($pageInfo !== false){
$commonInfo = [];
if ($source == BTemplate::SOURCE_BLOG) {//产品页
$commonInfo = $this->getProductCommonHtml($data,$is_list,$pageInfo);
}
if ($source == BTemplate::SOURCE_BLOG) {//博客页
$commonInfo = $this->getBlogCommonHtml($data,$is_list,$pageInfo);
}
if ($source == BTemplate::SOURCE_NEWS) {//新闻页
$commonInfo = $this->getNewsCommonHtml($data,$is_list,$pageInfo);
}
if ($source == BTemplate::SOURCE_KEYWORD) {//聚合页
$commonInfo = $this->getKeywordCommonHtml($data,$pageInfo);
}
if(!empty($commonInfo)){
return $this->success($commonInfo);
}
}
}
//获取首页公共的头部和底部
$commonInfo = $this->getHomeCommonHtml($data);
return $commonInfo;
}
/**
* @remark :获取中间公共部分
* @name :getCommonMain
* @remark :获取首页头部底部
* @name :getHomeCommonHtml
* @author :lyh
* @method :post
* @time :2023/10/24 15:58
* @time :2023/12/27 16:11
*/
public function getCommonMain($source,$source_id,$is_custom){
$data = [];
if($is_custom == BTemplate::SOURCE_CUSTOM){
if($source_id != 0){$type = BTemplate::TYPE_CUSTOM;}else{$type = BTemplate::TYPE_CUSTOM_LIST;}
}else{
if ($source == BTemplate::SOURCE_PRODUCT) {if ($source_id != 0) {$type = BTemplate::TYPE_TWO;} else {$type = BTemplate::TYPE_THREE;}}
if ($source == BTemplate::SOURCE_BLOG) {if ($source_id != 0) {$type = BTemplate::TYPE_FOUR;} else {$type = BTemplate::TYPE_FIVE;}}
if ($source == BTemplate::SOURCE_NEWS) {if ($source_id != 0) {$type = BTemplate::TYPE_SIX;} else {$type = BTemplate::TYPE_SEVEN;}}
if ($source == BTemplate::SOURCE_KEYWORD) {$type = BTemplate::TYPE_EIGHT;}
public function getHomeCommonHtml($data){
$data['type'] = BTemplate::SOURCE_HOME;
$commonTemplateModel = new BTemplateCommon();
return $commonTemplateModel->read($data);
}
/**
* @remark :聚合页
* @name :getKeywordCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/27 16:09
*/
public function getKeywordCommonHtml($data,$pageInfo){
$commonInfo = [];
$commonTemplateModel = new BTemplateCommon();
$data['type'] = BTemplate::TYPE_EIGHT;
if ($pageInfo['polymerization'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
//查询有没有公共详情模板
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$type]);
if($mainInfo === false){
$data['main_html'] = $this->getModule($type);
$data['main_css'] = "<style id='globalsojs-styles'></style>";
}else{
$data['main_html'] = $mainInfo['main_html'];
$data['main_css'] = $mainInfo['main_css'];
return $this->success($commonInfo);
}
/**
* @remark :产品头部底部
* @name :getProductCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/27 16:01
*/
public function getProductCommonHtml($data,$is_list,$pageInfo){
$commonInfo = [];
$commonTemplateModel = new BTemplateCommon();
if($is_list == BTemplate::IS_LIST){
$data['type'] = BTemplate::TYPE_THREE;
if ($pageInfo['product_list'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
} else {
$data['type'] = BTemplate::TYPE_TWO;
if ($pageInfo['product_details'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
}
return $data;
return $this->success($commonInfo);
}
/**
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @remark :博客头部
* @name :getBlogCommonHtml
* @author :lyh
* @method :post
* @time :2023/10/21 16:55
* @time :2023/12/27 16:05
*/
public function getCommonPage($source,$source_id,$template_id){
if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
//查看页面是否设置自定义头部底部
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo != false) {
$commonTemplateModel = new BTemplateCommon();
$data = [
'template_id' => $template_id,
'project_id' => $this->user['project_id']
];
if ($source == BTemplate::SOURCE_PRODUCT) {//产品页
if($source_id != 0){$data['type'] = BTemplate::TYPE_TWO;if ($pageInfo['product_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = BTemplate::TYPE_THREE;if ($pageInfo['product_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == BTemplate::SOURCE_BLOG) {//博客页
if ($source_id != 0) {$data['type'] = BTemplate::TYPE_FOUR;if ($pageInfo['blog_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = BTemplate::TYPE_FIVE;if ($pageInfo['blog_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == BTemplate::SOURCE_NEWS) {//新闻页
if ($source_id != 0) {$data['type'] = BTemplate::TYPE_SIX;if ($pageInfo['news_details'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
else {$data['type'] = BTemplate::TYPE_SEVEN;if ($pageInfo['news_list'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}}
if ($source == BTemplate::SOURCE_KEYWORD) {//聚合页
$data['type'] = BTemplate::TYPE_EIGHT;if ($pageInfo['polymerization'] != 0) {$commonInfo = $commonTemplateModel->read($data);}}
public function getBlogCommonHtml($data,$is_list,$pageInfo){
$commonInfo = [];
$commonTemplateModel = new BTemplateCommon();
if ($is_list == BTemplate::IS_LIST) {
$data['type'] = BTemplate::TYPE_SEVEN;
if ($pageInfo['blog_list'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
} else {
$data['type'] = BTemplate::TYPE_SIX;
if ($pageInfo['blog_details'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
}
//获取首页公共的头部和底部
if(!isset($commonInfo) || $commonInfo === false){
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>BTemplate::TYPE_ONE]);
return $this->success($commonInfo);
}
/**
* @remark :新闻头部
* @name :getNewsCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/27 16:07
*/
public function getNewsCommonHtml($data,$is_list,$pageInfo){
$commonInfo = [];
$commonTemplateModel = new BTemplateCommon();
if ($is_list == BTemplate::IS_LIST) {
$data['type'] = BTemplate::TYPE_SEVEN;
if ($pageInfo['news_list'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
} else {
$data['type'] = BTemplate::TYPE_SIX;
if ($pageInfo['news_details'] != 0) {
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$commonInfo = [];
}
}
}
return $commonInfo;
return $this->success($commonInfo);
}
/**
... ... @@ -336,28 +452,40 @@ class BTemplateLogic extends BaseLogic
public function templateSave(){
//演示项目不允许修改
$this->showProjectNoEdit($this->param['source']);
DB::beginTransaction();
try {
$this->param = $this->handleDefaultString($this->param);//设置默认字符
$templateInfo = $this->webTemplateInfo($this->param['template_id'],$this->param['source'],
$this->param['source_id'],$this->param['is_custom']);
if($templateInfo === false){//执行新增
$this->templateAddHtml($this->param['html'], $this->param['source'], $this->param['source_id'],
$this->param['template_id'], $this->param['section_list_id'], $this->param['is_custom']);
}else{//执行编辑
$this->templateEditHtml($this->param['html'],$this->param['source'],$this->param['source_id'],
$this->param['template_id'],$this->param['section_list_id'], $this->param['is_custom']);
}
//更新头部信息
$this->saveCommonHtml($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id']);
$this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('系统错误,请联系管理员');
$this->param = $this->handleDefaultString($this->param);//设置默认数据
$templateInfo = $this->model->read([
'template_id'=>$this->param['template_id'],
'source'=>$this->param['source'],
'source_id'=>$this->param['source_id'],
'is_custom'=>$this->param['is_custom'],
'is_list'=>$this->param['is_list']
]);
if($templateInfo === false){//执行新增
$data = [
'source'=>$this->param['source'], 'source_id'=>$this->param['source_id'],'type'=>BTemplate::PAGE_HTML,
'template_id'=>$this->param['template_id'], 'project_id'=>$this->user['project_id'],
'section_list_id'=>$this->param['section_list_id'],'is_custom'=>$this->param['is_custom'],
'is_list'=>$this->param['is_list']
];
$data = $this->handleVisualizationParam($this->param['html'],$this->param['source'],$this->param['is_list'],$data);
$this->model->add($data);
}else{//执行编辑
$condition = [
'source'=>$this->param['source'], 'source_id'=>$this->param['source'],
'is_custom'=>$this->param['is_custom'], 'template_id'=>$this->param['template_id'],
'is_list'=>$this->param['is_list']
];
$data = [
'section_list_id'=>$this->param['section_list_id']
];
$data = $this->handleVisualizationParam($this->param['html'],$this->param['source'],$this->param['is_list'],$data);
$this->model->edit($data,$condition);
}
//更新头部信息
$this->saveCommonHtml($this->param['html'],$this->param['source'],$this->param['is_list'],$this->param['template_id']);
$this->setOperationRecords($this->param['html'],$this->param['source'],$this->param['source_id'],$this->param['template_id'],$this->param['is_custom']);
//通知更新
$this->homeOrProduct($this->param['source'],$this->param['source_id'],$this->param['is_custom']);
$this->homeOrProduct($this->param['source'],$this->param['source_id'],$this->param['is_custom'],$this->param['is_list']);
return $this->success();
}
... ... @@ -369,66 +497,23 @@ class BTemplateLogic extends BaseLogic
* @time :2023/12/15 10:30
*/
public function handleDefaultString($param){
if(!isset($param['template_id'])){
$param['template_id'] = 0;
}
if(!isset($param['is_custom'])){
$param['is_custom'] = 0;
}
if(!isset($param['section_list_id'])){
$param['section_list_id'] = '';
}
$param['template_id'] = $param['template_id'] ?? 0;
$param['is_custom'] = $param['is_custom'] = 0;
$param['section_list_id'] = $param['section_list_id'] ?? '';
$param['is_list'] = $param['is_list'] ?? 0;
return $this->success($param);
}
/**
* @remark :可视化添加数据
* @name :templateAddHtml
* @author :lyh
* @method :post
* @time :2023/12/15 10:15
*/
public function templateAddHtml($html,$source,$source_id,$template,$section_list_id,$is_custom){
$data = [
'source'=>$source, 'source_id'=>$source_id,'type'=>BTemplate::PAGE_HTML,
'template_id'=>$template, 'project_id'=>$this->user['project_id'],
'section_list_id'=>$section_list_id,'is_custom'=>$is_custom,
];
$data = $this->handleVisualizationParam($html,$source,$source_id,$data);
$this->model->add($data);
return true;
}
/**
* @remark :可视化更新html
* @name :templateEditHtml
* @author :lyh
* @method :post
* @time :2023/12/15 10:26
*/
public function templateEditHtml($html,$source,$source_id,$template,$section_list_id,$is_custom){
$condition = [
'source'=>$source, 'source_id'=>$source_id,
'is_custom'=>$is_custom, 'template_id'=>$template
];
$data = [
'section_list_id'=>$section_list_id
];
$data = $this->handleVisualizationParam($html,$source,$source_id,$data);
$this->model->edit($data,$condition);
return true;
}
/**
* @remark :处理可视化数据
* @name :handleProjectParam
* @author :lyh
* @method :post
* @time :2023/12/15 10:59
*/
public function handleVisualizationParam($html,$source, $source_id,$data){
public function handleVisualizationParam($html,$source, $is_list,$data){
if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//定制项目
$type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
if (in_array($type, $page_array)) {//当前页面是定制界面
... ... @@ -455,8 +540,8 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/12/13 17:05
*/
public function saveCommonHtml($html,$source,$source_id,$template_id){
$type = $this->getType($source,$source_id,$template_id);//获取头部类型1-9(首页到自定义页面)
public function saveCommonHtml($html,$source,$is_list,$template_id){
$type = $this->getType($source,$is_list,$template_id);//获取头部类型1-9(首页到自定义页面)
$templateCommonModel = new BTemplateCommon();
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);//查看当前头部是否存在
$handleInfo = $this->handleCommonParam($html);
... ... @@ -525,32 +610,70 @@ class BTemplateLogic extends BaseLogic
return $this->success($param);
}
/**
* @remark :获取设置的类型
* @remark :保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($source,$source_id,$template_id){
$type = 1;//首页公共头部底部
public function getType($source,$is_list,$template_id){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($template_id == 0){//保存上传的代码块时,默认为独立头部
$this->user['configuration']['is_head'] == 1;
$is_head == BTemplate::IS_HEADER;
}
//查看页面是否设置自定义头部底部
if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo !== false) {
if ($source == BTemplate::SOURCE_PRODUCT) {if ($source_id != 0) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_TWO;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_THREE;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($source_id != 0) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_FOUR;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_FIVE;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($source_id != 0) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_SIX;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_SEVEN;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_EIGHT;}}
if ($pageInfo === false) {
return $this->success($type);
}
switch ($source){
case BTemplate::SOURCE_PRODUCT:
if ($is_list != BTemplate::IS_LIST) {
if ($pageInfo['product_details'] != 0) {
$type = BTemplate::TYPE_TWO;
}
} else {
if ($pageInfo['product_list'] != 0) {
$type = BTemplate::TYPE_THREE;
}
}
break;
case BTemplate::SOURCE_BLOG:
if ($is_list != BTemplate::IS_LIST) {
if ($pageInfo['blog_details'] != 0) {
$type = BTemplate::TYPE_FOUR;
}
} else {
if ($pageInfo['blog_details'] != 0) {
$type = BTemplate::TYPE_FIVE;
}
}
break;
case BTemplate::SOURCE_BLOG:
if ($is_list != BTemplate::IS_LIST) {
if ($pageInfo['news_details'] != 0) {
$type = BTemplate::TYPE_SIX;
}
} else {
if ($pageInfo['news_list'] != 0) {
$type = BTemplate::TYPE_SEVEN;
}
}
break;
case BTemplate::SOURCE_KEYWORD:
if ($pageInfo['polymerization'] != 0) {
$type = BTemplate::TYPE_EIGHT;
}
break;
default:
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
break;
}
return $this->success($type);
}
return $type;
}
/**
... ... @@ -561,6 +684,9 @@ class BTemplateLogic extends BaseLogic
* @time :2023/8/23 11:16
*/
public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){
if($source != BTemplate::SOURCE_HOME){
return true;
}
$data = [
'template_id'=>$template_id,
'project_id'=>$this->user['project_id'],
... ... @@ -590,22 +716,38 @@ class BTemplateLogic extends BaseLogic
* @method :post
* @time :2023/7/31 16:05
*/
public function homeOrProduct($source,$source_id = 0,$is_custom = 0){
public function homeOrProduct($source,$source_id = 0,$is_custom = 0,$is_list = 0){
if($is_custom == 0){
if($source == BTemplate::SOURCE_HOME){
RouteMap::setRoute('index', RouteMap::SOURCE_PAGE, 0, $this->user['project_id']);
$type = RouteMap::SOURCE_PAGE;
}elseif($source == BTemplate::SOURCE_PRODUCT){
$type = RouteMap::SOURCE_PRODUCT;
if($is_list == BTemplate::IS_LIST){
$type = RouteMap::SOURCE_PRODUCT_CATE;
}else{
$type = RouteMap::SOURCE_PRODUCT;
}
}elseif($source == BTemplate::SOURCE_BLOG){
$type = RouteMap::SOURCE_BLOG;
if($is_list == BTemplate::IS_LIST){
$type = RouteMap::SOURCE_BLOG_CATE;
}else{
$type = RouteMap::SOURCE_BLOG;
}
}elseif($source == BTemplate::SOURCE_NEWS){
$type = RouteMap::SOURCE_NEWS;
if($is_list == BTemplate::IS_LIST){
$type = RouteMap::SOURCE_NEWS_CATE;
}else{
$type = RouteMap::SOURCE_NEWS;
}
}else{
$type = 'all';
}
}else{
$type = RouteMap::SOURCE_MODULE;
if($is_list == BTemplate::IS_LIST){
$type = RouteMap::SOURCE_MODULE_CATE;
}else{
$type = RouteMap::SOURCE_MODULE;
}
}
$route = RouteMap::getRoute($type,$source_id,$this->user['project_id']);
$this->addUpdateNotify($type,$route);
... ... @@ -658,19 +800,6 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :默认产品模块
* @name :getProductModule
* @author :lyh
* @method :post
* @time :2023/7/27 15:08
*/
public function getModule($type){
$mainModel = new TemplateTypeMain();
$info = $mainModel->read(['type'=>$type]);
return $info['main_html'];
}
/**
* @remark :设置主题公共head
* @name :setHeadInfo
* @author :lyh
... ... @@ -866,76 +995,4 @@ class BTemplateLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :保存详情模板数据
* @name :saveDetail
* @author :lyh
* @method :post
* @time :2023/10/24 11:53
*/
public function saveDetail(){
$bSettingModel = new Setting();
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($bSettingInfo === false){
$this->fail('请先设置模板');
}
$is_custom = $this->param['is_custom'] ?? 0;//扩展模块详情模版
$data = [
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
];
$data['section_list_id'] = $this->param['section_list_id'];
//保存中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom]);
if($mainInfo === false){
$data['project_id'] = $this->user['project_id'];
$data['type'] = $this->param['type'];
$data['is_custom'] = $is_custom;
$bTemplateMainModel->add($data);
}else{
$bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
}
$this->saveDetailCommonHtml($is_custom,$this->param['type'],$bSettingInfo['template_id'],$this->param['html']);
return $this->success();
}
/**
* @remark :保存详情页模版头部底部
* @name :saveDetailCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/15 18:12
*/
public function saveDetailCommonHtml($is_custom,$type,$template_id,$html){
$publicData = [
'head_html' => characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_css' => characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'footer_html' => characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
'footer_css' => characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
'other'=>str_replace('<header','',characterTruncation($html,"/<link id=\"google-fonts-link\"(.*?)<header/s")),
];
//查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
if($is_custom == BTemplate::SOURCE_CUSTOM){//扩展模块
$this->user['configuration']['is_head'] = BTemplate::SOURCE_NO_CUSTOM;
}
$templateCommonModel = new BTemplateCommon();
if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
$templateCommonInfo = $templateCommonModel->read(['type'=>$type,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
if($templateCommonInfo === false){
$publicData['type'] = $type;
$publicData['project_id'] = $this->user['project_id'];
$publicData['template_id'] = $template_id;
$templateCommonModel->add($publicData);
}else{
$templateCommonModel->edit($publicData,['id'=>$templateCommonInfo['id']]);
}
}else{
//更新首页头部底部
$templateCommonModel->edit($publicData,['type'=>1,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
}
return true;
}
}
... ...