|
@@ -58,6 +58,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
AtomicReference<BigDecimal> totalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
AtomicReference<BigDecimal> totalPrice = new AtomicReference<>(BigDecimal.ZERO);
|
|
List<CartProductVo> totalProducts = new ArrayList<>();
|
|
List<CartProductVo> totalProducts = new ArrayList<>();
|
|
List<ShopVo> shopList = new ArrayList<>();
|
|
List<ShopVo> shopList = new ArrayList<>();
|
|
|
|
+ List<String> productIdList = new ArrayList<>();
|
|
Integer onlinePay = 0;
|
|
Integer onlinePay = 0;
|
|
if (productId != null && productId > 0) {
|
|
if (productId != null && productId > 0) {
|
|
//立即购买
|
|
//立即购买
|
|
@@ -92,6 +93,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
BigDecimal shopTotalPrice = BigDecimal.ZERO;
|
|
BigDecimal shopTotalPrice = BigDecimal.ZERO;
|
|
for (CartProductVo product : shopProducts) {
|
|
for (CartProductVo product : shopProducts) {
|
|
shoppingCartService.setPrice(product, userId, collageFlag);
|
|
shoppingCartService.setPrice(product, userId, collageFlag);
|
|
|
|
+ productIdList.add(product.getProductId().toString());
|
|
shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getNum(), product.getPrice()));
|
|
shopTotalPrice = MathUtil.add(shopTotalPrice, MathUtil.mul(product.getNum(), product.getPrice()));
|
|
}
|
|
}
|
|
shop.setShopTotalPrice(shopTotalPrice);
|
|
shop.setShopTotalPrice(shopTotalPrice);
|
|
@@ -99,8 +101,9 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
totalProducts.addAll(shopProducts);
|
|
totalProducts.addAll(shopProducts);
|
|
totalPrice.set(MathUtil.add(totalPrice.get(), shopTotalPrice));
|
|
totalPrice.set(MathUtil.add(totalPrice.get(), shopTotalPrice));
|
|
});
|
|
});
|
|
- // 用户所有可用优惠券
|
|
|
|
- List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, null, null, 1);
|
|
|
|
|
|
+ String[] productIdArr = productIdList.toArray(new String[0]);
|
|
|
|
+ // 已领取商品可用优惠券
|
|
|
|
+ List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, productIdArr, null, 1);
|
|
if (null != couponId) {
|
|
if (null != couponId) {
|
|
// 领券购买对应优惠券领取标识
|
|
// 领券购买对应优惠券领取标识
|
|
AtomicBoolean couponReceiveFlag = new AtomicBoolean(false);
|
|
AtomicBoolean couponReceiveFlag = new AtomicBoolean(false);
|
|
@@ -119,18 +122,23 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
receiveCoupon.setReceiveTime(new Date());
|
|
receiveCoupon.setReceiveTime(new Date());
|
|
receiveCoupon.setDelFlag(0);
|
|
receiveCoupon.setDelFlag(0);
|
|
couponMapper.insertReceiveCoupon(receiveCoupon);
|
|
couponMapper.insertReceiveCoupon(receiveCoupon);
|
|
- // 重新查询已领取优惠券列表
|
|
|
|
- receiveCouponList = couponMapper.findReceiveCouponList(userId, null, null, 1);
|
|
|
|
|
|
+ // 重新查询已领取商品可用优惠券
|
|
|
|
+ receiveCouponList = couponMapper.findReceiveCouponList(userId, productIdArr, null, 1);
|
|
// 再将该领取的优惠券删除,未提交订单不算真正领取
|
|
// 再将该领取的优惠券删除,未提交订单不算真正领取
|
|
couponMapper.deleteReceiveCoupon(receiveCoupon.getReceiveCouponId());
|
|
couponMapper.deleteReceiveCoupon(receiveCoupon.getReceiveCouponId());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- receiveCouponList.forEach(coupon -> {
|
|
|
|
|
|
+ /*ListIterator<CouponVo> iterator = receiveCouponList.listIterator();
|
|
|
|
+ while (iterator.hasNext()) {
|
|
|
|
+ CouponVo coupon = iterator.next();
|
|
// 能参与该优惠券的总金额
|
|
// 能参与该优惠券的总金额
|
|
BigDecimal touchCouponAmount = BigDecimal.ZERO;
|
|
BigDecimal touchCouponAmount = BigDecimal.ZERO;
|
|
|
|
+ // 是否包含优惠券可用商品
|
|
|
|
+ boolean useFlag = false;
|
|
if (coupon.getProductType() == 1) {
|
|
if (coupon.getProductType() == 1) {
|
|
//全商城商品
|
|
//全商城商品
|
|
touchCouponAmount = totalPrice.get();
|
|
touchCouponAmount = totalPrice.get();
|
|
|
|
+ useFlag = true;
|
|
} else {
|
|
} else {
|
|
// 参与优惠券的所有商品id
|
|
// 参与优惠券的所有商品id
|
|
String couponProductIds = couponMapper.getCouponProductIds(coupon.getCouponId());
|
|
String couponProductIds = couponMapper.getCouponProductIds(coupon.getCouponId());
|
|
@@ -138,31 +146,36 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
|
|
// 立即购买
|
|
// 立即购买
|
|
CartProductVo cartProduct = totalProducts.get(0);
|
|
CartProductVo cartProduct = totalProducts.get(0);
|
|
if (couponProductIds.contains(cartProduct.getProductId().toString())) {
|
|
if (couponProductIds.contains(cartProduct.getProductId().toString())) {
|
|
|
|
+ useFlag = true;
|
|
touchCouponAmount = totalPrice.get();
|
|
touchCouponAmount = totalPrice.get();
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// 购物车结算
|
|
// 购物车结算
|
|
for (CartProductVo product : totalProducts) {
|
|
for (CartProductVo product : totalProducts) {
|
|
if (couponProductIds.contains(product.getProductId().toString())) {
|
|
if (couponProductIds.contains(product.getProductId().toString())) {
|
|
|
|
+ useFlag = true;
|
|
touchCouponAmount = MathUtil.add(touchCouponAmount, MathUtil.mul(product.getNum(), product.getPrice()));
|
|
touchCouponAmount = MathUtil.add(touchCouponAmount, MathUtil.mul(product.getNum(), product.getPrice()));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- if (coupon.getNoThresholdFlag() == 1 || touchCouponAmount.compareTo(coupon.getTouchPrice()) > 0) {
|
|
|
|
|
|
+ if ((useFlag && coupon.getNoThresholdFlag() == 1) || touchCouponAmount.compareTo(coupon.getTouchPrice()) > 0) {
|
|
// 满足优惠条件
|
|
// 满足优惠条件
|
|
coupon.setTouchFlag(1);
|
|
coupon.setTouchFlag(1);
|
|
} else {
|
|
} else {
|
|
coupon.setTouchFlag(0);
|
|
coupon.setTouchFlag(0);
|
|
}
|
|
}
|
|
- });
|
|
|
|
|
|
+ if (!useFlag) {
|
|
|
|
+ iterator.remove();
|
|
|
|
+ }
|
|
|
|
+ }*/
|
|
receiveCouponList.sort((o1, o2) -> {
|
|
receiveCouponList.sort((o1, o2) -> {
|
|
// 按满足优惠条件/优惠金额进行排序
|
|
// 按满足优惠条件/优惠金额进行排序
|
|
- if (!o1.getTouchFlag().equals(o2.getTouchFlag())) {
|
|
|
|
|
|
+ /*if (!o1.getTouchFlag().equals(o2.getTouchFlag())) {
|
|
return o1.getTouchFlag() - o2.getTouchFlag();
|
|
return o1.getTouchFlag() - o2.getTouchFlag();
|
|
- } else {
|
|
|
|
- return o2.getCouponAmount().compareTo(o1.getCouponAmount());
|
|
|
|
- }
|
|
|
|
|
|
+ } else {*/
|
|
|
|
+ return o2.getCouponAmount().compareTo(o1.getCouponAmount());
|
|
|
|
+// }
|
|
});
|
|
});
|
|
// 可参与的分享减免活动
|
|
// 可参与的分享减免活动
|
|
ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
|
|
ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
|