commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
|
|
3 |
namespace app\models; |
|
4 |
|
|
5 |
/** |
|
6 |
* This is the model class for table "{{%goods_warehouse}}". |
|
7 |
* |
|
8 |
* @property int $id |
|
9 |
* @property int $mall_id |
|
10 |
* @property string $name 商品名称 |
|
11 |
* @property string $subtitle 副标题 |
|
12 |
* @property string $original_price 原价 |
|
13 |
* @property string $cost_price 成本价 |
|
14 |
* @property string $detail 商品详情,图文 |
|
15 |
* @property string $cover_pic 商品缩略图 |
|
16 |
* @property string $pic_url 商品轮播图 |
|
17 |
* @property string $video_url 商品视频 |
|
18 |
* @property string $unit 单位 |
|
19 |
* @property string $created_at |
|
20 |
* @property string $updated_at |
|
21 |
* @property string $deleted_at |
|
22 |
* @property int $is_delete |
|
23 |
* @property string $type 商品类型:goods--实体商品 ecard--电子卡密 |
|
24 |
* @property int $ecard_id 卡密id |
|
25 |
* @property GoodsCatRelation[] $goodsCatRelation |
|
26 |
* @property GoodsCats $cats |
|
27 |
* @property Goods[] $goods |
|
28 |
* @property Goods $goodsInfo |
|
29 |
* @property $mchCats |
|
30 |
* @property Ecard $ecard |
|
31 |
*/ |
|
32 |
class GoodsWarehouse extends ModelActiveRecord |
|
33 |
{ |
|
34 |
const TYPE_VIRTUAL = 'exchange'; //虚拟商品 和兑换中心同名 |
|
35 |
/** |
|
36 |
* {@inheritdoc} |
|
37 |
*/ |
|
38 |
public static function tableName() |
|
39 |
{ |
|
40 |
return '{{%goods_warehouse}}'; |
|
41 |
} |
|
42 |
|
|
43 |
/** |
|
44 |
* {@inheritdoc} |
|
45 |
*/ |
|
46 |
public function rules() |
|
47 |
{ |
|
48 |
return [ |
|
49 |
[['mall_id', 'name', 'detail', 'pic_url', 'created_at', 'updated_at', 'deleted_at'], 'required'], |
|
50 |
[['mall_id', 'is_delete', 'ecard_id'], 'integer'], |
|
51 |
[['original_price', 'cost_price'], 'number'], |
|
52 |
[['detail', 'pic_url'], 'string'], |
|
53 |
[['created_at', 'updated_at', 'deleted_at'], 'safe'], |
|
54 |
[['name', 'subtitle', 'cover_pic', 'video_url', 'unit', 'type'], 'string', 'max' => 255], |
|
55 |
]; |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* {@inheritdoc} |
|
60 |
*/ |
|
61 |
public function attributeLabels() |
|
62 |
{ |
|
63 |
return [ |
|
64 |
'id' => 'ID', |
|
65 |
'mall_id' => 'Mall ID', |
|
66 |
'name' => '商品名称', |
|
67 |
'subtitle' => '副标题', |
|
68 |
'original_price' => '原价', |
|
69 |
'cost_price' => '成本价', |
|
70 |
'detail' => '商品详情,图文', |
|
71 |
'cover_pic' => '商品缩略图', |
|
72 |
'pic_url' => '商品轮播图', |
|
73 |
'video_url' => '商品视频', |
|
74 |
'unit' => '单位', |
|
75 |
'created_at' => 'Created At', |
|
76 |
'updated_at' => 'Updated At', |
|
77 |
'deleted_at' => 'Deleted At', |
|
78 |
'is_delete' => 'Is Delete', |
|
79 |
'type' => '商品类型:goods--实体商品 ecard--电子卡密', |
|
80 |
'ecard_id' => '卡密id', |
|
81 |
]; |
|
82 |
} |
|
83 |
|
|
84 |
public function getGoodsCatRelation() |
|
85 |
{ |
|
86 |
return $this->hasMany(GoodsCatRelation::className(), ['goods_warehouse_id' => 'id'])->where(['is_delete' => 0]); |
|
87 |
} |
|
88 |
|
|
89 |
public function getCats() |
|
90 |
{ |
|
91 |
return $this->hasMany(GoodsCats::className(), ['id' => 'cat_id']) |
|
92 |
->where(['mch_id' => 0]) |
|
93 |
->via('goodsCatRelation'); |
|
94 |
} |
|
95 |
|
|
96 |
public function getMchCats() |
|
97 |
{ |
|
98 |
return $this->hasMany(GoodsCats::className(), ['id' => 'cat_id']) |
|
99 |
->where(['>', 'mch_id', 0]) |
|
100 |
->via('goodsCatRelation'); |
|
101 |
} |
|
102 |
|
|
103 |
public function getGoods() |
|
104 |
{ |
|
105 |
return $this->hasMany(Goods::className(), ['goods_warehouse_id' => 'id']); |
|
106 |
} |
|
107 |
|
|
108 |
public function getGoodsInfo() |
|
109 |
{ |
|
110 |
return $this->hasOne(Goods::className(), ['goods_warehouse_id' => 'id'])->where(['sign' => ['', 'mch']]); |
|
111 |
} |
|
112 |
|
|
113 |
public function getEcard() |
|
114 |
{ |
|
115 |
return $this->hasOne(Ecard::className(), ['id' => 'ecard_id']); |
|
116 |
} |
|
117 |
} |