审查视图

application/admin/model/User.php 1.7 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 29 30
        'is_new_text',
        'level_text',
        'sex_text'
王智 authored
31
    ];
王智 authored
32
    
王智 authored
33
王智 authored
34 35
    
    public function getIsNewList()
王智 authored
36
    {
王智 authored
37
        return ['0' => __('Is_new 0'), '1' => __('Is_new 1')];
王智 authored
38 39
    }
王智 authored
40
    public function getLevelList()
王智 authored
41
    {
王智 authored
42
        return ['1' => __('Level 1'), '2' => __('Level 2'), '3' => __('Level 3'), '4' => __('Level 4'), '5' => __('Level 5'), '6' => __('Level 6'), '7' => __('Level 7'), '8' => __('Level 8')];
王智 authored
43 44
    }
王智 authored
45
    public function getSexList()
王智 authored
46
    {
王智 authored
47
        return ['1' => __('Sex 1'), '2' => __('Sex 2')];
王智 authored
48 49 50
    }

王智 authored
51
    public function getIsNewTextAttr($value, $data)
王智 authored
52
    {
王智 authored
53 54 55
        $value = $value ? $value : (isset($data['is_new']) ? $data['is_new'] : '');
        $list = $this->getIsNewList();
        return isset($list[$value]) ? $list[$value] : '';
王智 authored
56 57 58
    }

王智 authored
59
    public function getLevelTextAttr($value, $data)
王智 authored
60
    {
王智 authored
61 62 63
        $value = $value ? $value : (isset($data['level']) ? $data['level'] : '');
        $list = $this->getLevelList();
        return isset($list[$value]) ? $list[$value] : '';
王智 authored
64 65 66
    }

王智 authored
67
    public function getSexTextAttr($value, $data)
王智 authored
68
    {
王智 authored
69 70 71
        $value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
        $list = $this->getSexList();
        return isset($list[$value]) ? $list[$value] : '';
王智 authored
72 73 74 75 76 77
    }




}