|
...
|
...
|
@@ -272,10 +272,19 @@ class BTemplateLogic extends BaseLogic |
|
|
|
$this->showProjectNoEdit($this->param['source']);
|
|
|
|
DB::beginTransaction();
|
|
|
|
try {
|
|
|
|
//字符串截取
|
|
|
|
$this->param = $this->handleSaveParam($this->param);
|
|
|
|
$this->saveTemplateHtml($this->param);
|
|
|
|
$this->setTemplateLog($this->param);
|
|
|
|
$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();
|
|
...
|
...
|
@@ -287,56 +296,93 @@ class BTemplateLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :可视化保存html
|
|
|
|
* @name :saveHtml
|
|
|
|
* @remark :保存数据时设置默认字符
|
|
|
|
* @name :saveDefaultString
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/13 17:02
|
|
|
|
* @time :2023/12/15 10:30
|
|
|
|
*/
|
|
|
|
public function saveHtml($html,$source,$source_id,$section_list_id,$template_id = 0,$is_custom = 0){
|
|
|
|
$type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
|
|
|
|
//查看当前页面是否定制,是否开启可视化
|
|
|
|
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
|
|
|
|
if (in_array($type, $page_array)) {//是定制界面
|
|
|
|
|
|
|
|
|
|
|
|
public function handleDefaultString($param){
|
|
|
|
if(!isset($param['template_id'])){
|
|
|
|
$param['template_id'] = 0;
|
|
|
|
}
|
|
|
|
//保存头部底部
|
|
|
|
$this->saveCommonHtml($html,$source,$source_id,$template_id);
|
|
|
|
$templateInfo = $this->webTemplateInfo($template_id,$source,$source_id,$is_custom);
|
|
|
|
$handleInfo = $this->handleTemplateParam($html);
|
|
|
|
if($templateInfo === false){
|
|
|
|
//TODO::查看当前界面是否为定制界面
|
|
|
|
$data = [
|
|
|
|
'source'=>$source,'source_id'=>$source_id,'section_list_id'=>$section_list_id,
|
|
|
|
'template_id'=>$template_id, 'project_id'=>$this->user['project_id'],
|
|
|
|
'main_html'=>$handleInfo['main_html'],'main_css'=>$handleInfo['main_css']
|
|
|
|
];
|
|
|
|
$this->model->add($data);
|
|
|
|
}else{
|
|
|
|
$data = [
|
|
|
|
'main_html'=>$handleInfo['main_html'],'main_css'=>$handleInfo['main_css'],'section_list_id'=>$section_list_id
|
|
|
|
];
|
|
|
|
$this->model->edit($data,['id'=>$templateInfo['id']]);
|
|
|
|
if(!isset($param['is_custom'])){
|
|
|
|
$param['is_custom'] = 0;
|
|
|
|
}
|
|
|
|
return $this->success();
|
|
|
|
if(!isset($param['section_list_id'])){
|
|
|
|
$param['section_list_id'] = '';
|
|
|
|
}
|
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :定制项目处理数据
|
|
|
|
* @name :saveCustomizedHtml
|
|
|
|
* @remark :可视化添加数据
|
|
|
|
* @name :templateAddHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/15 9:38
|
|
|
|
* @time :2023/12/15 10:15
|
|
|
|
*/
|
|
|
|
public function saveCustomizedHtml($source,$source_id)
|
|
|
|
{
|
|
|
|
|
|
|
|
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){
|
|
|
|
if($this->user['is_customized'] == BTemplate::SOURCE_VISUALIZATION){//定制项目
|
|
|
|
$type = $this->getCustomizedType($source, $source_id);//获取定制界面类型
|
|
|
|
//查看当前页面是否定制,是否开启可视化
|
|
|
|
$page_array = (array)$this->user['is_visualization']->page_array;//获取所有定制界面
|
|
|
|
if (in_array($type, $page_array)) {//当前页面是定制界面
|
|
|
|
$data['html'] = $html;
|
|
|
|
$data['type'] = BTemplate::ALL_HTML;
|
|
|
|
}else{
|
|
|
|
$mainInfo = $this->handleTemplateHtml($html);
|
|
|
|
$data['main_html'] = $mainInfo['main_html'];
|
|
|
|
$data['main_css'] = $mainInfo['main_css'];
|
|
|
|
}
|
|
|
|
}else{
|
|
|
|
$mainInfo = $this->handleTemplateHtml($html);
|
|
|
|
$data['main_html'] = $mainInfo['main_html'];
|
|
|
|
$data['main_css'] = $mainInfo['main_css'];
|
|
|
|
}
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存公共头部底部
|
|
|
|
* @name :saveCommonHtml
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -382,61 +428,6 @@ class BTemplateLogic extends BaseLogic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存可视化数据
|
|
|
|
* @name :saveTemplateHtml
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/12/12 10:23
|
|
|
|
*/
|
|
|
|
public function saveTemplateHtml($param){
|
|
|
|
//TODO::自定义默认默认取首页的头部底部,不需要保存头部底部
|
|
|
|
if($param['is_custom'] == 0){
|
|
|
|
$this->saveCommonTemplate($param);
|
|
|
|
}
|
|
|
|
$info = $this->webTemplateInfo($this->param['template_id'],$param['source'],$param['source_id'],$param['is_custom']);
|
|
|
|
$param['project_id'] = $this->user['project_id'];
|
|
|
|
unset($param['head_html'],$param['head_css'],$param['footer_html'],$param['footer_css']);
|
|
|
|
if($info === false){
|
|
|
|
$this->model->add($param);
|
|
|
|
}else{
|
|
|
|
$this->model->edit($param,['id'=>$info['id']]);
|
|
|
|
}
|
|
|
|
return true;//组装数据
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存头部公共数据
|
|
|
|
* @name :saveCommonTemplate
|
|
|
|
* @author :lyh
|
|
|
|
* @method :post
|
|
|
|
* @time :2023/10/13 14:27
|
|
|
|
*/
|
|
|
|
public function saveCommonTemplate($param){
|
|
|
|
$type = $this->getType($param['source'],$param['source_id']);
|
|
|
|
$templateCommonModel = new BTemplateCommon();
|
|
|
|
$info = $templateCommonModel->read(['template_id'=>$param['template_id'],'project_id'=>$this->user['project_id'],'type'=>$type]);
|
|
|
|
$data = [
|
|
|
|
'head_html'=>$param['head_html'],
|
|
|
|
'head_css'=>$param['head_css'],
|
|
|
|
'footer_html'=>$param['footer_html'],
|
|
|
|
'footer_css'=>$param['footer_css'],
|
|
|
|
];
|
|
|
|
$footer_other = str_replace('<header','',characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<header/s'));
|
|
|
|
$other = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
|
|
|
|
if($info === false){
|
|
|
|
$data['template_id'] = $param['template_id'];
|
|
|
|
$data['project_id'] = $this->user['project_id'];
|
|
|
|
$data['type'] = $type;
|
|
|
|
$templateCommonModel->add($data);
|
|
|
|
}else{
|
|
|
|
$templateCommonModel->edit($data,['id'=>$info['id']]);
|
|
|
|
}
|
|
|
|
//更新所有界面的other
|
|
|
|
$templateCommonModel->edit(['other'=>$other],['project_id'=>$this->user['project_id'],'template_id'=>$param['template_id']]);
|
|
|
|
return $this->success();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @remark :保存时字符串处理
|
|
|
|
* @name :handleCommonParam
|
|
|
|
* @author :lyh
|
|
...
|
...
|
@@ -461,7 +452,7 @@ class BTemplateLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/6/29 15:35
|
|
|
|
*/
|
|
|
|
public function handleTemplateParam($html){
|
|
|
|
public function handleTemplateHtml($html){
|
|
|
|
//字符串截取
|
|
|
|
$param['main_html'] = characterTruncation($html,'/<main\b[^>]*>(.*?)<\/main>/s');
|
|
|
|
$param['main_css'] = characterTruncation($html,'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
...
|
...
|
@@ -500,24 +491,17 @@ class BTemplateLogic extends BaseLogic |
|
|
|
* @method :post
|
|
|
|
* @time :2023/8/23 11:16
|
|
|
|
*/
|
|
|
|
public function setTemplateLog($param){
|
|
|
|
public function setOperationRecords($html,$source,$source_id,$template_id,$is_custom,$type = 0){
|
|
|
|
$data = [
|
|
|
|
'template_id'=>$param['template_id'],
|
|
|
|
'template_id'=>$template_id,
|
|
|
|
'project_id'=>$this->user['project_id'],
|
|
|
|
'operator_id'=>$this->user['id'],
|
|
|
|
'text'=>$param['html'],
|
|
|
|
'source'=>$param['source'],
|
|
|
|
'source_id'=>$param['source_id'],
|
|
|
|
'head_html'=>$param['head_html'],
|
|
|
|
'head_css'=>$param['head_css'],
|
|
|
|
'main_html'=>$param['main_html'],
|
|
|
|
'main_css'=>$param['main_css'],
|
|
|
|
'footer_html'=>$param['footer_html'],
|
|
|
|
'footer_css'=>$param['footer_css'],
|
|
|
|
'is_custom'=>$param['is_custom']
|
|
|
|
'text'=>$html,
|
|
|
|
'type'=>$type,
|
|
|
|
'is_custom'=>$is_custom,
|
|
|
|
'source'=>$source,
|
|
|
|
'source_id'=>$source_id
|
|
|
|
];
|
|
|
|
$footer_other = str_replace('<header','',characterTruncation($param['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);
|
|
|
|
}
|
|
...
|
...
|
@@ -591,8 +575,9 @@ class BTemplateLogic extends BaseLogic |
|
|
|
$param['main_css'] = characterTruncation($param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
|
|
|
|
$param['footer_css'] = characterTruncation($param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
|
|
|
|
if(!isset($param['is_custom'])){
|
|
|
|
$param['is_custom'] = 0;
|
|
|
|
$param['is_custom'] = BTemplate::SOURCE_NO_CUSTOM;
|
|
|
|
}
|
|
|
|
$param['type'] = BTemplate::PAGE_HTML;//不显示整个HTML
|
|
|
|
return $this->success($param);
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|