审查视图

application/admin/model/User.php 2.0 KB
王智 authored
1 2 3 4 5 6
<?php

namespace app\admin\model;

use think\Model;
王智 authored
7
王智 authored
8 9 10
class User extends Model
{
王智 authored
11 12 13 14
    

    
王智 authored
15 16
    // 表名
    protected $name = 'user';
王智 authored
17
    
王智 authored
18 19
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
王智 authored
20
王智 authored
21 22 23
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
王智 authored
24 25
    protected $deleteTime = false;
王智 authored
26 27
    // 追加属性
    protected $append = [
王智 authored
28
        'vip_text',
2  
杨育虎 authored
29 30 31
        'exptime_text',
        'is_black_text',
        'type_text'
王智 authored
32
    ];
王智 authored
33
    
王智 authored
34
王智 authored
35 36
    
    public function getVipList()
王智 authored
37
    {
王智 authored
38
        return ['1' => __('Vip 1'), '0' => __('Vip 0')];
王智 authored
39 40
    }
2  
杨育虎 authored
41 42 43 44 45 46 47 48 49 50
    public function getIsBlackList()
    {
        return ['1' => __('Is_black 1'), '0' => __('Is_black 0')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3')];
    }
王智 authored
51
王智 authored
52
    public function getVipTextAttr($value, $data)
王智 authored
53
    {
王智 authored
54 55 56
        $value = $value ? $value : (isset($data['vip']) ? $data['vip'] : '');
        $list = $this->getVipList();
        return isset($list[$value]) ? $list[$value] : '';
王智 authored
57 58 59
    }

王智 authored
60
    public function getExptimeTextAttr($value, $data)
王智 authored
61
    {
王智 authored
62
        $value = $value ? $value : (isset($data['exptime']) ? $data['exptime'] : '');
王智 authored
63 64 65
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }
2  
杨育虎 authored
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81

    public function getIsBlackTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_black']) ? $data['is_black'] : '');
        $list = $this->getIsBlackList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }
王智 authored
82
    protected function setExptimeAttr($value)
王智 authored
83
    {
王智 authored
84
        return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
王智 authored
85 86 87 88
    }


}