|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @remark :
|
|
|
|
* @name :GeneratePageService.php
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/2/19 15:54
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Services;
|
|
|
|
|
|
|
|
use App\Models\CustomModule\CustomModule;
|
|
|
|
use App\Models\CustomModule\CustomModuleCategory;
|
|
|
|
use App\Models\CustomModule\CustomModuleContent;
|
|
|
|
use App\Models\Project\Project;
|
|
|
|
use App\Models\RouteMap\RouteMap;
|
|
|
|
use App\Models\Template\BTemplate;
|
|
|
|
use App\Models\Template\BTemplateCommon;
|
|
|
|
use App\Models\Template\BTemplateMain;
|
|
|
|
use App\Models\Template\Setting;
|
|
|
|
use App\Models\Template\Template;
|
|
|
|
use App\Models\Template\TemplateTypeMain;
|
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
|
|
|
class GeneratePageService
|
|
|
|
{
|
|
|
|
protected $route;
|
|
|
|
|
|
|
|
protected $param;
|
|
|
|
|
|
|
|
protected $project_id = 0;
|
|
|
|
public function __construct(){
|
|
|
|
$this->param = request()->all();
|
|
|
|
$this->route = $this->param['route'];
|
|
|
|
$this->project_id = $this->param['project_id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :生成单页数据
|
|
|
|
* @name :generateHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/2/19 16:57
|
|
|
|
*/
|
|
|
|
public function generateHtml(){
|
|
|
|
ProjectServer::useProject($this->project_id);
|
|
|
|
$routeMapModel = new RouteMap();
|
|
|
|
$routeInfo = $routeMapModel->read(['route'=>$this->param['route']]);
|
|
|
|
if($this->param['route'] != RouteMap::SOURCE_INDEX && $routeInfo['source'] == RouteMap::SOURCE_PAGE){
|
|
|
|
//页面管理单独处理
|
|
|
|
}else{
|
|
|
|
$this->handleParam($routeInfo);
|
|
|
|
$this->getTemplateHtml();
|
|
|
|
}
|
|
|
|
DB::disconnect('custom_mysql');
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :生成页面参数处理
|
|
|
|
* @name :generateHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/2/19 16:36
|
|
|
|
*/
|
|
|
|
public function handleParam($routeInfo){
|
|
|
|
switch ($routeInfo['source']){
|
|
|
|
case RouteMap::SOURCE_PRODUCT:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_PRODUCT;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_DETAIL;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_PRODUCT_CATE:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_PRODUCT;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_LIST;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_BLOG:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_BLOG;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_DETAIL;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_BLOG_CATE:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_BLOG;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_LIST;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_NEWS:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_NEWS;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_DETAIL;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_NEWS_CATE:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_NEWS;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_LIST;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_MODULE:
|
|
|
|
$this->param['is_custom'] = BTemplate::IS_CUSTOM;
|
|
|
|
//TODO::获取对应模块数据
|
|
|
|
$moduleModel = new CustomModuleContent();
|
|
|
|
$moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);
|
|
|
|
$this->param['source'] = $moduleInfo['id'] ?? 0;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_DETAIL;
|
|
|
|
break;
|
|
|
|
case RouteMap::SOURCE_MODULE_CATE:
|
|
|
|
$this->param['is_custom'] = BTemplate::IS_CUSTOM;
|
|
|
|
//TODO::获取对应模块数据
|
|
|
|
$moduleModel = new CustomModuleCategory();
|
|
|
|
$moduleInfo = $moduleModel->read(['id'=>$routeInfo['source_id']],['module_id']);
|
|
|
|
$this->param['source'] = $moduleInfo['id'] ?? 0;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_LIST;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$this->param['source'] = BTemplate::SOURCE_HOME;
|
|
|
|
$this->param['is_list'] = BTemplate::IS_DETAIL;
|
|
|
|
break;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @notes: 请简要描述方法功能
|
|
|
|
* @param array $data
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function success($data = [])
|
|
|
|
{
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取html
|
|
|
|
* @name :getTemplateHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
*/
|
|
|
|
public function getTemplateHtml(){
|
|
|
|
$is_custom = $this->param['is_custom'] ?? 0;//是否为扩展模块
|
|
|
|
$is_list = $this->param['is_list'] ?? 0;//是否为列表页
|
|
|
|
$template_id = $this->getSettingTemplate($this->param['source'],$is_list,$is_custom);//设置的模版id
|
|
|
|
$templateInfo = $this->webTemplateInfo($this->param['source'],$this->param['source_id'],$template_id,$is_custom,$is_list);
|
|
|
|
if($templateInfo === false){
|
|
|
|
if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
|
|
|
|
$html = $this->customizedReturnHtml($this->param['source'],$template_id,$is_custom,$is_list);
|
|
|
|
if($html !== false){
|
|
|
|
return $this->success($html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//非定制初始中间部分
|
|
|
|
$mainInfo = $this->getMAinHtml($this->param['source'],$is_custom,$is_list);//获取中间部分代码
|
|
|
|
}else{
|
|
|
|
if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码
|
|
|
|
return $this->getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list);
|
|
|
|
}
|
|
|
|
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
|
|
|
|
}
|
|
|
|
$commonInfo = $this->getCommonHtml($this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部
|
|
|
|
$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];
|
|
|
|
return $this->success($result);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取整个html代码
|
|
|
|
* @name :getCustomizeAllHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/1/10 14:15
|
|
|
|
*/
|
|
|
|
public function getCustomizeAllHtml($templateInfo,$template_id,$is_custom,$is_list){
|
|
|
|
if($is_custom == BTemplate::IS_CUSTOM){
|
|
|
|
$commonInfo = $this->getCustomizedCommonHtml($this->param['source'],$is_custom,$is_list);//获取定制头部
|
|
|
|
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
|
|
|
|
}else{
|
|
|
|
$type = $this->getCustomizedType($this->param['source'],$is_list);
|
|
|
|
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
|
|
|
|
$html = $this->handleAllHtml($commonInfo,$templateInfo['html']);
|
|
|
|
}
|
|
|
|
return $this->success(['html'=>$html,'template_id'=>$template_id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取装修详情
|
|
|
|
* @name :webTemplateInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/1/10 13:43
|
|
|
|
*/
|
|
|
|
public function webTemplateInfo($source,$source_id,$template_id,$is_custom,$is_list){
|
|
|
|
$templateInfo = $this->model->read([
|
|
|
|
'template_id'=>$template_id, 'source'=>$source,
|
|
|
|
'project_id'=>$this->user['project_id'], 'source_id'=>$source_id,
|
|
|
|
'is_custom'=>$is_custom, 'is_list'=>$is_list
|
|
|
|
]);
|
|
|
|
return $this->success($templateInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :定制页面获取html
|
|
|
|
* @name :customizedReturnHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/1/10 13:46
|
|
|
|
*/
|
|
|
|
public function customizedReturnHtml($source,$template_id,$is_custom,$is_list){
|
|
|
|
//TODO::扩展模块定制单独处理
|
|
|
|
if($is_custom == BTemplate::IS_CUSTOM){
|
|
|
|
$customModuleModel = new CustomModule();
|
|
|
|
$info = $customModuleModel->read(['id'=>$source]);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('当前扩展模块不存在或已被删除');
|
|
|
|
}
|
|
|
|
//扩展模块定制
|
|
|
|
if($is_list == BTemplate::IS_LIST && $info['list_customized'] == BTemplate::IS_VISUALIZATION){
|
|
|
|
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
|
|
|
|
return $this->success(['html'=>$html,'template_id'=>$template_id]);
|
|
|
|
}
|
|
|
|
if($is_list == BTemplate::IS_DETAIL && $info['detail_customized'] == BTemplate::IS_VISUALIZATION){
|
|
|
|
$html = $this->customModuleCustomizeHtml($source,$is_list,$is_custom);
|
|
|
|
return $this->success(['html'=>$html,'template_id'=>$template_id]);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
//TODO::默认模块定制
|
|
|
|
$html = $this->isCustomizedPage($source,$is_list,$is_custom);//获取定制页面的html
|
|
|
|
if(!empty($html)){
|
|
|
|
return $this->success(['html'=>$html,'template_id'=>$template_id]);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :扩展模块定制html
|
|
|
|
* @name :customModuleInfo
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2024/1/10 9:20
|
|
|
|
*/
|
|
|
|
public function customModuleCustomizeHtml($source,$is_list,$is_custom){
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
//TODO::获取初始代码
|
|
|
|
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom]);
|
|
|
|
if($customHtmlInfo === false){
|
|
|
|
$this->fail('定制页面,请先上传代码块');
|
|
|
|
}
|
|
|
|
$commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部
|
|
|
|
if($commonInfo !== false){
|
|
|
|
$customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
|
|
|
|
}
|
|
|
|
return $customHtmlInfo['main_html'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :获取中间部分的html
|
|
|
|
* @name :getMAinHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/27 15:00
|
|
|
|
*/
|
|
|
|
public function getMAinHtml($type,$is_custom,$is_list){
|
|
|
|
//获取设置的默认中间部分
|
|
|
|
$bTemplateMainModel = new BTemplateMain();
|
|
|
|
$mainInfo = $bTemplateMainModel->read(['type'=>$type,'is_list'=>$is_list,'is_custom'=>$is_custom]);
|
|
|
|
if($mainInfo === false){
|
|
|
|
$main_html = $this->getInitModule($type,$is_custom,$is_list);
|
|
|
|
$main_css = "<style id='globalsojs-styles'></style>";
|
|
|
|
}else{
|
|
|
|
$main_html = $mainInfo['main_html'];
|
|
|
|
$main_css = $mainInfo['main_css'];
|
|
|
|
}
|
|
|
|
return ['main_html'=>$main_html,'main_css'=>$main_css];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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::IS_CUSTOM) {
|
|
|
|
$type = BTemplate::SOURCE_CUSTOM;
|
|
|
|
}
|
|
|
|
$mainModel = new TemplateTypeMain();
|
|
|
|
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
|
|
|
|
return $info['main_html'];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :返回整个html截取代码
|
|
|
|
* @name :handleAllHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/13 15:39
|
|
|
|
*/
|
|
|
|
public function handleAllHtml($commonInfo,$html){
|
|
|
|
if(!empty($commonInfo)){
|
|
|
|
$html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $commonInfo['head_html'], $html);
|
|
|
|
$html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $commonInfo['footer_html'], $html);
|
|
|
|
$html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $commonInfo['head_css'], $html);
|
|
|
|
$html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $commonInfo['footer_css'], $html);
|
|
|
|
}
|
|
|
|
return $html;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :页面是否为定制页面获取初始代码
|
|
|
|
* @name :watchProjectIsCustomized
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/13 10:55
|
|
|
|
*/
|
|
|
|
public function isCustomizedPage($source,$is_list,$is_custom)
|
|
|
|
{
|
|
|
|
$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'=>$source,'is_custom'=>$is_custom,'is_list'=>$is_list]);
|
|
|
|
if($customHtmlInfo === false){
|
|
|
|
$this->fail('定制页面,请先上传代码块');
|
|
|
|
}
|
|
|
|
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
|
|
|
|
if($commonInfo !== false){
|
|
|
|
$customHtmlInfo['main_html'] = $this->handleAllHtml($commonInfo,$customHtmlInfo['main_html']);
|
|
|
|
}
|
|
|
|
return $customHtmlInfo['main_html'];
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :定制项目获取头部底部
|
|
|
|
* @name :getCustomizedCommonHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/29 13:13
|
|
|
|
*/
|
|
|
|
public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){
|
|
|
|
$data = [
|
|
|
|
'template_id' => 0,
|
|
|
|
'project_id' => $this->user['project_id'],
|
|
|
|
'type'=>$type,
|
|
|
|
'is_custom'=>$is_custom,
|
|
|
|
'is_list'=>$is_list
|
|
|
|
];
|
|
|
|
$commonTemplateModel = new BTemplateCommon();
|
|
|
|
return $commonTemplateModel->read($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 :getSettingTemplate
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/13 10:48
|
|
|
|
*/
|
|
|
|
public function getSettingTemplate($source,$is_list,$is_custom){
|
|
|
|
$template_id = 0;
|
|
|
|
if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
|
|
|
|
if($is_custom == BTemplate::IS_CUSTOM){
|
|
|
|
$customModuleModel = new CustomModule();
|
|
|
|
$info = $customModuleModel->read(['id'=>$source]);
|
|
|
|
if($info === false){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if($info['list_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_LIST){
|
|
|
|
return $this->success($template_id);
|
|
|
|
}
|
|
|
|
if($info['detail_customized'] == BTemplate::IS_VISUALIZATION && $is_list == BTemplate::IS_DETAIL){
|
|
|
|
return $this->success($template_id);
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
|
|
|
|
//查看当前页面是否定制,是否开启可视化
|
|
|
|
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
|
|
|
|
if (in_array($type, $page_array)) {//是定制界面
|
|
|
|
return $this->success($template_id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$bSettingModel = new Setting();
|
|
|
|
$info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
|
|
|
|
if($info === false){
|
|
|
|
$this->fail('请先选择模版');
|
|
|
|
}
|
|
|
|
$template_id = $info['template_id'];
|
|
|
|
return $this->success($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 = 0){
|
|
|
|
$type = $this->getType($source,$is_list,$is_custom);
|
|
|
|
$data = [
|
|
|
|
'template_id' => $template_id,
|
|
|
|
'project_id' => $this->user['project_id'],
|
|
|
|
'type'=>$type,
|
|
|
|
'is_custom'=>0,
|
|
|
|
];
|
|
|
|
$commonTemplateModel = new BTemplateCommon();
|
|
|
|
$commonInfo = $commonTemplateModel->read($data);
|
|
|
|
if($commonInfo === false){
|
|
|
|
$data['type'] = BTemplate::SOURCE_HOME;
|
|
|
|
$commonInfo = $commonTemplateModel->read($data);
|
|
|
|
}
|
|
|
|
return $this->success($commonInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
} |
...
|
...
|
|