<?php

namespace app\admin\model;

use think\Model;


class User extends Model
{

    

    

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

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

    // 追加属性
    protected $append = [
        'vip_text',
        'exptime_text'
    ];
    

    
    public function getVipList()
    {
        return ['1' => __('Vip 1'), '0' => __('Vip 0')];
    }


    public function getVipTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['vip']) ? $data['vip'] : '');
        $list = $this->getVipList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getExptimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['exptime']) ? $data['exptime'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    protected function setExptimeAttr($value)
    {
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
    }


}