|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :InitHtmlLogic.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/27 10:39
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Http\Logic\Bside\BTemplate;
|
|
|
|
|
|
|
|
use App\Http\Logic\Bside\BaseLogic;
|
|
|
|
use App\Models\Template\BTemplate;
|
|
|
|
use App\Models\Template\BTemplateCommon;
|
|
|
|
use App\Models\Template\BTemplateMain;
|
|
|
|
use App\Models\Template\Setting;
|
|
|
|
use App\Models\Template\TemplateTypeMain;
|
|
|
|
|
|
|
|
class InitHtmlLogic extends BaseLogic
|
|
|
|
{
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
$this->param = $this->requestAll;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取非定制项目复合页数据
|
|
|
|
* @name :getDetailHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/27 10:50
|
|
|
|
*/
|
|
|
|
public function getDetailHtml(){
|
|
|
|
$template_id = $this->getTemplateId();
|
|
|
|
$is_custom = $this->param['is_custom'] ?? 0;//TODO::1:代表扩展模块
|
|
|
|
$is_list = $this->param['is_list'] ?? 0;//TODO::1:代表分类列表模块
|
|
|
|
//获取设置的默认中间部分
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_list'=>$is_list,'is_custom'=>$is_custom]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$main_html = $this->getInitModule($this->param['type'],$is_list);
|
|
|
|
$main_style = "<style id='globalsojs-styles'></style>";
|
|
|
|
}else{
|
|
|
|
$main_html = $mainInfo['main_html'];
|
|
|
|
$main_style = $mainInfo['main_css'];
|
|
|
|
}
|
|
|
|
$commonInfo = $this->getTypeCommonHtml($template_id,$this->param['type'],$is_custom,$is_list); //获取头部
|
|
|
|
$html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
|
|
|
|
$html = $this->getHeadFooter($html);//组装数据
|
|
|
|
return $this->success($html);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存复合页数据
|
|
|
|
* @name :saveDetailHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/27 11:57
|
|
|
|
*/
|
|
|
|
public function saveDetailHtml(){
|
|
|
|
$template_id = $this->getTemplateId();
|
|
|
|
$is_custom = $this->param['is_custom'] ?? 0;//TODO::1:代表扩展模块
|
|
|
|
$is_list = $this->param['is_list'] ?? 0;//TODO::1:代表分类列表模块
|
|
|
|
//保存中间部分
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom,'is_list'=>$is_list]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$data = [
|
|
|
|
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
|
|
|
|
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
|
|
|
|
'section_list_id'=>$this->param['section_list_id'] ?? '',
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'type'=>$this->param['type'],
|
|
|
|
'is_custom'=>$is_custom,
|
|
|
|
'is_list'=>$is_list
|
|
|
|
];
|
|
|
|
$bTemplateMainModel->add($data);
|
|
|
|
}else{
|
|
|
|
$data = [
|
|
|
|
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
|
|
|
|
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
|
|
|
|
'section_list_id'=>$this->param['section_list_id'] ?? '',
|
|
|
|
];
|
|
|
|
$bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
|
|
|
|
}
|
|
|
|
$this->saveDetailCommonHtml($this->param['html'],$this->param['type'],$template_id,$is_custom,$is_list);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* @remark :保存详情页模版头部底部
|
|
|
|
* @name :saveDetailCommonHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/15 18:12
|
|
|
|
*/
|
|
|
|
public function saveDetailCommonHtml($html,$template_id,$is_custom,$is_list){
|
|
|
|
$publicData = $this->handleCommonParam($html);
|
|
|
|
$templateCommonModel = new BTemplateCommon();
|
|
|
|
if($is_custom == BTemplate::SOURCE_CUSTOM){//扩展模块
|
|
|
|
//更新首页头部底部
|
|
|
|
$templateCommonModel->edit($publicData,['type'=>BTemplate::SOURCE_HOME,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
//查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
|
|
|
|
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{
|
|
|
|
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存时字符串处理
|
|
|
|
* @name :handleCommonParam
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/29 15:35
|
|
|
|
*/
|
|
|
|
public function handleCommonParam($html){
|
|
|
|
//字符串截取
|
|
|
|
$param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
|
|
|
|
$param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
|
|
|
|
$param['head_css'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
|
|
|
|
$param['footer_css'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
|
|
|
|
$footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
|
|
|
|
$param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
|
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :默认复合页数据
|
|
|
|
* @name :getProductModule
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/7/27 15:08
|
|
|
|
*/
|
|
|
|
public function getInitModule($type,$is_custom,$is_list){
|
|
|
|
if($is_custom == BTemplate::SOURCE_CUSTOM) {
|
|
|
|
$type = BTemplate::TYPE_CUSTOM;
|
|
|
|
}
|
|
|
|
$mainModel = new TemplateTypeMain();
|
|
|
|
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
|
|
|
|
return $info['main_html'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :根据type获取头部html
|
|
|
|
* @name :getHeaderFooter
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/15 18:06
|
|
|
|
*/
|
|
|
|
public function getTypeCommonHtml($template_id,$type,$is_custom,$is_list){
|
|
|
|
//获取首页公共部分
|
|
|
|
$templateCommonModel = new BTemplateCommon();
|
|
|
|
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>1]);
|
|
|
|
if($is_custom == BTemplate::SOURCE_CUSTOM){
|
|
|
|
return $this->success($commonInfo);
|
|
|
|
}
|
|
|
|
//判断当前项目是否有设置独立头部的权限
|
|
|
|
if(isset($this->user['configuration']['is_head']) && ($this->user['configuration']['is_head'] != 0)) {
|
|
|
|
//有独立头部,获取独立头部
|
|
|
|
$commonType = $this->getHeaderType($type,$is_list);
|
|
|
|
$commonTypeInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$commonType['type']]);
|
|
|
|
if($commonTypeInfo !== false){
|
|
|
|
$commonInfo = $commonTypeInfo;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success($commonInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $this->success(['type'=>$resultType]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取模版id
|
|
|
|
* @name :getTemplateId
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/27 10:51
|
|
|
|
*/
|
|
|
|
public function getTemplateId(){
|
|
|
|
$bSettingModel = new Setting();
|
|
|
|
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']],['id','template_id']);
|
|
|
|
if($bSettingInfo === false){
|
|
|
|
$this->fail('请先设置模板');
|
|
|
|
}
|
|
|
|
return $this->success($bSettingInfo['template_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取代码块
|
|
|
|
* @name :getVisualizationInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/17 14:44
|
|
|
|
*/
|
|
|
|
public function getCustomizedHtml(){
|
|
|
|
$is_list = $this->param['is_list'] ?? 0;
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$info = $bTemplateMainModel->read(['type'=>$this->param['type'],'is_list'=>$is_list]);
|
|
|
|
if($info === false){
|
|
|
|
$html = '';
|
|
|
|
}else{
|
|
|
|
$html = $info['main_html'];
|
|
|
|
}
|
|
|
|
return $this->success(['html'=>$html]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存定制html
|
|
|
|
* @name :saveHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/11/15 10:12
|
|
|
|
*/
|
|
|
|
public function saveCustomizedHtml(){
|
|
|
|
try {
|
|
|
|
$is_list = $this->param['is_list'] ?? 0;
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['type'=>$this->param['type'],'is_list'=>$is_list]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$mainData = [
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'type'=>$this->param['type'],
|
|
|
|
'is_list'=>$is_list,
|
|
|
|
'main_html'=>$this->param['html']
|
|
|
|
];
|
|
|
|
$bTemplateMainModel->add($mainData);
|
|
|
|
}else{
|
|
|
|
$bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
|
|
|
|
}
|
|
|
|
}catch (\Exception $exception){
|
|
|
|
$this->fail('保存失败,请联系开发人员');
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|