Goods.php
4.6 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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
namespace app\admin\model;
use think\Model;
class Goods extends Model
{
// 表名
protected $name = 'goods';
// 自动写入时间戳字段
protected $autoWriteTimestamp = 'int';
// 定义时间戳字段名
protected $createTime = 'createtime';
protected $updateTime = 'updatetime';
protected $deleteTime = false;
// 追加属性
protected $append = [
'type_text',
// 'view_time_text',
'start_time_text',
'end_time_text',
'sex_text',
'status_text',
'user_is_up_text',
'admin_is_up_text',
'user_deletetime_text',
'admin_deletetime_text'
];
public function getTypeList()
{
return ['3' => __('图文'), '2' => __('音频'), '1' => __('视频')];
}
public function getSexList()
{
return ['2' => __('女'), '1' => __('男'), '0' => __('不限')];
}
public function getStatusList()
{
return ['3' => __('审核失败'), '2' => __('审核通过'), '1' => __('审核中')];
}
public function getUserIsUpList()
{
return ['1' => __('上架'), '0' => __('下架')];
}
public function getAdminIsUpList()
{
return ['1' => __('上架'), '0' => __('下架')];
}
public function getTypeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
$list = $this->getTypeList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getViewTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['view_time']) ? $data['view_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getStartTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['start_time']) ? $data['start_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getEndTimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['end_time']) ? $data['end_time'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getSexTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['sex']) ? $data['sex'] : '');
$list = $this->getSexList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getStatusTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['status']) ? $data['status'] : '');
$list = $this->getStatusList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getUserIsUpTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['user_is_up']) ? $data['user_is_up'] : '');
$list = $this->getUserIsUpList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getAdminIsUpTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['admin_is_up']) ? $data['admin_is_up'] : '');
$list = $this->getAdminIsUpList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getUserDeletetimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['user_deletetime']) ? $data['user_deletetime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
public function getAdminDeletetimeTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['admin_deletetime']) ? $data['admin_deletetime'] : '');
return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
}
protected function setViewTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setStartTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setEndTimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setUserDeletetimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
protected function setAdminDeletetimeAttr($value)
{
return $value === '' ? null : ($value && !is_numeric($value) ? strtotime($value) : $value);
}
public function admin()
{
return $this->belongsTo('Admin', 'admin_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}