作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6

<?php
/**
* @remark :
* @name :UpdateRoute.php
* @author :lyh
* @method :post
* @time :2023/11/20 15:07
*/
namespace App\Console\Commands;
use App\Models\Blog\Blog;
use App\Models\Blog\BlogCategory;
use App\Models\News\News;
use App\Models\News\NewsCategory;
use App\Models\Product\Category;
use App\Models\Product\Keyword;
use App\Models\Product\Product;
use App\Models\Project\Project;
use App\Models\RouteMap\RouteMap;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* @remark :更新所有项目的路由
* @name :UpdateRoute
* @author :lyh
* @method :post
* @time :2023/11/20 15:08
*/
class UpdateMainHtml extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update_main';
/**
* The console command description.
*
* @var string
*/
protected $description = '洗数据';
/**
* @remark :统一更新路由
* @name :handle
* @author :lyh
* @method :post
* @time :2023/11/20 15:13
*/
public function handle(){
$projectModel = new Project();
$list = $projectModel->list(['is_upgrade'=>0]);
foreach ($list as $v){
echo date('Y-m-d H:i:s') . 'project_id:'.$v['id'] . PHP_EOL;
ProjectServer::useProject($v['id']);
DB::disconnect('custom_mysql');
}
echo date('Y-m-d H:i:s') . 'end' . PHP_EOL;
}
/**
* @remark :洗数据
* @name :getMainHtml
* @author :lyh
* @method :post
* @time :2023/12/27 18:03
*/
public function editMainHtml(){
}
}
... ...
... ... @@ -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);
}
... ... @@ -138,28 +138,4 @@ class BTemplateController extends BaseController
$this->response('模板保存成功');
}
/**
* @remark :获取可视化详情页模板数据
* @name :getDetailInfo
* @author :lyh
* @method :post
* @time :2023/10/24 11:27
*/
public function getDetailInfo(BTemplateLogic $BTemplateLogic){
$html = $BTemplateLogic->getDetail();
$this->response('success',Code::SUCCESS,['html'=>$html]);
}
/**
* @remark :保存详情页模板数据
* @name :saveDetail
* @author :lyh
* @method :post
* @time :2023/10/24 14:47
*/
public function saveDetail(BTemplateLogic $BTemplateLogic){
$BTemplateLogic->saveDetail();
$this->response('success');
}
}
... ...
<?php
/**
* @remark :
* @name :VisualizationController.php
* @name :InitHtmlController.php
* @author :lyh
* @method :post
* @time :2023/11/15 9:55
* @time :2023/12/27 10:37
*/
namespace App\Http\Controllers\Bside\Template;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\BTemplate\BTemplateLogic;
use App\Http\Logic\Bside\BTemplate\InitHtmlLogic;
use App\Http\Logic\Bside\BTemplate\VisualizationLogic;
/**
* @remark :定制项目处理
* @name :VisualizationController
* @remark :初始复合页代码块上传
* @name :InitHtmlController
* @author :lyh
* @method :post
* @time :2023/11/15 9:55
* @time :2023/12/27 10:37
*/
class VisualizationController extends BaseController
class InitHtmlController extends BaseController
{
/**
* @remark :获取可视化详情页模板数据
* @name :getDetailInfo
* @author :lyh
* @method :post $param (type:类型,2产品 3博客 4新闻 对应扩展模块的id)
* @time :2023/10/24 11:27
*/
public function getDetailHtml(InitHtmlLogic $logic){
$this->request->validate([
'type'=>['required'],
],[
'type.required' => '类型不能为空',
]);
$html = $logic->getDetailHtml();
$this->response('success',Code::SUCCESS,['html'=>$html]);
}
/**
* @remark :保存详情页模板数据
* @name :saveDetail
* @author :lyh
* @method :post $param (type:类型,2产品 3博客 4新闻 对应扩展模块的id)
* @time :2023/10/24 14:47
*/
public function saveDetailHtml(InitHtmlLogic $logic){
$this->request->validate([
'type'=>['required'],
],[
'type.required' => '类型不能为空',
]);
$logic->saveDetailHtml();
$this->response('success');
}
/**
* @remark :获取当前定制代码块详情
* @name :info
* @author :lyh
* @method :post
* @time :2023/11/15 10:26
*/
public function info(VisualizationLogic $logic){
$info = $logic->getVisualizationInfo();
public function getCustomizedHtml(InitHtmlLogic $logic){
$this->request->validate([
'type'=>['required'],
],[
'type.required' => '类型不能为空',
]);
$info = $logic->getCustomizedHtml();
if($info === false){
$info = [];
}
... ... @@ -44,8 +85,13 @@ class VisualizationController extends BaseController
* @method :post
* @time :2023/11/15 10:08
*/
public function save(VisualizationLogic $logic){
$logic->saveVisualization();
public function saveCustomizedHtml(InitHtmlLogic $logic){
$this->request->validate([
'type'=>['required'],
],[
'type.required' => '类型不能为空',
]);
$logic->saveCustomizedHtml();
$this->response('success');
}
}
... ...
... ... @@ -57,48 +57,44 @@ 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
$data = $this->getHtml($template_id,$this->param['source'],$this->param['source_id'],$this->param['is_custom'] ?? 0);
return $this->success($data);
}
/**
* @remark :获取可视化装修的html
* @remark :获取可视化html
* @name :getTemplateHtml
* @author :lyh
* @method :post
* @time :2023/12/13 10:47
* @time :2023/12/27 14:48
*/
public function getHtml($template_id,$source,$source_id,$is_custom){
$templateInfo = $this->webTemplateInfo($template_id,$source,$source_id,$is_custom);
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);//设置的模版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($source,$source_id);//查看当前页面是否定制
$html = $this->isCustomizedPage($this->param['source'],$is_list);//获取定制页面的html
return $this->success(['html'=>$html,'template_id'=>$template_id]);
}
$mainInfo = $this->getCommonMain($source,$source_id,$is_custom);//获取中间部分代码
$mainInfo = $this->getMAinHtml($this->param['source'],$is_custom,$is_list);//获取中间部分代码
}else{
if($templateInfo['type'] == BTemplate::ALL_HTML){//返回整个html代码
$type = $this->getCustomizedType($source, $source_id);//定制获取头部底部类型
$commonInfo = $this->getCommonPage($type,$this->user['project_id'],0);//获取定制头部
$type = $this->getCustomizedType($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']];
}
$commonInfo = $this->getCommonPage($source,$source_id,$template_id);//获取头部
$type = $this->getCustomizedType($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){
if($templateInfo !== false)
{
$result['id'] = $templateInfo['id'];
$result['updated_at'] = $templateInfo['updated_at'];
}
... ... @@ -106,6 +102,43 @@ class BTemplateLogic extends BaseLogic
}
/**
* @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::SOURCE_CUSTOM) {
$type = BTemplate::TYPE_CUSTOM;
}
$mainModel = new TemplateTypeMain();
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
return $info['main_html'];
}
/**
* @remark :返回整个html截取代码
* @name :handleAllHtml
* @author :lyh
... ... @@ -129,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']);
}
... ... @@ -151,22 +184,34 @@ class BTemplateLogic extends BaseLogic
}
/**
* @remark :定制界面根据source+source_id获取type类型
* @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;
}
... ... @@ -178,13 +223,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 0;
return $this->success($template_id);
}
}
$bSettingModel = new Setting();
... ... @@ -192,95 +238,172 @@ class BTemplateLogic extends BaseLogic
if($info === false){
$this->fail('请先选择模版');
}
return $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_DETAIL;}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);
}
/**
... ... @@ -293,28 +416,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();
}
... ... @@ -326,66 +461,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)) {//当前页面是定制界面
... ... @@ -412,8 +504,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);
... ... @@ -482,32 +574,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;
}
/**
... ... @@ -518,6 +648,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'],
... ... @@ -547,22 +680,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);
... ... @@ -615,19 +764,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
... ... @@ -823,134 +959,4 @@ class BTemplateLogic extends BaseLogic
}
return $this->success();
}
/**
* @remark :获取详情模板详情
* @name :getDetail
* @author :lyh
* @method :post
* @time :2023/10/24 11:29
*/
public function getDetail(){
$bSettingModel = new Setting();
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($bSettingInfo === false){
$this->fail('请先设置模板');
}
$is_custom = $this->param['is_custom'] ?? 0;//扩展模块详情模版
$commonInfo = $this->getTypeCommonHtml($bSettingInfo['template_id'],$this->param['type'],$is_custom);
//获取设置的默认中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom]);
if($mainInfo === false){
if($is_custom == BTemplate::SOURCE_CUSTOM) {
$this->param['type'] = BTemplate::TYPE_CUSTOM_DETAIL;
}
$main_html = $this->getModule($this->param['type']);
$main_style = "<style id='globalsojs-styles'></style>";
}else{
$main_html = $mainInfo['main_html'];
$main_style = $mainInfo['main_css'];
}
$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 :根据type获取html
* @name :getHeaderFooter
* @author :lyh
* @method :post
* @time :2023/12/15 18:06
*/
public function getTypeCommonHtml($template_id,$type,$is_custom){
//获取首页公共部分
$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)) {
//有权限时,获取独立头部
$commonTypeInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$type]);
if($commonTypeInfo !== false){
$commonInfo = $commonTypeInfo;
}
}
return $this->success($commonInfo);
}
/**
* @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;
}
}
... ...
... ... @@ -29,7 +29,7 @@ class CustomTemplateLogic extends BaseLogic
* @time :2023/6/29 15:46
*/
public function customTemplateLists($map,$page,$row,$order = 'created_at'){
$filed = ['id','name','status','url','title','keywords','description','project_id','created_at','updated_at'];
$filed = ['id','name','status','url','title','keywords','description','project_id','is_upgrade','six_read','created_at','updated_at'];
$map['deleted_status'] = 0;
$map['project_id'] = $this->user['project_id'];
$lists = $this->model->lists($map,$page,$row,$order,$filed);
... ...
<?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\Service\Service as ServiceSettingModel;
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 $param (type:类型,2产品 3博客 4新闻 对应扩展模块的id)
* @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_custom,$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 :getHeadFooter
* @author :lyh
* @method :post
* @time :2023/7/21 17:22
*/
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;
}
/**
* @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,$type,$template_id,$is_custom,$is_list){
$publicData = $this->handleCommonParam($html);
$templateCommonModel = new BTemplateCommon();
//查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
$is_head = $this->user['configuration']['is_head'] ?? 0;
if($is_custom == BTemplate::SOURCE_CUSTOM){//todo::扩展模块无独立头部底部
$is_head = BTemplate::IS_NO_HEADER;
}
if($is_head == BTemplate::IS_HEADER) {
//有独立头部,更新独立头部
$commonType = $this->getHeaderType($type,$is_list);
$templateCommonInfo = $templateCommonModel->read(['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'type'=>$commonType]);
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'=>BTemplate::SOURCE_HOME,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
}
return $this->success();
}
/**
* @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){
//判断当前项目是否有设置独立头部的权限
$is_head = $this->user['configuration']['is_head'] ?? 0;
if($is_custom == BTemplate::SOURCE_CUSTOM){//todo::拓展模块默认取首页
$is_head = BTemplate::IS_NO_HEADER;
}
//获取首页公共部分
$templateCommonModel = new BTemplateCommon();
if($is_head == BTemplate::IS_HEADER) {
//有独立头部,获取独立头部
$commonType = $this->getHeaderType($type,$is_list);
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$commonType]);
if($commonInfo !== false){
return $this->success($commonInfo);
}
}
//首页头底
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>BTemplate::SOURCE_HOME]);
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($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();
}
}
... ...
<?php
/**
* @remark :
* @name :VisualizationLogic.php
* @author :lyh
* @method :post
* @time :2023/11/15 10:09
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Blog\Blog;
use App\Models\News\News;
use App\Models\Product\Product;
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\BTemplateCommon;
use App\Models\Template\BTemplateLog;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
use App\Models\Template\Template;
use App\Models\Template\TemplateTypeMain;
use App\Models\Visualization\Visualization;
class VisualizationLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->model = new BTemplateMain();
$this->param = $this->requestAll;
}
/**
* @remark :获取代码块
* @name :getVisualizationInfo
* @author :lyh
* @method :post
* @time :2023/11/17 14:44
*/
public function getVisualizationInfo(){
$bTemplateMainModel = new BTemplateMain();
$info = $bTemplateMainModel->read(['type'=>$this->param['type']]);
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 saveVisualization(){
try {
$type = $this->param['type'];
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['type'=>$type]);
if($mainInfo === false){
$mainData = [
'project_id'=>$this->user['project_id'],
'type'=>$type,
'main_html'=>$this->param['html']
];
$bTemplateMainModel->add($mainData);
}else{
$bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
}
... ... @@ -36,8 +36,10 @@ class BTemplate extends Base
const TYPE_SEVEN = 7;//新闻列表
const TYPE_EIGHT = 8;//自定义页面
const TYPE_CUSTOM_DETAIL = 11;//扩展详情
const TYPE_CUSTOM_LIST = 12;//扩展列表
const TYPE_CUSTOM = 7;//扩展详情
const IS_LIST = 1;//列表页
const IS_HEADER = 1;//独立头部底部
const IS_NO_HEADER = 0;//非独立头部底部
protected $table = 'gl_web_template';
//连接数据库
... ...
... ... @@ -341,12 +341,12 @@ Route::middleware(['bloginauth'])->group(function () {
});
});
//定制项目上传代码块
Route::prefix('visualization')->group(function () {
Route::any('/info', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'info'])->name('visualization_info');
Route::any('/save', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'save'])->name('visualization_save');
Route::any('/getHtml', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'getHtml'])->name('visualization_getHtml');
Route::any('/saveHtml', [\App\Http\Controllers\Bside\Template\VisualizationController::class, 'saveHtml'])->name('visualization_saveHtml');
//初始代码块
Route::prefix('init_html')->group(function () {
Route::any('/getCustomizedHtml', [\App\Http\Controllers\Bside\Template\InitHtmlController::class, 'getCustomizedHtml'])->name('init_getCustomizedHtml');
Route::any('/saveCustomizedHtml', [\App\Http\Controllers\Bside\Template\InitHtmlController::class, 'saveCustomizedHtml'])->name('init_saveCustomizedHtml');
Route::any('/getDetailHtml', [\App\Http\Controllers\Bside\Template\InitHtmlController::class, 'getDetailHtml'])->name('init_getDetailHtml');
Route::any('/saveDetailHtml', [\App\Http\Controllers\Bside\Template\InitHtmlController::class, 'saveDetailHtml'])->name('init_saveDetailHtml');
});
// 自定义页面,专题页
... ... @@ -434,6 +434,7 @@ Route::middleware(['bloginauth'])->group(function () {
//自定义模板
Route::prefix('custom_module')->group(function () {
Route::any('/', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'lists'])->name('custom_lists');
Route::any('/info', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'info'])->name('custom_info');
Route::any('/save', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'save'])->name('custom_save');
Route::any('/del', [\App\Http\Controllers\Bside\CustomModule\CustomModuleController::class, 'del'])->name('custom_del');
... ...