ATemplate.php 2.3 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 ATemplate extends \App\Models\Base{


    protected $table = 'gl_aside_template';


    protected $hidden = ['deleted_at'];


    use SoftDeletes;

    /**
     * 显示
     */
    const STATUS_ACTIVE = 1;

    /**
     * 隐藏
     */
    const STATUS_DISABLED = 0;


    /**
     * b 端调用
     * @param int $limit
     * @return mixed
     * @author:dc
     * @time 2023/5/9 14:14
     */
    public static function _bAll(int $limit = 20)
    {
        return static::where(function ($query){

            $query->where('status',static::STATUS_ACTIVE);

        })
            ->select(['id','name','url','thumb','created_at','updated_at'])
            ->orderBy('sort')
            ->paginate($limit);
    }

    /**
     * @param $id
     * @return array
     * @author:dc
     * @time 2023/5/9 15:16
     */
    public static function _bFind($id)
    {
        $data = static::where('id',$id)->first();
        if(!$data || $data->status === static::STATUS_DISABLED){
            return [];
        }
        return $data;
    }


    /**
     * 获取默认模板
     * @return mixed
     * @author:dc
     * @time 2023/5/9 15:09
     */
    public static function _default()
    {
        return static::where(['status'=>static::STATUS_ACTIVE,'is_default'=>1])->first();
    }


    /**
     * 查询
     * @param $id
     * @return mixed
     * @author:dc
     * @time 2023/5/10 10:15
     */
    public static function _find($id)
    {
        return static::where('id',$id)->first();
    }


//    /**
//     * @param array $data
//     * @param int $id
//     * @author:dc
//     * @time 2023/5/11 10:08
//     */
//    public static function _save(array $data,int $id=0){
//        if($id){
//            $model  =   static::where('id',$id)->first();
//        }
//        if(empty($model)) $model = new static();
//
//        $model->name = $data['name'];
//        $model->status = $data['status'];
//        $model->is_default = $data['is_default'];
//        $model->sort = $data['sort'];
//        $model->thumb = $data['thumb'];
//        $model->url = $data['url'];
//
//        $model->save();
//
//        return $model->id;
//    }



}