CustomTemplateLogic.php 4.0 KB
<?php

namespace App\Http\Logic\Bside\BTemplate;

use App\Http\Logic\Bside\BaseLogic;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\BCustomTemplate;
use App\Models\Template\BSetting;
use App\Models\Template\Template;

class CustomTemplateLogic extends BaseLogic
{
    public function __construct()
    {
        parent::__construct();
        $this->model = new BCustomTemplate();
        $this->param = $this->requestAll;
    }

    /**
     * @remark :获取自定义模块列表
     * @name   :lists
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 15:46
     */
    public function customTemplateLists($map,$page,$row,$order = 'created_at',$filed = ['*']){
        $map['status'] = 0;
        $map['deleted_status'] = 0;
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        return $this->success($lists);
    }

    /**
     * @remark :获取当前自定义界面详情
     * @name   :customTemplateInfo
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 16:23
     */
    public function customTemplateInfo(){
        $info = $this->model->read(['id'=>$this->param['id']]);
        if(!empty($info['html'])){
            $html = $this->getBodyHeaderFooter();
            $info['html'] = $this->getHeadFooter($html);
        }
        if($info === false){
            $this->fail('error');
        }
        return $this->success($info);
    }

    /**
     * @remark :保存自定义界面
     * @name   :customTemplateSave
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 16:21
     */
    public function customTemplateSave(){
        if(isset($this->param['id']) && !empty($this->param['id'])){
            if(isset($this->param['html']) && !empty($this->param['html'])){
                $this->param['html'] = $this->getHeadFooter(characterTruncation($this->param['html'],'/<style id="vvvebjs-header">(.*?)<\/footer>/s'));
            }
            $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        }else{
            $this->param['project_id'] = $this->user['project_id'];
            $rs = $this->model->add($this->param);
        }
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :删除自定义界面
     * @name   :customTemplateDel
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 16:21
     */
    public function customTemplateDel(){
        $rs = $this->model->edit(['deleted_status'=>1,'deleted_at'=>date('Y-m-d H:i:s')],['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }

    /**
     * @remark :获取body的详情
     * @name   :getBodyHeaderFooter
     * @author :lyh
     * @method :post
     * @time   :2023/7/21 18:08
     */
    public function getBodyHeaderFooter(){
        $html = '';
        //获取设置的默认模版
        $bSettingModel = new BSetting();
        $info = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
        //获取模板详情
        $ATemplateModel = new Template();
        $TemplateInfo = $ATemplateModel->read(['id'=>$info['template_id']]);
        $html = $html.$TemplateInfo['head_css'].$TemplateInfo['footer_css'].$TemplateInfo['head_html'].$TemplateInfo['footer_html'];
        return $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;
    }
}