<?php

namespace app\admin\model;

use think\Model;


class Banner extends Model
{

    

    

    // 表名
    protected $name = 'banner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'banner_weizhi_text',
        'banner_state_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getBannerWeizhiList()
    {
        return ['1' => __('Banner_weizhi 1'), '2' => __('Banner_weizhi 2')];
    }

    public function getBannerStateList()
    {
        return ['1' => __('Banner_state 1'), '2' => __('Banner_state 2')];
    }


    public function getBannerWeizhiTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['banner_weizhi']) ? $data['banner_weizhi'] : '');
        $list = $this->getBannerWeizhiList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getBannerStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['banner_state']) ? $data['banner_state'] : '');
        $list = $this->getBannerStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
