commit | author | age
|
90c639
|
1 |
<?php |
Z |
2 |
|
|
3 |
namespace app\models; |
|
4 |
|
|
5 |
use Yii; |
|
6 |
|
|
7 |
/** |
|
8 |
* This is the model class for table "{{%cart}}". |
|
9 |
* |
|
10 |
* @property int $id |
|
11 |
* @property int $mall_id |
|
12 |
* @property int $user_id |
|
13 |
* @property int $goods_id 商品 |
|
14 |
* @property string $attr_id 商品规格 |
|
15 |
* @property int $num 商品数量 |
|
16 |
* @property int $mch_id 商户id |
|
17 |
* @property int $is_delete 删除 |
|
18 |
* @property int $sign 删除 |
|
19 |
* @property string $attr_info 规格信息 |
|
20 |
* @property string $created_at |
|
21 |
* @property string $deleted_at |
|
22 |
* @property string $updated_at |
|
23 |
* @property Store $store |
|
24 |
* @property Goods $goods |
|
25 |
* @property GoodsAttr $attrs |
|
26 |
*/ |
|
27 |
class Cart extends ModelActiveRecord |
|
28 |
{ |
|
29 |
/** @var string 购物车添加 */ |
|
30 |
const EVENT_CART_ADD = 'cartAdd'; |
|
31 |
|
|
32 |
/** @var string 购物车删除 */ |
|
33 |
const EVENT_CART_DESTROY = 'cartDestroy'; |
|
34 |
|
|
35 |
const CART_STATUS_CACHE = 'cart_status_cache'; |
|
36 |
|
|
37 |
/** |
|
38 |
* {@inheritdoc} |
|
39 |
*/ |
|
40 |
public static function tableName() |
|
41 |
{ |
|
42 |
return '{{%cart}}'; |
|
43 |
} |
|
44 |
|
|
45 |
/** |
|
46 |
* {@inheritdoc} |
|
47 |
*/ |
|
48 |
public function rules() |
|
49 |
{ |
|
50 |
return [ |
|
51 |
[['mall_id', 'user_id', 'goods_id', 'attr_id', 'created_at', 'deleted_at', 'updated_at'], 'required'], |
|
52 |
[['mall_id', 'user_id', 'goods_id', 'num', 'mch_id', 'is_delete', 'attr_id'], 'integer'], |
|
53 |
[['created_at', 'deleted_at', 'updated_at', 'sign', 'attr_info'], 'safe'], |
|
54 |
]; |
|
55 |
} |
|
56 |
|
|
57 |
/** |
|
58 |
* {@inheritdoc} |
|
59 |
*/ |
|
60 |
public function attributeLabels() |
|
61 |
{ |
|
62 |
return [ |
|
63 |
'id' => 'ID', |
|
64 |
'mall_id' => 'Mall ID', |
|
65 |
'user_id' => 'User ID', |
|
66 |
'goods_id' => '商品', |
|
67 |
'attr_id' => '商品规格', |
|
68 |
'num' => '商品数量', |
|
69 |
'mch_id' => '商户id', |
|
70 |
'is_delete' => '删除', |
|
71 |
'sign' => '标记', |
|
72 |
'attr_info' => '规格信息', |
|
73 |
'created_at' => 'Created At', |
|
74 |
'deleted_at' => 'Deleted At', |
|
75 |
'updated_at' => 'Updated At', |
|
76 |
]; |
|
77 |
} |
|
78 |
|
|
79 |
public static function cacheStatusGet() |
|
80 |
{ |
|
81 |
$cart_status_cache = self::CART_STATUS_CACHE . \Yii::$app->user->id; |
|
82 |
return \Yii::$app->cache->get($cart_status_cache); |
|
83 |
} |
|
84 |
|
|
85 |
public static function cacheStatusSet(bool $info) |
|
86 |
{ |
|
87 |
$cart_status_cache = self::CART_STATUS_CACHE . \Yii::$app->user->id; |
|
88 |
\Yii::$app->cache->set($cart_status_cache, $info, 0); |
|
89 |
} |
|
90 |
|
|
91 |
public function getAttrs() |
|
92 |
{ |
|
93 |
return $this->hasOne(GoodsAttr::className(), ['id' => 'attr_id'])->where(['is_delete' => 0]); |
|
94 |
} |
|
95 |
|
|
96 |
public function getGoods() |
|
97 |
{ |
|
98 |
return $this->hasOne(Goods::className(), ['id' => 'goods_id']); |
|
99 |
} |
|
100 |
|
|
101 |
public function getStore() |
|
102 |
{ |
|
103 |
return $this->hasOne(Store::className(), ['mch_id' => 'mch_id']); |
|
104 |
} |
|
105 |
} |