ATemplateHtml.php 3.1 KB
<?php

namespace App\Models\Template;

use Illuminate\Database\Eloquent\SoftDeletes;

/**
 * 由 A端增删改
 * 模板
 * @author:dc
 * @time 2023/5/9 13:56
 * Class ATemplate
 * @package App\Models\Template
 */
class ATemplateHtml extends \App\Models\Base{


    protected $table = 'gl_aside_template_html';


    protected $hidden = ['deleted_at'];


    use SoftDeletes;


    public static $sourceMap = [
        // 数据表/数据类型     =》   模板类型/模板名称
        'index'   =>  [
            'template'  =>  'index',
            'name'=>'首页'
        ],
        'product'   =>  [
            'template'  =>  'product',
            'name'=>'商品列表'
        ],
        'product_info'   =>  [
            'template'  =>  'product_info',
            'name'=>'商品详情'
        ],
        'blogs'   =>  [
            'template'  =>  'blogs',
            'name'=>'博客列表'
        ],
        'blogs_info'   =>  [
            'template'  =>  'blogs_info',
            'name'=>'博客详情'
        ],
        'page'   =>  [
            'template'  =>  'page',
            'name'=>'单页'
        ],
        'news'   =>  [
            'template'  =>  'news',
            'name'=>'新闻列表'
        ],
        'news_info'   =>  [
            'template'  =>  'news_info',
            'name'=>'新闻详情'
        ],
    ];

    public static $typeMap = [
        'index'   =>  '首页',
        'product'   =>  '商品列表',
        'product_info'   =>  '商品详情',
        'blogs' =>  '博客列表',
        'blogs_info' =>  '博客详情',
        'page' =>  '单页',
        'news' =>  '新闻列表',
        'news_info' =>  '新闻详情',
    ];


    /**
     * 模板中的数据
     * @param $template_id
     * @return mixed
     * @author:dc
     * @time 2023/5/10 10:30
     */
    public static function _all($template_id){
        return static::where(['template_id'=>$template_id])->get();
    }


    /**
     * 是否存在type
     * @param int $template_id
     * @param $type
     * @return mixed
     * @author:dc
     * @time 2023/5/10 16:03
     */
    public static function _typeExist(int $template_id,$type){
        return static::where(['template_id'=>$template_id,'type'=>$type])->limit(1)->count();
    }


    public static function _bAll($template_id){
        return static::where(['template_id'=>$template_id,'status'=>1])->get();
    }


    public static function _find($id){
        return static::where('id',$id)->first();
    }

    /**
     * @param array $data
     * @param int $id
     * @return mixed
     * @author:dc
     * @time 2023/5/11 10:20
     */
    public static function _save(int $template_id, array $data,int $id = 0){
        if($id){
            $model  =   static::where('id',$id)->first();
        }
        if(empty($model)) $model = new static();

        $model->template_id = $template_id;

        $model->name = $data['name'];
        $model->type = $data['type'];
        $model->css = $data['css'];
        $model->script = $data['script'];
        $model->html = $data['html'];


        $model->save();

        return $model->id;
    }





}