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 "{{%order_detail}}". |
|
9 |
* |
|
10 |
* @property int $id |
|
11 |
* @property int $order_id |
|
12 |
* @property int $goods_id |
|
13 |
* @property int $num 购买商品数量 |
|
14 |
* @property string $unit_price 商品单价 |
|
15 |
* @property string $total_original_price 商品原总价(优惠前) |
|
16 |
* @property string $total_price 商品总价(优惠后) |
|
17 |
* @property string $member_discount_price 会员优惠金额(正数表示优惠,负数表示加价) |
|
18 |
* @property string $erase_price 抹零价格 |
|
19 |
* @property string $goods_info 购买商品信息 |
|
20 |
* @property int $is_delete |
|
21 |
* @property string $created_at |
|
22 |
* @property string $updated_at |
|
23 |
* @property string $deleted_at |
|
24 |
* @property int $is_refund 是否退款 |
|
25 |
* @property int $refund_status 售后状态 0--未售后 1--售后中 2--售后结束 |
|
26 |
* @property string $back_price 后台优惠(正数表示优惠,负数表示加价) |
|
27 |
* @property string $sign 订单详情标识,用于区分插件 |
|
28 |
* @property string $goods_no 商品货号 |
|
29 |
* @property Goods $goods |
|
30 |
* @property ShareOrder $share |
|
31 |
* @property OrderRefund $refund |
|
32 |
* @property GoodsWarehouse $goodsWarehouse |
|
33 |
* @property Order $order |
|
34 |
* @property string $refundStatusText 售后状态文字 |
|
35 |
* @property GoodsCards[] $card |
|
36 |
* @property $userCards |
|
37 |
* @property string $form_data 自定义表单提交的数据 |
|
38 |
* @property int $form_id 自定义表单的id |
|
39 |
* @property string $goods_type 商品类型 |
|
40 |
* @property OrderDetailExpressRelation $expressRelation |
|
41 |
* @property $goodsCard |
|
42 |
* @property $goodsCoupon |
|
43 |
* @property $coupon |
|
44 |
*/ |
|
45 |
class OrderDetail extends ModelActiveRecord |
|
46 |
{ |
|
47 |
/** |
|
48 |
* {@inheritdoc} |
|
49 |
*/ |
|
50 |
public static function tableName() |
|
51 |
{ |
|
52 |
return '{{%order_detail}}'; |
|
53 |
} |
|
54 |
|
|
55 |
/** |
|
56 |
* {@inheritdoc} |
|
57 |
*/ |
|
58 |
public function rules() |
|
59 |
{ |
|
60 |
return [ |
|
61 |
[['order_id', 'goods_id', 'num', 'unit_price', 'total_original_price', 'total_price', 'member_discount_price', 'goods_info', 'created_at', 'updated_at', 'deleted_at'], 'required'], |
|
62 |
[['order_id', 'goods_id', 'num', 'is_delete', 'is_refund', 'refund_status', 'form_id'], 'integer'], |
|
63 |
[['unit_price', 'total_original_price', 'total_price', 'member_discount_price','erase_price', 'back_price'], 'number'], |
|
64 |
[['goods_info', 'form_data'], 'string'], |
|
65 |
[['created_at', 'updated_at', 'deleted_at'], 'safe'], |
|
66 |
[['sign', 'goods_type'], 'string', 'max' => 255], |
|
67 |
[['goods_no'], 'string', 'max' => 60], |
|
68 |
]; |
|
69 |
} |
|
70 |
|
|
71 |
/** |
|
72 |
* {@inheritdoc} |
|
73 |
*/ |
|
74 |
public function attributeLabels() |
|
75 |
{ |
|
76 |
return [ |
|
77 |
'id' => 'ID', |
|
78 |
'order_id' => 'Order ID', |
|
79 |
'goods_id' => 'Goods ID', |
|
80 |
'num' => '购买商品数量', |
|
81 |
'unit_price' => '商品单价', |
|
82 |
'total_original_price' => '商品原总价(优惠前)', |
|
83 |
'total_price' => '商品总价(优惠后)', |
|
84 |
'member_discount_price' => '会员优惠金额(正数表示优惠,负数表示加价)', |
|
85 |
'erase_price' => '抹零价格', |
|
86 |
'goods_info' => '购买商品信息', |
|
87 |
'is_delete' => 'Is Delete', |
|
88 |
'created_at' => 'Created At', |
|
89 |
'updated_at' => 'Updated At', |
|
90 |
'deleted_at' => 'Deleted At', |
|
91 |
'is_refund' => '是否退款', |
|
92 |
'refund_status' => '售后状态 0--未售后 1--售后中 2--售后结束', |
|
93 |
'back_price' => '后台优惠(正数表示优惠,负数表示加价)', |
|
94 |
'sign' => '订单详情标识,用于区分插件', |
|
95 |
'goods_no' => '商品货号', |
|
96 |
'form_data' => '自定义表单提交的数据', |
|
97 |
'form_id' => '自定义表单的id', |
|
98 |
'goods_type' => '商品类型', |
|
99 |
]; |
|
100 |
} |
|
101 |
|
|
102 |
/** |
|
103 |
* @param null $goodsInfo |
|
104 |
* @return string |
|
105 |
* @throws \Exception |
|
106 |
*/ |
|
107 |
public function encodeGoodsInfo($goodsInfo = null) |
|
108 |
{ |
|
109 |
if (!$goodsInfo) { |
|
110 |
$goodsInfo = $this->goods_info; |
|
111 |
} |
|
112 |
if (!$goodsInfo) { |
|
113 |
throw new \Exception('goodsInfo不能为空。'); |
|
114 |
} |
|
115 |
return Yii::$app->serializer->encode($goodsInfo); |
|
116 |
} |
|
117 |
|
|
118 |
/** |
|
119 |
* @param null $goodsInfo |
|
120 |
* @return \ArrayObject|mixed |
|
121 |
* @throws \Exception |
|
122 |
*/ |
|
123 |
public function decodeGoodsInfo($goodsInfo = null) |
|
124 |
{ |
|
125 |
if (!$goodsInfo) { |
|
126 |
$goodsInfo = $this->goods_info; |
|
127 |
} |
|
128 |
if (!$goodsInfo) { |
|
129 |
throw new \Exception('goodsInfo不能为空。'); |
|
130 |
} |
|
131 |
return Yii::$app->serializer->decode($goodsInfo); |
|
132 |
} |
|
133 |
|
|
134 |
public function getGoodsCard() |
|
135 |
{ |
|
136 |
return $this->hasMany(GoodsCardRelation::className(), ['goods_id' => 'goods_id'])->where(['is_delete' => 0]); |
|
137 |
} |
|
138 |
|
|
139 |
public function getCard() |
|
140 |
{ |
|
141 |
return $this->hasMany(GoodsCards::className(), ['id' => 'card_id']) |
|
142 |
->via('goodsCard'); |
|
143 |
} |
|
144 |
|
|
145 |
public function getGoodsCoupon() |
|
146 |
{ |
|
147 |
return $this->hasMany(GoodsCouponRelation::className(), ['goods_id' => 'goods_id'])->where(['is_delete' => 0]); |
|
148 |
} |
|
149 |
|
|
150 |
public function getCoupon() |
|
151 |
{ |
|
152 |
return $this->hasMany(Coupon::className(), ['id' => 'coupon_id']) |
|
153 |
->via('goodsCoupon'); |
|
154 |
} |
|
155 |
|
|
156 |
public function getGoods() |
|
157 |
{ |
|
158 |
return $this->hasOne(Goods::className(), ['id' => 'goods_id']); |
|
159 |
} |
|
160 |
|
|
161 |
public function getOrder() |
|
162 |
{ |
|
163 |
return $this->hasOne(Order::className(), ['id' => 'order_id']); |
|
164 |
} |
|
165 |
|
|
166 |
public function getRefund() |
|
167 |
{ |
|
168 |
return $this->hasOne(OrderRefund::className(), ['order_detail_id' => 'id'])->andWhere(['is_delete' => 0])->orderBy('created_at DESC'); |
|
169 |
} |
|
170 |
|
|
171 |
public function getUserCards() |
|
172 |
{ |
|
173 |
return $this->hasMany(UserCard::className(), ['order_detail_id' => 'id']); |
|
174 |
} |
|
175 |
|
|
176 |
public function getShare() |
|
177 |
{ |
|
178 |
return $this->hasOne(ShareOrder::className(), ['order_detail_id' => 'id']); |
|
179 |
} |
|
180 |
|
|
181 |
public function getGoodsWarehouse() |
|
182 |
{ |
|
183 |
return $this->hasOne(GoodsWarehouse::className(), ['id' => 'goods_warehouse_id']) |
|
184 |
->via('goods'); |
|
185 |
} |
|
186 |
|
|
187 |
public function getExpressRelation() |
|
188 |
{ |
|
189 |
return $this->hasOne(OrderDetailExpressRelation::className(), ['order_detail_id' => 'id'])->andWhere(['is_delete' => 0]); |
|
190 |
} |
|
191 |
|
|
192 |
public function getRefundStatusText() |
|
193 |
{ |
|
194 |
if ($this->refund_status == 0) { |
|
195 |
$refundStatusText = '未售后'; |
|
196 |
} elseif ($this->refund_status == 1) { |
|
197 |
$refundStatusText = '售后申请中'; |
|
198 |
} elseif ($this->refund_status == 2) { |
|
199 |
$refundStatusText = '售后完成'; |
|
200 |
} else { |
|
201 |
$refundStatusText = '位置状态'; |
|
202 |
} |
|
203 |
return $refundStatusText; |
|
204 |
} |
|
205 |
|
|
206 |
public function getOrderRefund() |
|
207 |
{ |
|
208 |
return $this->hasOne(OrderRefund::className(), ['order_detail_id' => 'id']); |
|
209 |
} |
|
210 |
|
|
211 |
public function changePluginData($pluginData) |
|
212 |
{ |
|
213 |
if (version_compare(\Yii::$app->getAppVersion(), '4.2.88') == 1) { |
|
214 |
return $pluginData; |
|
215 |
} else { |
|
216 |
if (isset($pluginData['discount_list'])) { |
|
217 |
return $pluginData['discount_list']; |
|
218 |
} else { |
|
219 |
return []; |
|
220 |
} |
|
221 |
} |
|
222 |
} |
|
223 |
} |