作者 lyh

gx

... ... @@ -7,10 +7,12 @@
*/
namespace App\Services\Html;
use App\Enums\Common\Code;
use App\Models\Product\Keyword;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\WebSetting\WebSettingSeo;
use App\Services\TdkService;
class CreateHtmlService
{
... ... @@ -22,22 +24,38 @@ class CreateHtmlService
*/
public function getHtml($project_id, $route, $lang = [], $page = 0)
{
//获取项目详情
$projectInfo = $this->getProjectInfo($project_id);
if($projectInfo === false){
return ['code'=>400,'message'=>'当前项目不存在或者已被删除'];
}
//获取页面信息
$pageInfo = $this->getInfoByRoute($route);
if(empty($pageInfo)){
return ['code'=>400,'message'=>'当前路由不存在或者已被删除'];
}
if($projectInfo['is_upgrade'] == 0){
$html = $this->getHtmlV6($project_id, $route);
$projectModel = new Project();
$projectInfo = $projectModel->with(['payment', 'deploy_build'])->where(['id'=>$project_id])->first()->toArray();
$routeMapModel = new RouteMap();
$routeInfo = $routeMapModel->read(['route'=>$route]);
if($routeInfo === false){
if($route == 'top-search' || $route == 'products' || $route == 'news' || $route == 'blog'){
$html = '';
}else{
$html = '';
}
}else{
$html = $this->getHtmlV5();
//TODO::5.0,6.0获取html,自定义页面还需要单独处理
if(($routeInfo['source'] == RouteMap::SOURCE_PAGE) && ($route != 'index')){
$customTemplateService = new CustomTemplateService();
$data = $customTemplateService->getHtml($projectInfo,$routeInfo['source_id']);
if($data === false){
return false;
}
$html = $data['html'];
}else{
$generatePageService = new GeneratePageService();
$data = $generatePageService->generateHtml($projectInfo,$routeInfo);
if($data === false){
return false;
}
$html = $data['html'];
}
}
return $html;
//处理页面tdk
$tdkService = new TdkService();
$html = $tdkService->pageTdkHandle($projectInfo,$html,$routeInfo['source'],$routeInfo);
return ['html'=>$html];
}
/**
... ... @@ -54,16 +72,6 @@ class CreateHtmlService
}
/**
* 返回5.0页面最终HTML
* @return string
*/
public function getHtmlV5()
{
$html = '';
return $html;
}
/**
* 返回6.0页面最终HTML
* @return mixed
*/
... ... @@ -104,10 +112,7 @@ class CreateHtmlService
*/
public function originHtml($project_id,$route)
{
$generatePageService = new GeneratePageService();
$data = $generatePageService->generateHtml($project_id,$route);
$html = $data['html'] ?? '';
return $html;
}
/**
... ...
<?php
/**
* @remark :
* @name :CustomTemplateService.php
* @author :lyh
* @method :post
* @time :2024/3/11 16:15
*/
namespace App\Services\Html;
use App\Models\Project\PageSetting;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\Setting;
class CustomTemplateService
{
/**
* @remark :获取当前自定义界面详情
* @name :customTemplateInfo
* @author :lyh
* @method :post
* @time :2023/6/29 16:23
*/
public function getHtml($projectInfo,$custom_id){
$info = $this->model->read(['id'=>$custom_id]);
if($info === false){
return false;
}
if($info['is_visualization'] == 0 || $info['is_visualization'] == 1){
$html = $this->getBodyHeaderFooter($projectInfo,$info['html'],$info['html_style']);
$info['html'] = $this->getHeadFooter($html);
}
return ['html'=>$info['html']];
}
/**
* @remark :获取body的详情
* @name :getBodyHeaderFooter
* @author :lyh
* @method :post
* @time :2023/7/21 18:08
*/
public function getBodyHeaderFooter($projectInfo,$preg_html,$html_style){
if(empty($preg_html)){
$preg_html = "<main></main>";
$html_style = "<style id='globalsojs-styles'></style>";
}
//获取设置的默认模版
$bSettingModel = new Setting();
$info = $bSettingModel->read(['project_id'=>$projectInfo['id']]);
if($info === false){
return false;
}
//获取type类型
$commonInfo = $this->getCommonPage($projectInfo,$info['template_id']);
$html = $commonInfo['head_css'].$html_style.$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$preg_html.$commonInfo['footer_html'];
return ['html'=>$html];
}
/**
* @remark :根据类型获取公共头和底
* @name :getCommonPage
* @author :lyh
* @method :post
*/
public function getCommonPage($projectInfo,$template_id){
$is_head = $projectInfo['deploy_build']['configuration']['is_head'] ?? BTemplate::IS_NO_HEADER;
if(isset($is_head) && ($is_head != 0)) {
//查看页面是否设置自定义头部底部
$pageSettingModel = new PageSetting();
$pageInfo = $pageSettingModel->read(['project_id' => $projectInfo['id']]);
if ($pageInfo !== false) {
$commonTemplateModel = new BTemplateCommon();
if ($pageInfo['page_list'] != 0) {
//使用独立头和底
$commonInfo = $commonTemplateModel->read(['template_id' => $template_id, 'project_id' => $projectInfo['id'], 'type' => 9]);
}
}
}
if(!isset($commonInfo) || $commonInfo === false){
//获取首页公共的头部和底部
$commonTemplateModel = new BTemplateCommon();
$commonInfo = $commonTemplateModel->read(['template_id'=>$template_id,'project_id'=>$projectInfo['id'],'type'=>1]);
}
return $commonInfo;
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
* @method :post
*/
public function getHeadFooter($html = ''){
//获取公共主题头部底部
$serviceSettingModel = new ServiceSettingModel();
$list = $serviceSettingModel->list(['type'=>2],'created_at');
//拼接html
foreach ($list as $v){
if($v['key'] == 'head'){
$html = $v['values'].$html;
}
if($v['key'] == 'footer'){
$html = $html.$v['values'];
}
}
return $html;
}
}
... ...
... ... @@ -12,6 +12,8 @@ namespace App\Services\Html;
use App\Models\CustomModule\CustomModule;
use App\Models\CustomModule\CustomModuleCategory;
use App\Models\CustomModule\CustomModuleContent;
use App\Models\Project\PageSetting;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
... ... @@ -36,20 +38,14 @@ class GeneratePageService
* @method :post
* @time :2024/2/19 16:57
*/
public function generateHtml($project_id,$route){
$this->project_id = $project_id;
$this->route = $route;
public function generateHtml($projectInfo,$routeInfo){
$this->project_id = $projectInfo['id'];
$this->route = $routeInfo['route'];
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);
return $this->getTemplateHtml();
}
$this->handleParam($routeInfo);
$result = $this->getTemplateHtml($projectInfo);
DB::disconnect('custom_mysql');
return true;
return $this->success($result);
}
/**
... ... @@ -125,14 +121,17 @@ class GeneratePageService
* @author :lyh
* @method :post
*/
public function getTemplateHtml(){
public function getTemplateHtml($projectInfo){
$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
$template_id = $this->getSettingTemplate($projectInfo,$this->param['source'],$is_list,$is_custom);//设置的模版id
if($template_id === false){
return false;
}
$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($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION){//处理定制页面初始数据
$html = $this->customizedReturnHtml($projectInfo,$this->param['source'],$template_id,$is_custom,$is_list);
if($html !== false){
return $this->success($html);
}
... ... @@ -145,10 +144,10 @@ class GeneratePageService
}
$mainInfo = ['main_html'=>$templateInfo['main_html'], 'main_css'=>$templateInfo['main_css']];
}
$commonInfo = $this->getCommonHtml($this->param['source'],$is_list,$template_id,$is_custom);//获取非定制头部
$commonInfo = $this->getCommonHtml($projectInfo,$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];
$result = ['html'=>$html];
return $this->success($result);
}
... ... @@ -181,7 +180,7 @@ class GeneratePageService
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,
'project_id'=>$this->project_id, 'source_id'=>$source_id,
'is_custom'=>$is_custom, 'is_list'=>$is_list
]);
return $this->success($templateInfo);
... ... @@ -194,29 +193,35 @@ class GeneratePageService
* @method :post
* @time :2024/1/10 13:46
*/
public function customizedReturnHtml($source,$template_id,$is_custom,$is_list){
public function customizedReturnHtml($projectInfo,$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('当前扩展模块不存在或已被删除');
return false;
}
//扩展模块定制
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($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
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]);
if($html === false){
return false;
}
return $this->success(['html'=>$html]);
}
return false;
}
//TODO::默认模块定制
$html = $this->isCustomizedPage($source,$is_list,$is_custom);//获取定制页面的html
if(!empty($html)){
return $this->success(['html'=>$html,'template_id'=>$template_id]);
$html = $this->isCustomizedPage($projectInfo,$source,$is_list,$is_custom);//获取定制页面的html
if($html !== false){
return $this->success(['html'=>$html]);
}
return false;
}
... ... @@ -233,7 +238,7 @@ class GeneratePageService
//TODO::获取初始代码
$customHtmlInfo = $bTemplateMainModel->read(['type'=>$source,'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($customHtmlInfo === false){
$this->fail('定制页面,请先上传代码块');
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($source,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
... ... @@ -303,17 +308,17 @@ class GeneratePageService
* @method :post
* @time :2023/12/13 10:55
*/
public function isCustomizedPage($source,$is_list,$is_custom)
public function isCustomizedPage($projectInfo,$source,$is_list,$is_custom)
{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
$page_array = (array)$projectInfo['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('定制页面,请先上传代码块');
return false;
}
$commonInfo = $this->getCustomizedCommonHtml($type,$is_custom,$is_list);//获取定制头部
if($commonInfo !== false){
... ... @@ -334,7 +339,7 @@ class GeneratePageService
public function getCustomizedCommonHtml($type,$is_custom = 0,$is_list = 0){
$data = [
'template_id' => 0,
'project_id' => $this->user['project_id'],
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>$is_custom,
'is_list'=>$is_list
... ... @@ -383,9 +388,9 @@ class GeneratePageService
* @method :post
* @time :2023/12/13 10:48
*/
public function getSettingTemplate($source,$is_list,$is_custom){
public function getSettingTemplate($projectInfo,$source,$is_list,$is_custom){
$template_id = 0;
if($this->user['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
if($projectInfo['is_customized'] == BTemplate::IS_VISUALIZATION) {//定制项目
if($is_custom == BTemplate::IS_CUSTOM){
$customModuleModel = new CustomModule();
$info = $customModuleModel->read(['id'=>$source]);
... ... @@ -401,16 +406,16 @@ class GeneratePageService
}else{
$type = $this->getCustomizedType($source, $is_list);//获取定制界面类型
//查看当前页面是否定制,是否开启可视化
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
$page_array = (array)$projectInfo['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']]);
$info = $bSettingModel->read(['project_id'=>$this->project_id]);
if($info === false){
$this->fail('请先选择模版');
return false;
}
$template_id = $info['template_id'];
return $this->success($template_id);
... ... @@ -423,11 +428,11 @@ class GeneratePageService
* @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);
public function getCommonHtml($ProjectInfo,$source,$is_list,$template_id,$is_custom = 0,){
$type = $this->getType($ProjectInfo,$source,$is_list,$is_custom);
$data = [
'template_id' => $template_id,
'project_id' => $this->user['project_id'],
'project_id' => $this->project_id,
'type'=>$type,
'is_custom'=>0,
];
... ... @@ -440,4 +445,36 @@ class GeneratePageService
return $this->success($commonInfo);
}
/**
* @remark :(非定制)保存时获取获取设置的类型
* @name :getType
* @author :lyh
* @method :post
* @time :2023/10/21 17:29
*/
public function getType($projectInfo,$source,$is_list,$is_custom = 0){
$type = BTemplate::SOURCE_HOME;//首页公共头部底部
$is_head = $projectInfo['deploy_build']['configuration']['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' => $projectInfo['id']]);
if ($pageInfo === false) {
return $this->success($type);
}
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);
}
}
... ...