|
|
|
@ -130,7 +130,12 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
$canRealUseCoupons = $couponRecs['available']; |
|
|
|
$canRealUseCouponRecIds = array_values(array_column($canRealUseCoupons, 'id')); |
|
|
|
if (!empty(array_diff($receiveCouponIds, $canRealUseCouponRecIds))) { |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[优惠券不可用]'.$receiveCouponIds.'_'.$canRealUseCouponRecIds); |
|
|
|
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '订单中有不能使用优惠券的商品', 'data' => json_encode([ |
|
|
|
'all_user_coupons_rec' => json_encode($couponRecs), |
|
|
|
'can_real_user_coupons' => json_encode($canRealUseCoupons), |
|
|
|
'receive_coupon_ids' => json_encode($canRealUseCouponRecIds), |
|
|
|
])]); |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON); |
|
|
|
} |
|
|
|
|
|
|
|
// 处理购物车数据,计算订单金额、子订单数据处理等
|
|
|
|
@ -168,20 +173,20 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
if ($cart->activity_type == 1) { |
|
|
|
$goods = Goods::query()->lockForUpdate()->with('store')->find($cart->goods_id); |
|
|
|
if (empty($goods)) { |
|
|
|
throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效1]'.$cart->goods_id); |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_NOT_EXISTS, '['.$cart->goods_id.']'); |
|
|
|
} |
|
|
|
$check = $this->goodsService->check($goods, $cart->num); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id); |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); |
|
|
|
} |
|
|
|
} elseif ($cart->activity_type == 2) { |
|
|
|
$goods = GoodsActivity::query()->lockForUpdate()->with('store')->find($cart->goods_id); |
|
|
|
if (empty($goods)) { |
|
|
|
throw new ErrorCodeException(ErrorCode::ORDER_GOODS_NOT_AVAILABLE, '[商品失效3]'.$cart->goods_id); |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_NOT_EXISTS, '['.$cart->goods_id.']'); |
|
|
|
} |
|
|
|
$check = $this->goodsActivityService->check($goods, $cart->num, $userId); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '[商品失效4]'.$cart->goods_id); |
|
|
|
throw new ErrorCodeException($check, '['.$goods->name.'/'.$goods->goods_unit.']'); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
@ -306,7 +311,8 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
// 判断是否有购买多个特价商品
|
|
|
|
$check = $this->goodsActivityService->checkOrderActivityCount($dataOrderGoods); |
|
|
|
if(!$check){ |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT, '[同一订单同种类型活动商品]'.json_encode($dataOrderGoods)); |
|
|
|
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => '订单中有活动商品超过限购数量', 'data' => json_encode($dataOrderGoods)]); |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_RESTRICT_LIMIT); |
|
|
|
} |
|
|
|
|
|
|
|
// 订单成功,做一些处理
|
|
|
|
@ -333,7 +339,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
return $this->paymentService->do($globalOrderId, $totalAmount, $userId, config('wechat.notify_url.online')); |
|
|
|
} catch (Exception $e) { |
|
|
|
Db::rollBack(); |
|
|
|
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['exception_msg' => $e->getMessage()]); |
|
|
|
$this->log->event(LogLabel::ORDER_ONLINE_LOG, ['msg' => $e->getMessage()]); |
|
|
|
throw new ErrorCodeException(ErrorCode::ORDER_ONLINE_FAIL, $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|