Browse Source

自动取消订单

master
weigang 5 years ago
parent
commit
40a65297b2
  1. 5
      app/Constants/v3/LogLabel.php
  2. 15
      app/Service/v3/Implementations/OrderOnlineService.php

5
app/Constants/v3/LogLabel.php

@ -102,4 +102,9 @@ class LogLabel extends AbstractConstants
*/
const PAY_TO_WX_FAIL_LOG = 'pay_to_wx_fail_log';
/**
* @Message("自动取消订单失败")
*/
const ORDER_AUTO_CANCEL_FAIL_LOG = 'order_auto_cancel_fail_log';
}

15
app/Service/v3/Implementations/OrderOnlineService.php

@ -647,6 +647,9 @@ class OrderOnlineService implements OrderOnlineServiceInterface
public function autoCancel()
{
try {
$orderMains = OrderMain::query()
->select(['global_order_id', 'user_id'])
->where(['state' => OrderState::UNPAID])
@ -655,11 +658,8 @@ class OrderOnlineService implements OrderOnlineServiceInterface
foreach ($orderMains as $key => &$orderMain) {
// 订单待支付
$orderMain->state = OrderState::CANCELED;
if (!$orderMain->save()) {
throw new ErrorCodeException(ErrorCode::ORDER_NOT_AVAILABLE);
}
// 订单取消
OrderMain::query()->where(['id' => $orderMain->id])->update(['state' => OrderState::CANCELED]);
// 退还优惠券
$this->couponService->orderRefundCoupons($orderMain->global_order_id);
@ -693,5 +693,10 @@ class OrderOnlineService implements OrderOnlineServiceInterface
$orderChildIds = array_values(array_column($orders, 'store_id'));
$this->badgeService->doByOrder($orderMain->user_id, $orderChildIds, $orderMain->global_order_id, OrderState::CANCELED);
}
} catch (Exception $e) {
$this->log->event(LogLabel::ORDER_AUTO_CANCEL_FAIL_LOG, ['message' => $e->getMessage()]);
}
}
}
Loading…
Cancel
Save