ATemplateLogic.php 5.1 KB
<?php

namespace App\Http\Logic\Aside\Template;

use App\Http\Logic\Aside\BaseLogic;
use App\Models\Service\Service as ServiceSettingModel;
use App\Models\Template\Template;
use App\Models\Template\BSetting;
use Illuminate\Support\Facades\DB;
use mysql_xdevapi\Exception;

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

    /**
     * @remark :公共模块模板
     * @name   :aTemplateList
     * @author :lyh
     * @method :post
     * @time   :2023/6/28 17:03
     */
    public function aTemplateList($map,$page,$row,$order = ['created_at'],$filed = ['id','name','status','deleted_status','sort','image']){
        $map['deleted_status'] = 0;
        $map['status'] = 0;
        $lists = $this->model->lists($map,$page,$row,$order,$filed);
        return $this->success($lists);
    }

    /**
     * @remark :添加或编辑模块
     * @name   :aTemplateSave
     * @author :lyh
     * @method :post
     * @time   :2023/6/28 17:13
     */
    public function aTemplateSave(){
        //字符串截取
        $this->StringProcessing();
        if(isset($this->param['id'])){
            $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
        }else{
            $rs = $this->model->add($this->param);
        }
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }
    /**
     * @remark :字符串处理
     * @name   :StringProcessing
     * @author :lyh
     * @method :post
     * @time   :2023/6/29 15:35
     */
    public function StringProcessing(){
        //字符串截取
        $this->param['head_html'] = characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s');
        $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
        $this->param['footer_html'] = characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s');
        $this->param['head_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s');
        $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
        $this->param['footer_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s');
    }
    /**
     * @remark :修改模块状态
     * @name   :aTemplateStatus
     * @author :lyh
     * @method :post
     * @time   :2023/6/28 17:15
     */
    public function aTemplateStatus(){
        $rs = $this->model->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]);
        if($rs === false){
            $this->fail('error');
        }
        return $this->success();
    }


    /**
     * @remark :逻辑删除模板数据
     * @name   :aTemplateDel
     * @author :lyh
     * @method :post
     * @time   :2023/6/28 17:17
     */
    public function aTemplateDel(){
        //查看当前模板是否有模板在使用
        $BSettingModel = new BSetting();
        $info = $BSettingModel->read(['template_id'=>$this->param['id']]);
        if($info !== false){
            $this->fail('当前模板有项目在使用,不允许删除');
        }
        $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 :获取数据详情
     * @name   :aTemplateRead
     * @author :lyh
     * @method :post
     * @time   :2023/7/3 9:22
     */
    public function aTemplateRead(){
        $info = $this->model->read($this->param);
        if($info === false){
            $this->fail('当前数据不存在或已被删除');
        }
        return $this->success($info);
    }

    /**
     * @remark :设置主题公共head
     * @name   :setHeadInfo
     * @author :lyh
     * @method :post
     * @time   :2023/7/10 15:32
     */
    public function setHeadFooterSave(){
        $serviceSettingModel = new ServiceSettingModel();
        DB::beginTransaction();
        try {
            $serviceSettingModel->del(['type'=>2]);
            $data = [
                ['type'=>2,'key'=>'head','values'=>$this->param['head'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')],
                ['type'=>2,'key'=>'footer','values'=>$this->param['footer'],'created_at'=>date('Y-m-d H:i:s'),'updated_at'=>date('Y-m-d H:i:s')]
            ];
            $serviceSettingModel->insert($data);
            DB::commit();
        }catch (Exception $e){
            DB::rollBack();
            $this->fail('error');
        }
    }

    /**
     * @remark :获取主题公共head
     * @name   :getHeadInfo
     * @author :lyh
     * @method :post
     * @time   :2023/7/10 15:33
     */
    public function getHeadFooterList(){
        $serviceSettingModel = new ServiceSettingModel();
        $list = $serviceSettingModel->list(['type'=>2],'created_at');
        return $this->success($list);
    }
}