Goods.php
3.3 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
<?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 = [
'is_group_text',
'is_vip_price_text',
'is_recommend_text',
'status_text'
];
protected static function init()
{
self::afterInsert(function ($row) {
$pk = $row->getPk();
$row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
});
}
public function getIsGroupList()
{
return ['1' => __('Is_group 1'), '2' => __('Is_group 2')];
}
public function getIsVipPriceList()
{
return ['1' => __('Is_vip_price 1'), '2' => __('Is_vip_price 2')];
}
public function getIsRecommendList()
{
return ['1' => __('Is_recommend 1'), '2' => __('Is_recommend 2')];
}
public function getStatusList()
{
return ['1' => __('Status 1'), '2' => __('Status 2')];
}
public function getIsGroupTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_group']) ? $data['is_group'] : '');
$list = $this->getIsGroupList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getIsVipPriceTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_vip_price']) ? $data['is_vip_price'] : '');
$list = $this->getIsVipPriceList();
return isset($list[$value]) ? $list[$value] : '';
}
public function getIsRecommendTextAttr($value, $data)
{
$value = $value ? $value : (isset($data['is_recommend']) ? $data['is_recommend'] : '');
$list = $this->getIsRecommendList();
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 brand()
{
return $this->belongsTo('Brand', 'brand_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function category()
{
return $this->belongsTo('Category', 'category_one_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function category2()
{
return $this->belongsTo('Category2', 'category2_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function level()
{
return $this->belongsTo('Level', 'level_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function country()
{
return $this->belongsTo('Country', 'country_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function part()
{
return $this->belongsTo('Part', 'part_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function categorygroup()
{
return $this->belongsTo('CategoryGroup', 'category_group_ids', 'id', [], 'LEFT')->setEagerlyType(0);
}
public function depot()
{
return $this->belongsTo('Depot', 'depot_id', 'id', [], 'LEFT')->setEagerlyType(0);
}
}