作者 lyh

gx

... ... @@ -13,7 +13,6 @@ use App\Http\Logic\Bside\BaseLogic;
use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\Setting;
... ... @@ -65,14 +64,13 @@ class BTemplateLogLogic extends BaseLogic
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom']];
//TODO::还原头部+底部
$bTemplateModel->edit(['html'=>$info['text']],$condition);
$commonData = [
'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'],
'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
];
$type = $this->getCustomizedType($info['source'],$info['is_list']);
$commonTemplateModel = new BTemplateCommon();
//还原头部
$condition = ['template_id'=>$info['template_id'],'source'=>$info['source'],
'is_list'=>$info['is_list'],'is_custom'=>$info['is_custom'],'project_id'=>$this->user['project_id']];
$condition['common_type'] = BTemplate::COMMON_HEAD;
$commonTemplateModel->edit(['head'=>$info['head_html'], 'head_style'=>$info['head_css']],$condition);
$condition['common_type'] = BTemplate::COMMON_FOOTER;
$commonTemplateModel->edit(['footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']],$condition);
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
return $this->success();
}
... ... @@ -101,9 +99,18 @@ class BTemplateLogLogic extends BaseLogic
$bTemplateModel->edit($data,$condition);
//还原头部+底部
$commonData = [
'head_html'=>$info['head_html'], 'head_style'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_style'=>$info['footer_css'],'other'=>$info['other']
'head_html'=>$info['head_html'], 'head_css'=>$info['head_css'], 'footer_html'=>$info['footer_html'], 'footer_css'=>$info['footer_css']
];
$this->saveTemplateCom($commonData,$info['template_id'],$info['source'],$info['is_list'],$info['is_custom']);
$commonTemplateModel = new BTemplateCommon();
$type = $this->getType($info['source'],$info['is_list'],$info['is_custom']);
$commonTemplateModel->edit($commonData,['template_id'=>$info['template_id'],'type'=>$type,'project_id'=>$this->user['project_id']]);
if(!empty($info['other'])){
$commonTemplateModel->edit(['other'=>$info['other']],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$info['type']]);
}else{
$footer_other = str_replace('<header','',characterTruncation($info['text'],'/<style id="globalsojs-footer">(.*?)<header/s'));
$other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
$commonTemplateModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$info['template_id'],'type'=>$type]);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
... ... @@ -111,40 +118,36 @@ class BTemplateLogLogic extends BaseLogic
}
/**
* @remark :保存公共部分(头部。底部。连接部分)
* @name :saveTemplateCom
* @remark :定制页面头部类型---根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2024/4/29 10:32
* @time :2023/11/16 11:20
*/
public function saveTemplateCom($handleInfo,$template_id,$source,$is_list,$is_custom){
$typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
$templateComModel = new BTemplateCom();
foreach ($typeArr as $type){
if($type == BTemplate::COMMON_HEAD){
$param['html'] = $handleInfo['head_html'];
$param['html_style'] = $handleInfo['head_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
}elseif ($type == BTemplate::COMMON_FOOTER){
$param['html'] = $handleInfo['footer_html'];
$param['html_style'] = $handleInfo['footer_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_HOME;
if($source == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_PRODUCT_LIST;
}else{
$param['html'] = $handleInfo['other'];
$param['html_style'] = null;
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
$type = BTemplate::TYPE_PRODUCT_DETAIL;
}
//查看当前数据是否还存在
$condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
$info = $templateComModel->read($condition);
if($info === false){
$data = array_merge($param,$condition);
$templateComModel->add($data);
}
if($source == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_BLOG_LIST;
}else{
$templateComModel->edit($param,$condition);
$type = BTemplate::TYPE_BLOG_DETAIL;
}
}
return $this->success();
if($source == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_NEWS_LIST;
}else{
$type = BTemplate::TYPE_NEWS_DETAIL;
}
}
return $type;
}
/**
... ... @@ -154,30 +157,27 @@ class BTemplateLogLogic extends BaseLogic
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
if($template_id == 0){//定制全为独立头部和底部
$type = $source;
return $this->success($type);
}
$type = BTemplate::SOURCE_COM;//公共头部底部
public function getType($source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo === false) {
return $this->success($type);
}
if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
}
return $this->success($type);
}
... ...
... ... @@ -7,7 +7,6 @@ use App\Models\Project\PageSetting;
use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\Setting;
... ... @@ -50,81 +49,13 @@ class CustomTemplateLogic extends BaseLogic
$this->fail('当前数据不存在');
}
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
$html = $this->getTemplateComHtml($info['html'],$info['html_style']);
$html = $this->getBodyHeaderFooter($info['html'],$info['html_style']);
$info['html'] = $this->getHeadFooter($html);
}
return $this->success($info);
}
/**
* @remark :非定制获取头部+底部
* @name :getTemplateComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 16:53
*/
public function getTemplateComHtml($html,$html_style){
$headComInfo = $this->getHeadComHtml(['common_type'=>BTemplate::COMMON_HEAD]);
$bTemplateComModel = new BTemplateCom();
$condition['common_type'] = BTemplate::COMMON_OTHER;
$condition['source'] = $headComInfo['source'];
$otherInfo = $bTemplateComModel->read($condition);
if($otherInfo === false){
$this->fail('获取失败,请联系管理员');
}
$footerComInfo = $this->getFooterComHtml();
$commonInfo = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
$html = $commonInfo['head_style'].$html_style.$commonInfo['footer_style'].$commonInfo['other']. $commonInfo['head_html'].$html.$commonInfo['footer_html'];
return $this->success($html);
}
/**
* @remark :公共头部
* @name :HeadComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 17:20
*/
public function getHeadComHtml($condition){
$bTemplateComModel = new BTemplateCom();
$condition['source'] = $this->getType();
$condition['common_type'] = BTemplate::COMMON_HEAD;
$headComInfo = $bTemplateComModel->read($condition);
if($headComInfo === false){
//取默认公共的
$condition['source'] = BTemplate::SOURCE_COM;
$headComInfo = $bTemplateComModel->read($condition);
if($headComInfo === false){
$this->fail('获取失败,请联系管理员');
}
}
return $this->success($headComInfo);
}
/**
* @remark :公共底部
* @name :footerComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 17:18
*/
public function getFooterComHtml(){
$bTemplateComModel = new BTemplateCom();
$condition['common_type'] = BTemplate::COMMON_FOOTER;
$condition['source'] = $this->getType(BTemplate::COMMON_FOOTER);
$footerComInfo = $bTemplateComModel->read($condition);
if($footerComInfo === false){
//取默认首页的
$condition['source'] = BTemplate::SOURCE_COM;
$footerComInfo = $bTemplateComModel->read($condition);
if($footerComInfo === false){
$this->fail('获取失败,请联系管理员');
}
}
return $this->success($footerComInfo);
}
/**
* @remark :保存自定义界面
* @name :customTemplateSave
* @author :lyh
... ... @@ -177,16 +108,15 @@ class CustomTemplateLogic extends BaseLogic
if($bSettingInfo === false){
$this->fail('请先选择模版');
}
$handleInfo = $this->handleResultParam($html);
$this->saveTemplateCom($handleInfo,$bSettingInfo['template_id']);
$this->param['html'] = $handleInfo['main_html'];
$this->param['html_style'] = $handleInfo['main_style'];
$this->saveCommonTemplate($html,$bSettingInfo['template_id']);
$this->param['html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
$this->param['html_style'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
}
$rs = $this->model->edit($this->param,['id'=>$this->param['id'],'project_id'=>$this->user['project_id']]);
if($rs === false){
$this->fail('系统错误,请联系管理');
}
$this->setTemplateLog($bSettingInfo['template_id'],$handleInfo,$this->param['id']);
$this->setTemplateLog($bSettingInfo['template_id'],$html,$this->param['id']);
//通知
$this->addUpdateNotify(RouteMap::SOURCE_PAGE,$info['url']);
$this->curlDelRoute(['route'=>$info['url'],'new_route'=>$info['url']]);
... ... @@ -201,7 +131,6 @@ class CustomTemplateLogic extends BaseLogic
* @time :2023/8/23 11:16
*/
public function setTemplateLog($template_id,$html,$source_id){
$handleInfo = $this->handleResultParam($html);
$data = [
'template_id'=>$template_id,
'project_id'=>$this->user['project_id'],
... ... @@ -209,99 +138,71 @@ class CustomTemplateLogic extends BaseLogic
'text'=>$html,
'source'=>9,
'source_id'=>$source_id,
'head_html'=>$handleInfo['head_html'],
'head_css'=>$handleInfo['head_style'],
'footer_html'=>$handleInfo['footer_html'],
'footer_css'=>$handleInfo['footer_style'],
'main_html' => $handleInfo['main_html'],
'main_css' => $handleInfo['main_style'],
'other'=>$handleInfo['other']
'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'),
'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
];
$footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
$data['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
$bTemplateLogModel = new BTemplateLog();
return $bTemplateLogModel->add($data);
}
/**
* @remark :截取数据返回
* @name :handleResultParam
* @remark :保存头部公共数据
* @name :saveCommonTemplate
* @author :lyh
* @method :post
* @time :2024/5/6 14:14
* @time :2023/10/13 14:27
*/
public function handleResultParam($html){
$handleInfo = [
public function saveCommonTemplate($html,$template_id){
$type = $this->getType();
$templateCommonModel = new BTemplateCommon();
$info = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);
$data = [
'head_html'=>characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_style'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'head_css'=>characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'footer_html'=>characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s'),
'footer_style'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
'main_html' => characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_style' => characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
'footer_css'=>characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
];
$footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
$other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
$handleInfo['other'] = $other;
return $this->success($handleInfo);
}
/**
* @remark :保存公共部分(头部。底部。连接部分)
* @name :saveTemplateCom
* @author :lyh
* @method :post
* @time :2024/4/29 10:32
*/
public function saveTemplateCom($handleInfo,$template_id){
$typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
$templateComModel = new BTemplateCom();
foreach ($typeArr as $type){
if($type == BTemplate::COMMON_HEAD){
$param['html'] = $handleInfo['head_html'];
$param['html_style'] = $handleInfo['head_style'];
$typeSource = $this->getType($type);//头部是否为独立头部
}elseif ($type == BTemplate::COMMON_FOOTER){
$param['html'] = $handleInfo['footer_html'];
$param['html_style'] = $handleInfo['footer_style'];
$typeSource = $this->getType($type);
}else{
$param['html'] = $handleInfo['other'];
$param['html_style'] = null;
$type == BTemplate::COMMON_HEAD;
$typeSource = $this->getType($type);
}
//查看当前数据是否还存在
$condition = ['template_id'=>$template_id,'source'=>$typeSource,'common_type'=>$type];
$info = $templateComModel->read($condition);
if($info === false){
$data = array_merge($param,$condition);
$rs = $templateComModel->add($data);
$data['template_id'] = $template_id;
$data['project_id'] = $this->user['project_id'];
$data['type'] = $type;
$templateCommonModel->add($data);
}else{
$rs = $templateComModel->edit($param,$condition);
}
if($rs === false){
$this->fail('保存错误,请联系管理员');
}
$templateCommonModel->edit($data,['id'=>$info['id']]);
}
//更新所有界面的other
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id']]);
return $this->success();
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @remark :获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($CommonType = BTemplate::COMMON_HEAD){
$type = BTemplate::SOURCE_COM;//公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_head == BTemplate::IS_NO_HEADER){
return $this->success($type);
}
public function getType(){
$type = 1;//首页公共头部底部
//查看页面是否设置自定义头部底部
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'],'type'=>$CommonType]);
if ($pageInfo !== false) {if ($pageInfo['page_list'] != 0) {$type = 9;}}
return $this->success($type);
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo !== false) {
if ($pageInfo['page_list'] != 0) {
$type = 9;
}
}
}
return $type;
}
/**
... ... @@ -387,7 +288,7 @@ class CustomTemplateLogic extends BaseLogic
$this->fail('请先设置模版');
}
//获取type类型
$commonInfo = $this->getType();
$commonInfo = $this->getCommonPage($info['template_id']);
$html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];
return $this->success($html);
... ... @@ -494,44 +395,7 @@ class CustomTemplateLogic extends BaseLogic
}else{
$this->model->edit(['html'=>$logInfo['text']],['id'=>$logInfo['source_id']]);
}
return $this->success();
}
/**
* @remark :复制单页面
* @name :copyCustomTemplateInfo
* @author :lyh
* @method :post
* @time :2024/4/28 16:16
*/
public function copyCustomTemplateInfo(){
$info = $this->model->read(['id'=>$this->param['id']]);
$param = $this->setCustomTemplateParams($info);
$save_id = $this->model->insertGetId($param);
$route = RouteMap::setRoute($param['url'], RouteMap::SOURCE_PRODUCT, $save_id, $this->user['project_id']);
$this->model->edit(['route'=>$route],['id'=>$save_id]);
return $this->success(['id'=>$save_id]);
}
/**
* @remark :组装数据
* @name :setCustomTemplateParams
* @author :lyh
* @method :post
* @time :2024/4/28 16:18
*/
public function setCustomTemplateParams($info){
return [
'name'=>$info['name'].'-copy',
'status'=>$info['status'],
'url'=>$info['url'],
'html'=>$info['html'],
'html_style'=>$info['html_style'],
'project_id'=>$info['project_id'],
'section_list_id'=>$info['section_list_id'],
'is_visualization'=>$info['is_visualization'],
'created_at'=>date('Y-m-d H:i:s'),
'updated_at'=>date('Y-m-d H:i:s'),
];
return $this->success();
}
}
... ...
... ... @@ -14,7 +14,6 @@ use App\Models\Project\PageSetting;
use App\Models\RouteMap\RouteMap;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCom;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
... ... @@ -52,83 +51,14 @@ class InitHtmlLogic extends BaseLogic
$data['id'] = $mainInfo['id'];
$data['updated_at'] = $mainInfo['updated_at'];
}
$commonInfo = $this->getTemplateComHtml($this->param['type'],$is_list,$is_custom,$template_id); //获取头部
$html = $commonInfo['head_style'].$main_style.$commonInfo['footer_style'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
$commonInfo = $this->getCommonHtml($this->param['type'],$is_list,$template_id,$is_custom); //获取头部
$html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);//组装数据
$data['html'] = $html;
return $this->success($data);
}
/**
* @remark :非定制获取头部+底部
* @name :getTemplateComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 16:53
*/
public function getTemplateComHtml($source,$is_list,$is_custom,$template_id){
$condition = ['common_type'=>BTemplate::COMMON_HEAD,'source'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom,'template_id'=>$template_id];
$headComInfo = $this->getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id);
$bTemplateComModel = new BTemplateCom();
$condition['common_type'] = BTemplate::COMMON_OTHER;
$condition['source'] = $headComInfo['source'];
$otherInfo = $bTemplateComModel->read($condition);
if($otherInfo === false){
$this->fail('获取失败,请联系管理员');
}
$footerComInfo = $this->getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id);
$data = ['head_html'=>$headComInfo['html'] ?? '', 'head_style'=>$headComInfo['html_style'] ?? '', 'other'=>$otherInfo['html'] ?? '',
'footer_html'=>$footerComInfo['html'] ?? '','footer_style'=>$footerComInfo['html_style'] ?? ''];
return $this->success($data);
}
/**
* @remark :公共头部
* @name :HeadComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 17:20
*/
public function getHeadComHtml($condition,$source,$is_list,$is_custom,$template_id){
$commonHead = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
$bTemplateComModel = new BTemplateCom();
$condition['source'] = $commonHead;
$condition['common_type'] = BTemplate::COMMON_HEAD;
$headComInfo = $bTemplateComModel->read($condition);
if($headComInfo === false){
//取默认公共的
$condition['source'] = BTemplate::SOURCE_COM;
$headComInfo = $bTemplateComModel->read($condition);
if($headComInfo === false){
$this->fail('获取失败,请联系管理员');
}
}
return $this->success($headComInfo);
}
/**
* @remark :公共底部
* @name :footerComHtml
* @author :lyh
* @method :post
* @time :2024/4/29 17:18
*/
public function getFooterComHtml($condition,$source,$is_list,$is_custom,$template_id){
$bTemplateComModel = new BTemplateCom();
$condition['common_type'] = BTemplate::COMMON_FOOTER;
$condition['source'] = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_FOOTER,$template_id);
$footerComInfo = $bTemplateComModel->read($condition);
if($footerComInfo === false){
//取默认首页的
$condition['source'] = BTemplate::SOURCE_COM;
$footerComInfo = $bTemplateComModel->read($condition);
if($footerComInfo === false){
$this->fail('获取失败,请联系管理员');
}
}
return $this->success($footerComInfo);
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
... ... @@ -184,80 +114,93 @@ class InitHtmlLogic extends BaseLogic
];
$bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
}
$this->saveTemplateCom($this->param['html'],$template_id,$this->param['type'],$is_list,$is_custom);
$this->saveCommonHtml($this->param['html'],$this->param['type'],$is_list,$template_id,$is_custom);
$route = RouteMap::getRoute('all',0,$this->user['project_id']);
$this->curlDelRoute(['route'=>$route,'new_route'=>$route]);
return $this->success();
}
/**
* @remark :保存公共部分(头部。底部。连接部分)
* @name :saveTemplateCom
* @remark :保存公共头部底部
* @name :saveCommonHtml
* @author :lyh
* @method :post
* @time :2024/4/29 10:32
* @time :2023/12/13 17:05
*/
public function saveTemplateCom($html,$template_id,$source,$is_list,$is_custom){
$typeArr = [BTemplate::COMMON_HEAD, BTemplate::COMMON_FOOTER, BTemplate::COMMON_OTHER];
public function saveCommonHtml($html,$source,$is_list,$template_id,$is_custom){
$type = $this->getType($source,$is_list,$is_custom);//获取头部类型1-9(首页到自定义页面)
$templateCommonModel = new BTemplateCommon();
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);//查看当前头部是否存在
$handleInfo = $this->handleCommonParam($html);
$templateComModel = new BTemplateCom();
foreach ($typeArr as $type){
if($type == BTemplate::COMMON_HEAD){
$param['html'] = $handleInfo['head_html'];
$param['html_style'] = $handleInfo['head_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);//头部是否为独立头部
}elseif ($type == BTemplate::COMMON_FOOTER){
$param['html'] = $handleInfo['footer_html'];
$param['html_style'] = $handleInfo['footer_style'];
$typeSource = $this->getType($source,$is_list,$is_custom,$type,$template_id);
if($commonInfo === false){
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
'type'=>$type,'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],
];
$templateCommonModel->add($data);
}else{
$param['html'] = $handleInfo['other'];
$param['html_style'] = null;
$typeSource = $this->getType($source,$is_list,$is_custom,BTemplate::COMMON_HEAD,$template_id);
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],'other'=>$handleInfo['other'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
];
$templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
}
//查看当前数据是否还存在
$condition = ['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'is_list'=>$is_list,'is_custom'=>$is_custom,'source'=>$typeSource,'common_type'=>$type];
$info = $templateComModel->read($condition);
if($info === false){
$data = array_merge($param,$condition);
$templateComModel->add($data);
}else{
$templateComModel->edit($param,$condition);
//更新所有界面的other
return $templateCommonModel->edit(['other'=>$handleInfo['other']],['project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
}
/**
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @author :lyh
* @method :post
* @time :2023/10/21 16:55
*/
public function getCommonHtml($source,$is_list,$template_id,$is_custom){
$type = $this->getType($source,$is_list,$is_custom);
$data = [
'template_id' => $template_id,
'project_id' => $this->user['project_id'],
'type'=>$type
];
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read($data);
if($commonInfo === false){
$data['type'] = BTemplate::SOURCE_HOME;
$commonInfo = $commonTemplateModel->read($data);
}
return $this->success();
return $this->success($commonInfo);
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @remark :保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($source,$is_list,$is_custom = BTemplate::IS_NO_CUSTOM,$CommonType = BTemplate::COMMON_HEAD,$template_id = 0){
if($template_id == 0){
return $this->success($source);
}
$type = BTemplate::SOURCE_COM;//公共头部底部
public function getType($source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $this->user['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if($is_custom == BTemplate::IS_CUSTOM || $is_head == BTemplate::IS_NO_HEADER){//拓展模块为首页头部
if($is_custom == BTemplate::IS_CUSTOM){//拓展模块为首页头部
return $this->success($type);
}
//查看页面是否设置自定义头部底部
if($is_head != BTemplate::IS_NO_HEADER) {
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id'],'type'=>$CommonType]);
$pageInfo = $pageSettingModel->read(['project_id' => $this->user['project_id']]);
if ($pageInfo === false) {
return $this->success($type);
}
if($source == BTemplate::SOURCE_HOME){if ($pageInfo['home'] != 0){$type = BTemplate::SOURCE_HOME;}}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::SOURCE_PRODUCT;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::SOURCE_BLOG;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::SOURCE_BLOG;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::SOURCE_NEWS;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::SOURCE_NEWS;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::SOURCE_KEYWORD;}}
if ($source == BTemplate::SOURCE_PRODUCT) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['product_details'] != 0) {$type = BTemplate::TYPE_PRODUCT_DETAIL;}}
else {if ($pageInfo['product_list'] != 0) {$type = BTemplate::TYPE_PRODUCT_LIST;}}}
if ($source == BTemplate::SOURCE_BLOG) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['blog_details'] != 0) {$type = BTemplate::TYPE_BLOG_DETAIL;}}
else {if ($pageInfo['blog_list'] != 0) {$type = BTemplate::TYPE_BLOG_LIST;}}}
if ($source == BTemplate::SOURCE_NEWS) {if ($is_list != BTemplate::IS_LIST) {if ($pageInfo['news_details'] != 0) {$type = BTemplate::TYPE_NEWS_DETAIL;}}
else {if ($pageInfo['news_list'] != 0) {$type = BTemplate::TYPE_NEWS_LIST;}}}
if ($source == BTemplate::SOURCE_KEYWORD) {if ($pageInfo['polymerization'] != 0) {$type = BTemplate::TYPE_CUSTOM_PAGE;}}
}
return $this->success($type);
}
... ... @@ -272,8 +215,8 @@ class InitHtmlLogic extends BaseLogic
//字符串截取
$param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
$param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
$param['head_style'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
$param['footer_style'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/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);
... ... @@ -326,39 +269,21 @@ class InitHtmlLogic extends BaseLogic
if($info === false){
$html = '';
}else{
$commonInfo = $this->getCustomizeTemplateComHtml($this->param['type'],$is_custom,$is_list);
$html = $this->handleAllHtml($commonInfo,$info['main_html']);
}
//更新头部底部
return $this->success(['html'=>$html]);
}
/**
* @remark :定制获取头部底部
* @name :getCustomizedCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/29 13:13
*/
public function getCustomizeTemplateComHtml($type,$is_custom,$is_list,$template_id = 0){
$data = ['head_html'=>'','head_style'=>'','footer_html'=>'','footer_style'=>'','other'=>''];
$param = ['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list];
$commonTemplateModel = new BTemplateCom();
$commonList = $commonTemplateModel->list($param);
if(!empty($commonList)){
foreach ($commonList as $v){
if($v['common_type'] == BTemplate::COMMON_HEAD){
$data['head_html'] = $v['html'];
$data['head_style'] = $v['html_style'];
}elseif ($v['common_type'] == BTemplate::COMMON_FOOTER){
$data['footer_html'] = $v['html'];
$data['footer_style'] = $v['html_style'];
//扩展模块获取头部
if($is_custom == BTemplate::IS_CUSTOM){
$type = $this->param['type'];
}else{
$data['other'] = $v['html'];
$type = $this->getCustomizedType($this->param['type'],$is_list);
}
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id' => 0,'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list]);
if($commonInfo !== false){
$info['main_html'] = $this->handleAllHtml($commonInfo,$info['main_html']);
}
$html = $info['main_html'];
}
return $this->success($data);
//更新头部底部
return $this->success(['html'=>$html]);
}
/**
... ... @@ -404,7 +329,7 @@ class InitHtmlLogic extends BaseLogic
$bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
}
//更新头部底部
$this->saveTemplateCom($this->param['html'],0,$this->param['type'],$is_list,$is_custom);
$this->saveCustomizeCommon($this->param['html'],$this->param['type'],$is_list,$is_custom);
}catch (\Exception $exception){
$this->fail('保存失败,请联系开发人员');
}
... ... @@ -412,6 +337,73 @@ class InitHtmlLogic extends BaseLogic
}
/**
* @remark :定制代码更新头部信息
* @name :saveCustomizeCommon
* @author :lyh
* @method :post
* @time :2024/1/6 10:29
*/
public function saveCustomizeCommon($html,$source,$is_list,$is_custom){
if($is_custom == BTemplate::IS_CUSTOM){
$type = $source;
}else{
$type = $this->getCustomizedType($source,$is_list);
}
$templateCommonModel = new BTemplateCommon();
$commonInfo = $templateCommonModel->read(['template_id'=>0,'type'=>$type,'is_custom'=>$is_custom,'is_list'=>$is_list]);//查看当前头部是否存在
$handleInfo = $this->handleCommonParam($html);
if($commonInfo === false){
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
'type'=>$type,'template_id'=>0, 'project_id'=>$this->user['project_id'],
'is_custom'=>$is_custom,'is_list'=>$is_list
];
$templateCommonModel->add($data);
}else{
$data = [
'head_html'=>$handleInfo['head_html'], 'head_css'=>$handleInfo['head_css'],
'footer_html'=>$handleInfo['footer_html'], 'footer_css'=>$handleInfo['footer_css'],
];
$templateCommonModel->edit($data,['id'=>$commonInfo['id']]);
}
return $this->success();
}
/**
* @remark :定制页面头部类型---根据source获取type类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/11/16 11:20
*/
public function getCustomizedType($source,$is_list){
$type = BTemplate::TYPE_HOME;
if($source == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_PRODUCT_LIST;
}else{
$type = BTemplate::TYPE_PRODUCT_DETAIL;
}
}
if($source == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_BLOG_LIST;
}else{
$type = BTemplate::TYPE_BLOG_DETAIL;
}
}
if($source == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$type = BTemplate::TYPE_NEWS_LIST;
}else{
$type = BTemplate::TYPE_NEWS_DETAIL;
}
}
return $type;
}
/**
* @remark :前端获取设置模块(侧边栏)
* @name :getInitModuleMain
* @author :lyh
... ...