<?php

namespace app\admin\model;

use support\Model;

class HomeBanner extends Model
{

    const IS_DEL_YES = 1;
    const IS_DEL_NO  = 0;

    /**
     * 居家banner
     * The table associated with the model.
     *
     * @var string
     */
    protected $table = 'home_banner';
    public $timestamps = false;


    /**
     * Notes:获取顶部图
     * @param int $banner_category_id
     * @return array
     * User: YCP
     * Date: 2022/11/1
     */
     public static function getBannerInfo(int $banner_category_id)
     {
         return static::where(['banner_category_id' => $banner_category_id,'banner_is_del'=>0])
             ->get()->toArray();
     }

     /**
     * Notes:获取banner列表
     * @return array
     * User: YCP
     * Date: 2022/11/1 
     */
    public static function getBannerList()
    {
        $list = static::select('*')
            ->where(['banner_is_del'=>static::IS_DEL_NO])
            ->get();
        $count = static::where(['banner_is_del'=>static::IS_DEL_NO])
            ->count();
        return [$list, $count];
    }

    //时间格式
    public function getBannerCreateTimeAttribute($value)
    {
        if($value == 0 || $value == ''){
            return 0;
        }else{
            return date('Y-m-d H:i:s', $value);
        }
    }

    //时间格式
    public function getBannerUpdateTimeAttribute($value)
    {
        if($value == 0 || $value == ''){
            return 0;
        }else{
            return date('Y-m-d H:i:s', $value);
        }
    }

}
