1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace zacksleo\yii2\shop\models; |
4
|
|
|
|
5
|
|
|
use Yii; |
6
|
|
|
use yii\behaviors\TimestampBehavior; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* This is the model class for table "{{%order}}". |
10
|
|
|
* |
11
|
|
|
* @property integer $id |
12
|
|
|
* @property integer $user_id |
13
|
|
|
* @property integer $payment_method |
14
|
|
|
* @property string $total_amount |
15
|
|
|
* @property integer $status |
16
|
|
|
* @property string $sn |
17
|
|
|
* @property integer $created_at |
18
|
|
|
* @property integer $updated_at |
19
|
|
|
* @property string $address |
20
|
|
|
* @property string $remark |
21
|
|
|
*/ |
22
|
|
|
class Order extends \yii\db\ActiveRecord |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
const PAYMENT_METHOD_ALIPAY = 1; |
26
|
|
|
const PAYMENT_METHOD_WECHATPAY = 2; |
27
|
|
|
|
28
|
|
|
const STATUS_DELETED = -2; //已删除 |
29
|
|
|
const STATUS_CANCELED = -1; //已取消 |
30
|
|
|
const STATUS_UNPAID = 0; //未支付 |
31
|
|
|
const STATUS_PAID = 1; //已支付 |
32
|
|
|
const STATUS_CONSUMED = 2; //已消费 |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @inheritdoc |
36
|
|
|
*/ |
37
|
|
|
public static function tableName() |
38
|
|
|
{ |
39
|
|
|
return '{{%order}}'; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritdoc |
44
|
|
|
*/ |
45
|
|
|
public function rules() |
46
|
|
|
{ |
47
|
|
|
return [ |
48
|
|
|
[['user_id'], 'required'], |
49
|
|
|
[['user_id', 'payment_method', 'status', 'created_at', 'updated_at'], 'integer'], |
50
|
|
|
[['total_amount'], 'number'], |
51
|
|
|
[['sn', 'address', 'remark'], 'string', 'max' => 255], |
52
|
|
|
]; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @inheritdoc |
57
|
|
|
*/ |
58
|
|
|
public function attributeLabels() |
59
|
|
|
{ |
60
|
|
|
return [ |
61
|
|
|
'id' => 'ID', |
62
|
|
|
'user_id' => '用户', |
63
|
|
|
'payment_method' => '支付方式', |
64
|
|
|
'total_amount' => '总金额', |
65
|
|
|
'status' => '状态', |
66
|
|
|
'sn' => '订单编号', |
67
|
|
|
'created_at' => '创建时间', |
68
|
|
|
'updated_at' => '更新时间', |
69
|
|
|
'address' => '配送地址', |
70
|
|
|
'remark' => '备注', |
71
|
|
|
]; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @inheritdoc |
76
|
|
|
*/ |
77
|
|
|
public function behaviors() |
78
|
|
|
{ |
79
|
|
|
return [ |
80
|
|
|
'timestamp' => [ |
81
|
|
|
'class' => TimestampBehavior::className(), |
82
|
|
|
], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function getStatusList() |
87
|
|
|
{ |
88
|
|
|
return [ |
89
|
|
|
self::STATUS_DELETED => '已删除', |
90
|
|
|
self::STATUS_CANCELED => '已取消', |
91
|
|
|
self::STATUS_UNPAID => '未支付', |
92
|
|
|
self::STATUS_PAID => '未解读', |
93
|
|
|
self::STATUS_CONSUMED => '已解读', |
94
|
|
|
]; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
} |
98
|
|
|
|