|
|
|
@ -100,6 +100,8 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
$userAddr = UserAddress::query()->find($userAddrId); |
|
|
|
// 获取配送费用
|
|
|
|
$deliveryAmount = $this->deliveryService->do($userAddr->lat, $userAddr->lng); |
|
|
|
// 优惠券数据
|
|
|
|
$couponRec = CouponRec::query()->lockForUpdate()->whereIn('id', $receiveCouponIds)->get()->toArray(); |
|
|
|
|
|
|
|
// 处理购物车数据,计算订单金额、子订单数据处理等
|
|
|
|
$totalAmount = 0; # 实付金额
|
|
|
|
@ -127,7 +129,7 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
|
|
|
|
// 用户购物车数据
|
|
|
|
$cartIds = explode(',', $storeItem->cart_ids); |
|
|
|
$carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId])->get(); |
|
|
|
$carts = ShoppingCart::query()->whereIn('id', $cartIds)->where(['market_id' => $marketId, 'user_id' => $userId])->get(); |
|
|
|
foreach ($carts as $k => &$cart) { |
|
|
|
|
|
|
|
// 查个商品
|
|
|
|
@ -136,18 +138,33 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
$goods = Goods::query()->lockForUpdate()->find($cart->goods_id); |
|
|
|
$check = $this->goodsService->check($goods->id, $cart->num); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '[商品失效]'.$cart->goods_id); |
|
|
|
// throw new ErrorCodeException($check, '[商品失效1]'.$cart->goods_id);
|
|
|
|
} |
|
|
|
} elseif ($cart->activity_type == 2) { |
|
|
|
$goods = GoodsActivity::query()->lockForUpdate()->find($cart->goods_id); |
|
|
|
$check = $this->goodsActivityService->check($goods->id, $cart->num, $userId); |
|
|
|
if (true !== $check) { |
|
|
|
throw new ErrorCodeException($check, '[商品失效]'.$cart->goods_id); |
|
|
|
// throw new ErrorCodeException($check, '[商品失效2]'.$cart->goods_id);
|
|
|
|
} |
|
|
|
|
|
|
|
// 活动商品不可用优惠券
|
|
|
|
if ($goods->can_use_coupon!=1 && $receiveCouponIds) { |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.$cart->goods_id); |
|
|
|
} |
|
|
|
|
|
|
|
// 活动商品可用优惠券,再校验这些优惠券是不是可以在当前活动类型可用
|
|
|
|
// receiveCouponIds中是不是有当前活动不可用的优惠券
|
|
|
|
$couponIds = array_values(array_column($couponRec, 'coupon_id')); |
|
|
|
$couponsActivityAvailable = Coupon::query() |
|
|
|
->select(['id']) |
|
|
|
->whereJsonContains('activity_available', [(string)$goods->type]) |
|
|
|
->whereIn('id', $couponIds) |
|
|
|
->get()->toArray(); |
|
|
|
$couponsActivityAvailableIds = array_values(array_column($couponsActivityAvailable, 'id')); |
|
|
|
if (!empty(array_diff($couponIds, $couponsActivityAvailableIds))) { |
|
|
|
throw new ErrorCodeException(ErrorCode::GOODS_ACTIVITY_CANNOT_USE_COUPON, '[商品失效]'.json_encode($couponsActivityAvailableIds)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (empty($goods)) { |
|
|
|
@ -196,8 +213,6 @@ class OrderOnlineService implements OrderOnlineServiceInterface |
|
|
|
|
|
|
|
// 优惠券的使用
|
|
|
|
$couponMoney = 0; |
|
|
|
// 优惠券数据
|
|
|
|
$couponRec = CouponRec::query()->lockForUpdate()->whereIn('id', $receiveCouponIds)->get()->toArray(); |
|
|
|
if (!empty($couponRec)) { |
|
|
|
$couponsCanUse = $this->couponRecService->allForOrderOlAvailable($totalAmount, $userId, $marketId, 2, $storeTypeIds); |
|
|
|
$couponCanUseIds = array_column($couponsCanUse, 'id'); |
|
|
|
|