User.php
3.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace app\school\model\basic;
use app\school\model\basic\College;
use app\school\model\ManystoreShop;
use app\school\model\basic\Clazz;
use app\school\model\basic\Specialty;
use think\Model;
class User extends Model
{
// 表名
protected $name = 'user';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'prevtime_text',
'logintime_text',
'jointime_text',
'gender_text',
'school_id_text',
'clazz_text',
'specialty_text',
'college_text',
];
public function getschoolIdTextAttr($value,$data){
return (new ManystoreShop())->where('id',$data['school_id'])->value('name');
}
public function getcollegeTextAttr($value,$data){
return (new College())->where('id',$data['college'])->value('college_name');
}
public function getClazzTextAttr($value,$data){
return (new Clazz())->where('id',$data['clazz'])->value('clazz_name');
}
public function getspecialtyTextAttr($value,$data){
return (new Specialty())->where('id',$data['specialty'])->value('specialty_name');
}
public function getSex()
{
return ['0' => __('男'), '1' => __('女')];
}
public function getStatus(){
return ['normal' => __('正常'), 'lock' => __('锁定')];
}
public function getEducational(){
// return ['0'=>'学前','1'=>'小学','2'=>'初中','3'=>'高中','4'=>'中专','5'=>'大专','6'=>'本科','7'=>'硕士','8'=>'博士'];
return ['1'=>'小学','2'=>'初中','3'=>'高中','4'=>'中专','5'=>'大专','6'=>'本科','7'=>'硕士','8'=>'博士'];
}
public function getYears(){
$years = [];
$item = 8;
for ($i = 0 ; $i <= $item ; $i++){
$year = date('Y')-$i;
$years[$year] = $year;
}
return $years;
}
public function getGenderTextAttr($value,$data){
$value = $value ? $value : $data['gender'];
$list = $this->getSex();
return isset($list[$value]) ? $list[$value] : '';
}
public function getPrevtimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['prevtime']) ? $data['prevtime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getLogintimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['logintime']) ? $data['logintime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getJointimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['jointime']) ? $data['jointime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setPrevtimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setLogintimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setJointimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
}