commit | author | age
|
2207d6
|
1 |
<?php |
W |
2 |
|
|
3 |
namespace app\models; |
|
4 |
|
|
5 |
use app\forms\common\goods\CommonGoodsVipCard; |
|
6 |
use app\plugins\mch\models\Mch; |
|
7 |
use app\plugins\mch\models\MchOrder; |
|
8 |
use app\plugins\vip_card\models\VipCardDiscount; |
|
9 |
use Yii; |
|
10 |
|
|
11 |
/** |
|
12 |
* This is the model class for table "{{%order}}". |
|
13 |
* |
|
14 |
* @property string $id |
|
15 |
* @property int $mall_id |
|
16 |
* @property int $user_id |
|
17 |
* @property int $mch_id 多商户id,0表示商城订单 |
|
18 |
* @property string $order_no 订单号 |
|
19 |
* @property string $total_price 订单总金额(含运费) |
|
20 |
* @property string $total_pay_price 实际支付总费用(含运费) |
|
21 |
* @property string $express_original_price 运费(后台修改前) |
|
22 |
* @property string $express_price 运费(后台修改后) |
|
23 |
* @property string $total_goods_price 订单商品总金额(优惠后) |
|
24 |
* @property string $total_goods_original_price 订单商品总金额(优惠前) |
|
25 |
* @property string $member_discount_price 会员优惠价格(正数表示优惠,负数表示加价) |
|
26 |
* @property string $full_reduce_price 满减活动优惠价格 |
|
27 |
* @property int $use_user_coupon_id 使用的用户优惠券id |
|
28 |
* @property string $coupon_discount_price 优惠券优惠金额 |
|
29 |
* @property int $use_integral_num 使用积分数量 |
|
30 |
* @property string $integral_deduction_price 积分抵扣金额 |
|
31 |
* @property string $name 收件人姓名 |
|
32 |
* @property string $mobile 收件人手机号 |
|
33 |
* @property string $address 收件人地址 |
|
34 |
* @property string $remark 用户订单备注 |
|
35 |
* @property string $order_form 自定义表单(JSON) |
|
36 |
* @property string $distance 同城距离 |
|
37 |
* @property string $city_mobile 同城配送联系方式 |
|
38 |
* @property string $words 已废弃 商家备注 |
|
39 |
* @property string $seller_remark 商家备注 |
|
40 |
* @property int $is_pay 是否支付:0.未支付|1.已支付 |
|
41 |
* @property int $pay_type 支付方式:1.在线支付 2.货到付款 3.余额支付 4.现金 5.pos |
|
42 |
* @property string $pay_time 支付时间 |
|
43 |
* @property int $is_send 是否发货:0.未发货|1.已发货 |
|
44 |
* @property string $send_time 发货时间 |
|
45 |
* @property string $express 物流公司 |
|
46 |
* @property string $express_no 物流订单号 |
|
47 |
* @property int $is_sale 是否过售后时间 |
|
48 |
* @property int $is_confirm 收货状态:0.未收货|1.已收货 |
|
49 |
* @property string $confirm_time 确认收货时间 |
|
50 |
* @property int $cancel_status 订单取消状态:0.未取消|1.已取消|2.申请取消 |
|
51 |
* @property string $cancel_time 订单取消时间 |
|
52 |
* @property string $created_at |
|
53 |
* @property string $updated_at |
|
54 |
* @property string $deleted_at |
|
55 |
* @property int $is_delete |
|
56 |
* @property int $is_recycle 是否加入回收站 0.否|1.是 |
|
57 |
* @property int $send_type 配送方式:0--快递配送 1--到店自提 2--同城配送 |
|
58 |
* @property string $offline_qrcode 核销码 |
|
59 |
* @property int $clerk_id 核销员ID |
|
60 |
* @property int $store_id 自提门店ID |
|
61 |
* @property string $sign 订单标识,用于区分插件 |
|
62 |
* @property string $token |
|
63 |
* @property string $is_comment 是否评价0.否|1.是 |
|
64 |
* @property string $comment_time |
|
65 |
* @property string $support_pay_types 支持的支付方式,空表示支持系统设置支持的所有方式 |
|
66 |
* @property int $sale_status 是否申请售后 |
|
67 |
* @property int $status 订单状态|1.已完成|0.进行中不能对订单进行任何操作 |
|
68 |
* @property string $back_price 后台优惠(正数表示优惠,负数表示加价) |
|
69 |
* @property string $auto_cancel_time 自动取消时间 |
|
70 |
* @property string $auto_confirm_time 自动确认收货时间 |
|
71 |
* @property string $auto_sales_time 自动售后时间 |
|
72 |
* @property string $location 定位 |
|
73 |
* @property string $city_name 配送员 |
|
74 |
* @property string $city_info |
|
75 |
* @property string $cancel_data |
|
76 |
* @property string $platform wxapp:微信小程序 aliapp:支付宝小程序 bdapp:百度小程序 ttapp:字节跳动小程序 wechat:公众号网页 mobile:H5 |
|
77 |
* @property OrderRefund[] $refund |
|
78 |
* @property OrderDetail[] $detail |
|
79 |
* @property ShareOrder $shareOrder |
|
80 |
* @property UserCard[] $userCards |
|
81 |
* @property User $user |
|
82 |
* @property User $clerk |
|
83 |
* @property $comments |
|
84 |
* @property Store $store |
|
85 |
* @property Mch $mch |
|
86 |
* @property string $signName |
|
87 |
* @property string customer_name; |
|
88 |
* @property OrderDetailExpressRelation $detailExpressRelation; |
|
89 |
* @property $expressRelation; |
|
90 |
* @property OrderDetailExpress $detailExpress; |
|
91 |
* @property OrderExpressSingle $expressSingle; |
|
92 |
* @property PaymentOrder $paymentOrder; |
7db506
|
93 |
* @property string $ex_platform |
Z |
94 |
* @property string $ex_card_no |
|
95 |
* @property string $ex_code |
|
96 |
* @property string $ex_erp_no |
2207d6
|
97 |
*/ |
W |
98 |
class Order extends ModelActiveRecord |
|
99 |
{ |
|
100 |
/** @var string 订单创建 */ |
|
101 |
const EVENT_CREATED = 'orderCreated'; |
|
102 |
|
|
103 |
/** @var string 订单取消 */ |
|
104 |
const EVENT_CANCELED = 'orderCanceled'; |
|
105 |
|
|
106 |
/** @var string 订单改价 */ |
|
107 |
const EVENT_CHANGE_PRICE = 'orderChangePrice'; |
|
108 |
|
|
109 |
/** @var string 订单支付 */ |
|
110 |
const EVENT_PAYED = 'orderPayed'; |
|
111 |
|
|
112 |
/** @var string 订单发货 */ |
|
113 |
const EVENT_SENT = 'orderSent'; |
|
114 |
|
|
115 |
/** @var string 订单确认收货 */ |
|
116 |
const EVENT_CONFIRMED = 'orderConfirmed'; |
|
117 |
|
|
118 |
/** @var string 订单过售后 */ |
|
119 |
const EVENT_SALES = 'orderSales'; |
|
120 |
|
|
121 |
/** |
|
122 |
* {@inheritdoc} |
|
123 |
*/ |
|
124 |
public static function tableName() |
|
125 |
{ |
|
126 |
return '{{%order}}'; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* {@inheritdoc} |
|
131 |
*/ |
|
132 |
public function rules() |
|
133 |
{ |
|
134 |
return [ |
|
135 |
[['mall_id', 'user_id', 'total_price', 'total_pay_price', 'express_original_price', 'express_price', |
|
136 |
'total_goods_price', 'total_goods_original_price', 'member_discount_price', 'use_user_coupon_id', |
|
137 |
'coupon_discount_price', 'use_integral_num', 'integral_deduction_price', 'pay_type', 'created_at', |
|
138 |
'updated_at', 'deleted_at'], 'required'], |
|
139 |
[['mall_id', 'user_id', 'mch_id', 'use_user_coupon_id', 'use_integral_num', 'is_pay', 'pay_type', |
|
140 |
'is_send', 'is_sale', 'is_confirm', 'cancel_status', 'is_delete', 'is_recycle', 'send_type', |
|
141 |
'clerk_id', 'store_id', 'is_comment', 'sale_status', 'status', 'distance'], 'integer'], |
|
142 |
[['total_price', 'total_pay_price', 'express_original_price', 'express_price', 'total_goods_price', |
|
143 |
'total_goods_original_price', 'member_discount_price', 'full_reduce_price', 'coupon_discount_price', |
|
144 |
'integral_deduction_price', 'back_price'], 'number'], |
|
145 |
[['order_form', 'support_pay_types', 'cancel_data'], 'string'], |
|
146 |
[['pay_time', 'send_time', 'confirm_time', 'cancel_time', 'created_at', 'updated_at', 'deleted_at', |
|
147 |
'comment_time', 'auto_cancel_time', 'auto_confirm_time', 'auto_sales_time'], 'safe'], |
|
148 |
[['order_no', 'mobile', 'address', 'remark', 'words', 'seller_remark', 'express_no', 'offline_qrcode', |
|
149 |
'sign', 'location', 'city_name', 'city_info'], 'string', 'max' => 255], |
|
150 |
[['name', 'customer_name', 'express'], 'string', 'max' => 65], |
|
151 |
[['token', 'platform'], 'string', 'max' => 32], |
|
152 |
[['city_mobile'], 'string', 'max' => 100], |
7db506
|
153 |
[['ex_platform','ex_card_no','ex_code','ex_erp_no'], 'string', 'max' => 100], |
2207d6
|
154 |
]; |
W |
155 |
} |
|
156 |
|
|
157 |
/** |
|
158 |
* {@inheritdoc} |
|
159 |
*/ |
|
160 |
public function attributeLabels() |
|
161 |
{ |
|
162 |
return [ |
|
163 |
'id' => 'ID', |
|
164 |
'mall_id' => 'Mall ID', |
|
165 |
'user_id' => 'User ID', |
|
166 |
'mch_id' => '多商户id,0表示商城订单', |
|
167 |
'order_no' => '订单号', |
|
168 |
'total_price' => '订单总金额(含运费)', |
|
169 |
'total_pay_price' => '实际支付总费用(含运费)', |
|
170 |
'express_original_price' => '运费(后台修改前)', |
|
171 |
'express_price' => '运费(后台修改后)', |
|
172 |
'total_goods_price' => '订单商品总金额(优惠后)', |
|
173 |
'total_goods_original_price' => '订单商品总金额(优惠前)', |
|
174 |
'member_discount_price' => '会员优惠价格(正数表示优惠,负数表示加价)', |
|
175 |
'full_reduce_price' => '满减活动优惠价格', |
|
176 |
'use_user_coupon_id' => '使用的用户优惠券id', |
|
177 |
'coupon_discount_price' => '优惠券优惠金额', |
|
178 |
'use_integral_num' => '使用积分数量', |
|
179 |
'integral_deduction_price' => '积分抵扣金额', |
|
180 |
'name' => '收件人姓名', |
|
181 |
'mobile' => '收件人手机号', |
|
182 |
'address' => '收件人地址', |
|
183 |
'remark' => '用户订单备注', |
|
184 |
'order_form' => '自定义表单(JSON)', |
|
185 |
'words' => '已废弃 商家备注', |
|
186 |
'seller_remark' => '商家备注', |
|
187 |
'is_pay' => '是否支付:0.未支付|1.已支付', |
|
188 |
'pay_type' => '支付方式:1.在线支付 2.货到付款 3.余额支付 4.现金 5.pos', |
|
189 |
'pay_time' => '支付时间', |
|
190 |
'is_send' => '是否发货:0.未发货|1.已发货', |
|
191 |
'send_time' => '发货时间', |
|
192 |
'express' => '物流公司', |
|
193 |
'express_no' => '物流订单号', |
|
194 |
'is_sale' => '是否过售后时间', |
|
195 |
'is_confirm' => '收货状态:0.未收货|1.已收货', |
|
196 |
'confirm_time' => '确认收货时间', |
|
197 |
'cancel_status' => '订单取消状态:0.未取消|1.已取消|2.申请取消', |
|
198 |
'cancel_time' => '订单取消时间', |
|
199 |
'cancel_data' => '订单取消备注信息', |
|
200 |
'created_at' => 'Created At', |
|
201 |
'updated_at' => 'Updated At', |
|
202 |
'deleted_at' => 'Deleted At', |
|
203 |
'is_delete' => 'Is Delete', |
|
204 |
'is_recycle' => '是否加入回收站 0.否|1.是', |
|
205 |
'send_type' => '配送方式:0--快递配送 1--到店自提 2--同城配送', |
|
206 |
'offline_qrcode' => '核销码', |
|
207 |
'clerk_id' => '核销员ID', |
|
208 |
'store_id' => '自提门店ID', |
|
209 |
'sign' => '订单标识,用于区分插件', |
|
210 |
'token' => 'Token', |
|
211 |
'is_comment' => '是否评价', |
|
212 |
'comment_time' => '评价时间', |
|
213 |
'support_pay_types' => '支持的支付方式,空表示支持系统设置支持的所有方式', |
|
214 |
'sale_status' => '是否申请售后', |
|
215 |
'status' => '订单状态', |
|
216 |
'back_price' => '后台优惠(正数表示优惠,负数表示加价)', |
|
217 |
'auto_cancel_time' => '自动取消时间', |
|
218 |
'auto_confirm_time' => '自动确认收货时间', |
|
219 |
'auto_sales_time' => '自动售后时间', |
|
220 |
'customer_name' => '京东快递商户编码', |
|
221 |
'distance' => '同城距离', |
|
222 |
'city_mobile' => '同城配送联系方式', |
|
223 |
'location' => '定位', |
|
224 |
'city_name' => '配送员', |
|
225 |
'city_info' => '配送信息', |
7db506
|
226 |
'platform' => '平台信息', |
Z |
227 |
'ex_platform' => '发卡平台名称', |
|
228 |
'ex_card_no' => '提货卡号', |
|
229 |
'ex_code' => '提货卡密码', |
|
230 |
'ex_erp_no' => 'ERP单号' |
2207d6
|
231 |
]; |
W |
232 |
} |
|
233 |
|
|
234 |
public function getDetail() |
|
235 |
{ |
|
236 |
return $this->hasMany(OrderDetail::className(), ['order_id' => 'id']); |
|
237 |
} |
|
238 |
|
|
239 |
public function orderStatusText($order = null) |
|
240 |
{ |
|
241 |
if (!$order) { |
|
242 |
$order = $this; |
|
243 |
} |
|
244 |
if (!$order) { |
|
245 |
throw new \Exception('order不能为空'); |
|
246 |
} |
|
247 |
if (is_array($order)) { |
|
248 |
$order = (object) $order; |
|
249 |
} |
|
250 |
|
|
251 |
try { |
|
252 |
$statusText = ''; |
|
253 |
if ($order->is_pay == 0 && $order->pay_type != 2) { |
|
254 |
$statusText = '待付款'; |
|
255 |
} elseif ($order->is_send == 0) { |
|
256 |
$statusText = $order->send_type == 1 ? '待核销' : '待发货'; |
|
257 |
} elseif ($order->is_send == 1 && $order->is_confirm == 0) { |
|
258 |
$statusText = $order->send_type == 1 ? '待核销' : '待收货'; |
|
259 |
} elseif ($order->is_confirm == 1 && $order->is_sale == 0) { |
|
260 |
$statusText = $order->send_type == 1 ? '已核销' : '已收货'; |
|
261 |
} elseif ($order->is_sale == 1) { |
|
262 |
$statusText = '已完成'; |
|
263 |
} else { |
|
264 |
$statusText = '未知状态'; |
|
265 |
} |
|
266 |
|
|
267 |
if ($order->cancel_status == 1) { |
|
268 |
$statusText .= ' 已取消'; |
|
269 |
} |
|
270 |
} catch (\Exception $exception) { |
|
271 |
$statusText = '未知状态'; |
|
272 |
} |
|
273 |
|
|
274 |
return $statusText; |
|
275 |
} |
|
276 |
|
|
277 |
/** |
|
278 |
* uniqid() 根据微秒时间戳生成13位的随机字符串 |
|
279 |
* substr(uniqid(), 7, 13) 截取7至13位的字符 |
|
280 |
* str_split(string) 将字符串分割成数组形式 |
|
281 |
* array_map(ord, array) 将数组的每值 * 自身并返回新的数组 例如:1*1 2*2 3*3 |
|
282 |
* implode(array) 将数组拼接成字符串 |
|
283 |
* substr(string, 0, 8) 截取0至8位字符 |
|
284 |
* strtoupper($prefix) 将自定义的订单前缀转换成大写 |
|
285 |
* date('Ymd') 年月日 |
|
286 |
* @param $prefix |
|
287 |
* @return string |
|
288 |
* @throws \Exception |
|
289 |
*/ |
|
290 |
public static function getOrderNo($prefix) |
|
291 |
{ |
|
292 |
return generate_order_no($prefix); |
|
293 |
} |
|
294 |
|
|
295 |
public function getUser() |
|
296 |
{ |
|
297 |
return $this->hasOne(User::className(), ['id' => 'user_id']); |
|
298 |
} |
|
299 |
|
|
300 |
public function encodeOrderForm($data) |
|
301 |
{ |
|
302 |
return Yii::$app->serializer->encode($data); |
|
303 |
} |
|
304 |
|
|
305 |
public function decodeOrderForm($data) |
|
306 |
{ |
|
307 |
return Yii::$app->serializer->decode($data); |
|
308 |
} |
|
309 |
|
|
310 |
public function encodeSupportPayTypes($data) |
|
311 |
{ |
|
312 |
return Yii::$app->serializer->encode($data); |
|
313 |
} |
|
314 |
|
|
315 |
public function decodeSupportPayTypes($data) |
|
316 |
{ |
|
317 |
return Yii::$app->serializer->decode($data); |
|
318 |
} |
|
319 |
|
|
320 |
public function getPayTypeText($payType = null) |
|
321 |
{ |
|
322 |
if (!$payType) { |
|
323 |
$payType = $this->pay_type; |
|
324 |
} |
|
325 |
$text = ''; |
|
326 |
switch ($payType) { |
|
327 |
case 0: |
|
328 |
$text = '未支付'; |
|
329 |
break; |
|
330 |
case 1: |
|
331 |
$text = '在线支付'; |
|
332 |
break; |
|
333 |
case 2: |
|
334 |
$text = '货到付款'; |
|
335 |
break; |
|
336 |
case 3: |
|
337 |
$text = '余额支付'; |
|
338 |
break; |
|
339 |
case 4: |
|
340 |
$text = '现金'; |
|
341 |
break; |
|
342 |
case 5: |
|
343 |
$text = 'pos机'; |
|
344 |
break; |
|
345 |
default: |
|
346 |
} |
|
347 |
return $text; |
|
348 |
} |
|
349 |
|
|
350 |
public function getSendType() |
|
351 |
{ |
|
352 |
if ($this->send_type == 1) { |
|
353 |
$text = '到店自提'; |
|
354 |
} elseif ($this->send_type == 2) { |
|
355 |
$text = '同城配送'; |
|
356 |
} elseif ($this->send_type == 3) { |
|
357 |
$text = '自动发货'; |
|
358 |
} else { |
|
359 |
$text = '快递发货'; |
|
360 |
} |
|
361 |
return $text; |
|
362 |
} |
|
363 |
|
|
364 |
/** |
|
365 |
* 验证发货快递公司是否正确 |
|
366 |
* @throws \Exception |
|
367 |
*/ |
|
368 |
public function validateExpress($express) |
|
369 |
{ |
|
370 |
$expressList = Express::getExpressList(); |
|
371 |
$sentinel = false; |
|
372 |
foreach ($expressList as $value) { |
|
373 |
if ($value['name'] == $express) { |
|
374 |
$sentinel = true; |
|
375 |
break; |
|
376 |
} |
|
377 |
} |
|
378 |
if (!$sentinel) { |
|
379 |
throw new \Exception('快递公司错误'); |
|
380 |
} |
|
381 |
} |
|
382 |
|
|
383 |
public function getStore() |
|
384 |
{ |
|
385 |
return $this->hasOne(Store::className(), ['id' => 'store_id']); |
|
386 |
} |
|
387 |
|
|
388 |
public function getClerkUser() |
|
389 |
{ |
|
390 |
return $this->hasOne(ClerkUser::className(), ['id' => 'clerk_id']); |
|
391 |
} |
|
392 |
|
|
393 |
public function getClerk() |
|
394 |
{ |
|
395 |
return $this->hasOne(User::className(), ['id' => 'user_id']) |
|
396 |
->via('clerkUser'); |
|
397 |
} |
|
398 |
|
|
399 |
public function getOrderClerk() |
|
400 |
{ |
|
401 |
return $this->hasOne(OrderClerk::className(), ['order_id' => 'id']); |
|
402 |
} |
|
403 |
|
|
404 |
public function getComments() |
|
405 |
{ |
|
406 |
return $this->hasMany(OrderComments::className(), ['order_id' => 'id']); |
|
407 |
} |
|
408 |
|
|
409 |
public function getRefund() |
|
410 |
{ |
|
411 |
return $this->hasMany(OrderRefund::className(), ['order_id' => 'id'])->andWhere(['is_delete' => 0]); |
|
412 |
} |
|
413 |
|
|
414 |
public function getUserCards() |
|
415 |
{ |
|
416 |
return $this->hasMany(UserCard::className(), ['order_id' => 'id']); |
|
417 |
} |
|
418 |
|
|
419 |
public function getShareOrder() |
|
420 |
{ |
|
421 |
return $this->hasMany(ShareOrder::className(), ['order_id' => 'id']); |
|
422 |
} |
|
423 |
|
|
424 |
public function getMchOrder() |
|
425 |
{ |
|
426 |
return $this->hasOne(MchOrder::className(), ['order_id' => 'id']); |
|
427 |
} |
|
428 |
|
|
429 |
public function getUserCoupon() |
|
430 |
{ |
|
431 |
return $this->hasOne(UserCoupon::className(), ['id' => 'use_user_coupon_id']); |
|
432 |
} |
|
433 |
|
|
434 |
public function getMch() |
|
435 |
{ |
|
436 |
return $this->hasOne(Mch::className(), ['id' => 'mch_id']); |
|
437 |
} |
|
438 |
|
|
439 |
/** |
|
440 |
* @return string |
|
441 |
* @throws \app\core\exceptions\ClassNotFoundException |
|
442 |
* 获取订单对应的插件名称 |
|
443 |
*/ |
|
444 |
public function getSignName() |
|
445 |
{ |
|
446 |
if ($this->sign == '' && $this->mch_id == 0) { |
|
447 |
$signName = '商城'; |
|
448 |
} elseif ($this->mch_id > 0) { |
|
449 |
$signName = '多商户'; |
|
450 |
} else { |
|
451 |
try { |
|
452 |
$signName = \Yii::$app->plugin->getPlugin($this->sign)->getDisplayName(); |
|
453 |
} catch (\Exception $exception) { |
|
454 |
$signName = '未知插件'; |
|
455 |
} |
|
456 |
} |
|
457 |
return $signName; |
|
458 |
} |
|
459 |
|
|
460 |
//根据goods_warehouse_id,取商品名 |
|
461 |
public static function getGoods_name($data) |
|
462 |
{ |
|
463 |
$wids = ''; |
|
464 |
foreach ($data as $value) { |
|
465 |
if (empty($wids)) { |
|
466 |
$wids = $value['goods_warehouse_id']; |
|
467 |
} else { |
|
468 |
$wids .= ',' . $value['goods_warehouse_id']; |
|
469 |
} |
|
470 |
} |
|
471 |
if (!empty($wids)) { |
|
472 |
$gw_info = GoodsWarehouse::find()->where("id in ($wids)")->select('id,name')->asArray()->all(); |
|
473 |
foreach ($data as $key => $item) { |
|
474 |
foreach ($gw_info as $v) { |
|
475 |
if ($v['id'] == $item['goods_warehouse_id']) { |
|
476 |
$data[$key]['name'] = $v['name']; |
|
477 |
} |
|
478 |
} |
|
479 |
} |
|
480 |
} |
|
481 |
return $data; |
|
482 |
} |
|
483 |
|
|
484 |
public function getExpressSingle() |
|
485 |
{ |
|
486 |
return $this->hasOne(OrderExpressSingle::className(), ['order_id' => 'id'])->orderBy('created_at DESC'); |
|
487 |
} |
|
488 |
|
|
489 |
public function getDetailExpress() |
|
490 |
{ |
|
491 |
return $this->hasMany(OrderDetailExpress::className(), ['order_id' => 'id'])->andWhere(['is_delete' => 0]); |
|
492 |
} |
|
493 |
|
|
494 |
public function getDetailExpressRelation() |
|
495 |
{ |
|
496 |
return $this->hasMany(OrderDetailExpressRelation::className(), ['order_id' => 'id'])->andWhere(['is_delete' => 0]); |
|
497 |
} |
|
498 |
|
|
499 |
public function getVipCardDiscount() |
|
500 |
{ |
|
501 |
return $this->hasMany(VipCardDiscount::className(), ['order_id' => 'id']); |
|
502 |
} |
|
503 |
|
|
504 |
public function getPaymentOrder() |
|
505 |
{ |
|
506 |
return $this->hasOne(PaymentOrder::className(), ['order_no' => 'order_no'])->andWhere(['is_pay' => 1]); |
|
507 |
} |
|
508 |
|
|
509 |
public function getOrderActionStatus($order) |
|
510 |
{ |
|
511 |
$data['is_express_send'] = 0; |
|
512 |
$data['is_city_send'] = 0; |
|
513 |
$data['is_store_send'] = 0; |
|
514 |
$data['is_clerk_order'] = 0; |
|
515 |
$data['is_finish_order'] = 0; |
|
516 |
$data['is_confirm_order'] = 0; |
|
517 |
$data['is_print'] = 0; |
|
518 |
$data['is_resume'] = 0; |
|
519 |
$data['is_destroy'] = 0; |
|
520 |
$data['is_remark'] = 0; |
|
521 |
$data['edit_express_status'] = 0; |
|
522 |
$data['edit_city'] = 0; |
|
523 |
$data['is_edit_address'] = 0; |
|
524 |
$data['is_coerce_cancel'] = 0; |
|
525 |
$data['is_recycle'] = 0; |
|
526 |
$data['is_print_send_template'] = 0; |
|
527 |
|
|
528 |
if ($order['is_send'] == 0 && $order['cancel_status'] != 1 && $order['is_recycle'] == 0 && $order['status'] != 0) { |
|
529 |
// 快递订单发货 |
|
530 |
if ($order['is_pay'] == 1 || $order['pay_type'] == 2) { |
|
531 |
if ($order['send_type'] == 0 && $order['is_send_show'] == 1) { |
|
532 |
$data['is_express_send'] = 1; |
|
533 |
} |
|
534 |
// 同城配送发货 |
|
535 |
if ($order['send_type'] == 2 && $order['is_send_show'] == 1) { |
|
536 |
$data['is_city_send'] = 1; |
|
537 |
} |
|
538 |
|
|
539 |
// 核销订单 |
|
540 |
if ($order['send_type'] == 1 && $order['clerk'] == null && $order['is_clerk_show']) { |
|
541 |
$data['is_clerk_order'] = 1; |
|
542 |
} |
|
543 |
|
|
544 |
// 到店自提发货 |
|
545 |
if ($order['send_type'] == 1 && $order['is_send_show'] == 1) { |
|
546 |
$data['is_store_send'] = 1; |
|
547 |
} |
|
548 |
} |
|
549 |
} |
|
550 |
|
|
551 |
// 结束订单 |
|
552 |
if ($order['is_recycle'] == 0 && $order['is_confirm'] == 1 && $order['is_sale'] == 0 && $order['status'] != 0) { |
|
553 |
$data['is_finish_order'] = 1; |
|
554 |
} |
|
555 |
|
|
556 |
// 确认收货 |
|
557 |
if ($order['is_recycle'] == 0 && $order['is_send'] == 1 && $order['is_confirm'] == 0 && $order['status'] != 0 && $order['is_confirm_show']) { |
|
558 |
$data['is_confirm_order'] = 1; |
|
559 |
} |
|
560 |
|
|
561 |
// 打印小票 |
|
562 |
if ($order['is_recycle'] == 0) { |
|
563 |
$data['is_print'] = 1; |
|
564 |
} |
|
565 |
// 恢复订单 |
|
566 |
// 删除订单 |
|
567 |
if ($order['is_recycle'] == 1) { |
|
568 |
$data['is_resume'] = 1; |
|
569 |
$data['is_destroy'] = 1; |
|
570 |
} |
|
571 |
// 商家备注 |
|
572 |
if ($order['is_recycle'] == 0) { |
|
573 |
$data['is_remark'] = 1; |
|
574 |
} |
|
575 |
|
|
576 |
// 修改物流 |
|
577 |
if ($order['send_type'] != 2 && $order['cancel_status'] != 1 && $order['is_confirm'] == 0 && $order['is_recycle'] == 0 && $order['status'] != 0) { |
|
578 |
if ($order['detailExpress'] && count($order['detailExpress']) == 1 && $order['is_send'] == 1) { |
|
579 |
$data['edit_express_status'] = 1; |
|
580 |
} |
|
581 |
|
|
582 |
// 多个订单物流不能在订单列表修改,需在详情修改 |
|
583 |
if ($order['detailExpress'] && count($order['detailExpress']) >= 1) { |
|
584 |
$data['edit_express_status'] = 2; |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
588 |
// 修改配送员 |
|
589 |
if ($order['send_type'] == 2 && $order['cancel_status'] != 1 && $order['is_confirm'] == 0 && $order['city_info'] && $order['is_recycle'] == 0 && $order['status'] != 0) { |
|
590 |
$data['edit_city'] = 1; |
|
591 |
} |
|
592 |
// 修改收货地址 |
|
593 |
if (!in_array($order['send_type'], [1, 2]) && $order['cancel_status'] == 0 && $order['is_send'] == 0) { |
|
594 |
$data['is_edit_address'] = 1; |
|
595 |
} |
|
596 |
|
|
597 |
// 强制取消 |
|
598 |
if ($order['is_send'] == 0 && $order['cancel_status'] == 0 && $order['is_cancel_show'] == 1 && $order['status'] == 1) { |
|
599 |
$data['is_coerce_cancel'] = 1; |
|
600 |
} |
|
601 |
// 加入回收站 |
|
602 |
if ($order['is_recycle'] == 0 && $order['status'] == 1) { |
|
603 |
$data['is_recycle'] = 1; |
|
604 |
} |
|
605 |
|
|
606 |
if (($order['is_pay'] == 1 || $order['pay_type'] == 2) && $order['is_confirm'] == 0 && $order['is_recycle'] == 0 && $order['cancel_status'] != 1) { |
|
607 |
$data['is_print_send_template'] = 1; |
|
608 |
} |
|
609 |
|
|
610 |
// TODO 电子面单 |
|
611 |
|
|
612 |
return $data; |
|
613 |
} |
|
614 |
|
|
615 |
// 获取电子面单 |
|
616 |
// 兼容旧数据 |
|
617 |
public function getExpressSingleList($order) |
|
618 |
{ |
|
619 |
// 电子面单列表 |
|
620 |
$newExpressSingle = []; |
|
621 |
if ($order['detailExpress']) { |
|
622 |
foreach ($order['detailExpress'] as $deItem) { |
|
623 |
if ($deItem['expressSingle']) { |
|
624 |
$newItem = []; |
|
625 |
$newItem['express'] = $deItem['express']; |
|
626 |
$newItem['send_type'] = $deItem['send_type']; // 1.快递|2.其它方式 |
|
627 |
$newItem['express_content'] = $deItem['express_content']; |
|
628 |
$newItem['express_no'] = $deItem['express_no']; |
|
629 |
$newGoodsList = []; |
|
630 |
foreach ($deItem['expressRelation'] as $erItem) { |
|
631 |
$newGoodsItem = []; |
|
632 |
$goodsAttr = $erItem['orderDetail']['goods_info']['goods_attr']; |
|
633 |
$newGoodsItem['cover_pic'] = $goodsAttr['pic_url'] ?: $goodsAttr['cover_pic']; |
|
634 |
$newGoodsList[] = $newGoodsItem; |
|
635 |
} |
|
636 |
$newItem['goods_list'] = $newGoodsList; |
|
637 |
$newItem['print_teplate'] = $deItem['expressSingle']['print_teplate']; |
|
638 |
$newExpressSingle[] = $newItem; |
|
639 |
} |
|
640 |
} |
|
641 |
} else { |
|
642 |
if ($order['expressSingle']) { |
|
643 |
$newItem = []; |
|
644 |
$newItem['express'] = $order['express']; |
|
645 |
$newItem['express_no'] = $order['express_no']; |
|
646 |
$newItem['send_type'] = $order['express_no'] ? 1 : 2; |
|
647 |
$newItem['express_content'] = '无需物流发货'; |
|
648 |
$newGoodsList = []; |
|
649 |
foreach ($order['detail'] as $dItem) { |
|
650 |
$newGoodsItem = []; |
|
651 |
$goodsAttr = $dItem['goods_info']['goods_attr']; |
|
652 |
$newGoodsItem['cover_pic'] = $goodsAttr['pic_url'] ?: $goodsAttr['cover_pic']; |
|
653 |
$newGoodsList[] = $newGoodsItem; |
|
654 |
} |
|
655 |
$newItem['goods_list'] = $newGoodsList; |
|
656 |
$newItem['print_teplate'] = $order['expressSingle']['print_teplate']; |
|
657 |
$newExpressSingle[] = $newItem; |
|
658 |
} |
|
659 |
} |
|
660 |
|
|
661 |
return $newExpressSingle; |
|
662 |
} |
|
663 |
|
|
664 |
public function getPluginData($order, $priceList) |
|
665 |
{ |
|
666 |
$pluginData = [ |
|
667 |
'price_list' => $priceList, |
|
668 |
'price_name' => '', |
|
669 |
'discount_list' => [], |
|
670 |
'extra' => [], |
|
671 |
]; |
|
672 |
if ($order['sign']) { |
|
673 |
try { |
|
674 |
$plugin = \Yii::$app->plugin->getPlugin($order['sign']); |
|
675 |
if (method_exists($plugin, 'getOrderInfo')) { |
|
676 |
$pluginDataList = $plugin->getOrderInfo($order['id'], $order); |
|
677 |
if (is_array($pluginDataList)) { |
|
678 |
foreach ($pluginDataList as $pKey => $pItem) { |
|
679 |
$pluginData[$pKey] = $pItem; |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
} catch (\Exception $exception) { |
|
684 |
} |
|
685 |
} |
|
686 |
$erasePrice = 0; |
|
687 |
foreach ($order['detail'] as $item) { |
|
688 |
$erasePrice = price_format($erasePrice + $item['erase_price']); |
|
689 |
} |
|
690 |
if ($erasePrice != 0) { |
|
691 |
$pluginData['discount_list']['erase'] = [ |
|
692 |
'label' => '抹零', |
|
693 |
'value' => $erasePrice > 0 ? - $erasePrice : abs($erasePrice) |
|
694 |
]; |
|
695 |
} |
|
696 |
|
|
697 |
$pluginData['discount_list'] = array_merge( |
|
698 |
$pluginData['discount_list'], |
|
699 |
(CommonGoodsVipCard::getInstance()->getOrderInfo($order['id'], $order))['discount_list'] |
|
700 |
); |
|
701 |
return $pluginData; |
|
702 |
} |
|
703 |
} |