|
@@ -1,5 +1,8 @@
|
|
|
package com.caimei365.order.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei365.order.components.ProductService;
|
|
|
import com.caimei365.order.mapper.BaseMapper;
|
|
|
import com.caimei365.order.mapper.CartClubMapper;
|
|
@@ -26,6 +29,8 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|
|
import java.util.stream.Collectors;
|
|
|
import java.util.stream.Stream;
|
|
|
|
|
|
+import static com.alibaba.fastjson.JSON.parseArray;
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* Description
|
|
@@ -110,7 +115,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
AtomicDouble shopOriginalPrice = new AtomicDouble(0);
|
|
|
// 供应商促销优惠活动,以活动分类排序,店铺>凑单>单品
|
|
|
PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
- if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen() == 1 && userIdentity == 1) {
|
|
|
shopPromotion = null;
|
|
|
}
|
|
|
// 供应商下商品列表 ,购物车里的该供应商商品
|
|
@@ -149,7 +154,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取商品促销信息
|
|
|
promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
// 促销活动如果协销不可见直接置空
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
/*
|
|
@@ -165,7 +170,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
//单品满减-计算供应商总价/满减金额
|
|
|
// 叠加优惠计算
|
|
|
if (promotions.getType() == 1 && promotions.getMode() == 2) {
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
//叠加优惠计算
|
|
|
//叠加倍数
|
|
|
shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -267,7 +272,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取赠品
|
|
|
List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
|
|
|
// 叠加赠品
|
|
|
- if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
Integer in = floor.intValue();
|
|
|
List<CartItemVo> g = new ArrayList<>();
|
|
|
g.addAll(giftList);
|
|
@@ -296,7 +301,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
totalPromotions.add(shopPromotion);
|
|
|
// 店铺满减-计算供应商总价/满减金额
|
|
|
if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
|
|
|
- if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
// 该供应商总价 - 满减金额
|
|
|
shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
|
|
|
// 该供应商优惠总额 + 满减金额
|
|
@@ -345,7 +350,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
//叠加倍数
|
|
|
Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
|
|
|
if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
//叠加优惠计算
|
|
|
// 总价 - 满减金额
|
|
|
totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -523,7 +528,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取商品促销信息
|
|
|
PromotionsVo promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
// 如果促销活动协销不可见,移除促销
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
/*
|
|
@@ -576,7 +581,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
//叠加倍数
|
|
|
Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
|
|
|
if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
//叠加优惠计算
|
|
|
// 总价 - 满减金额
|
|
|
totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -792,7 +797,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
AtomicDouble shopOriginalPrice = new AtomicDouble(0);
|
|
|
// 供应商促销优惠活动
|
|
|
PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
- if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen() == 1 && userIdentity == 1) {
|
|
|
shopPromotion = null;
|
|
|
}
|
|
|
// 供应商下商品列表
|
|
@@ -830,7 +835,367 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取商品促销信息
|
|
|
promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
// 如果促销活动协销不可见,移除促销
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
+ promotions = null;
|
|
|
+ }
|
|
|
+ /*
|
|
|
+ * 设置商品促销优惠
|
|
|
+ */
|
|
|
+ if (null != promotions) {
|
|
|
+ BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
|
|
|
+ //叠加倍数
|
|
|
+ Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
|
|
|
+ // 当前促销活动的价格计算列表
|
|
|
+ List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
|
|
|
+ // 更新到总促销列表
|
|
|
+ productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
|
|
|
+ //单品满减-计算供应商总价/满减金额
|
|
|
+ if (promotions.getType() == 1 && promotions.getMode() == 2) {
|
|
|
+ if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) > -1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
+ //叠加优惠计算
|
|
|
+ shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ } else {
|
|
|
+ // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
|
|
|
+ shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
|
|
|
+ shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ cartItemVo.setPromotions(promotions);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (null != promotions || null != shopPromotion) {
|
|
|
+ // 商品处于活动状态
|
|
|
+ cartItemVo.setActStatus(1);
|
|
|
+ // 关闭阶梯价格,活动优先
|
|
|
+ cartItemVo.setLadderFlag(0);
|
|
|
+ } else {
|
|
|
+ if (cartItemVo.getLadderFlag() == 1) {
|
|
|
+ // 设置阶梯价
|
|
|
+ productService.setCartLadderPrices(cartItemVo, taxFlag);
|
|
|
+ } else {
|
|
|
+ // 复购价
|
|
|
+ Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
|
|
|
+ if (null != repurchase && repurchase > 0) {
|
|
|
+ if (taxFlag) {
|
|
|
+ BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(repurchase, cartItemVo.getTaxRate()), 100, 2);
|
|
|
+ cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
|
|
|
+ } else {
|
|
|
+ cartItemVo.setPrice(repurchase);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 该供应商下价格累加
|
|
|
+ shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
|
|
|
+ shopOriginalPrice.set(MathUtil.add(shopOriginalPrice.get(), MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getOriginalPrice())).doubleValue());
|
|
|
+ // 该供应商下可参与店铺促销的商品价格累加
|
|
|
+ if (!(1 == cartItemVo.getSvipProductFlag() && svipUserFlag)) {
|
|
|
+ // 超级会员购买svip商品不享受店铺促销优惠
|
|
|
+ shopPromotionFee.set(MathUtil.add(shopPromotionFee, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
|
|
|
+ }
|
|
|
+ // 该供应商下商品种类 +1
|
|
|
+ shopKindCount.incrementAndGet();
|
|
|
+ // 总数量 + 当前商品购买数量
|
|
|
+ totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
|
|
|
+ }
|
|
|
+
|
|
|
+ if (shopKindCount.get() > 0) {
|
|
|
+ // 店铺促销
|
|
|
+ if (null != shopPromotion) {
|
|
|
+ Double floor = Math.floor(MathUtil.div(shopPromotionFee, shopPromotion.getTouchPrice()).doubleValue());
|
|
|
+ shop.setPromotions(shopPromotion);
|
|
|
+ if (!promotionsIds.contains(shopPromotion.getId())) {
|
|
|
+ promotionsIds.add(shopPromotion.getId());
|
|
|
+ // 店铺满赠
|
|
|
+ if (shopPromotion.getMode() == 3 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
|
|
|
+ // 获取赠品
|
|
|
+ List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
|
|
|
+ //叠加满赠
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
+ Integer in = floor.intValue();
|
|
|
+ List<CartItemVo> g = new ArrayList<>();
|
|
|
+ g.addAll(giftList);
|
|
|
+ if (in > 1) {
|
|
|
+ for (Integer i = 1; i < in; i++) {
|
|
|
+ giftList.addAll(g);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ shopPromotion.setGiftList(giftList);
|
|
|
+ }
|
|
|
+ // 设置该优惠下的商品列表
|
|
|
+ List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
|
|
|
+ productList.forEach(item -> {
|
|
|
+ if (!(1 == item.getSvipProductFlag() && svipUserFlag)) {
|
|
|
+ // 超级会员购买svip商品不享受店铺促销优惠
|
|
|
+ PromotionPriceVo promotionPrice = new PromotionPriceVo();
|
|
|
+ promotionPrice.setProductId(item.getProductId());
|
|
|
+ promotionPrice.setNumber(item.getNumber());
|
|
|
+ promotionPrice.setPrice(item.getPrice());
|
|
|
+ promotionPriceList.add(promotionPrice);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ shopPromotion.setProductList(promotionPriceList);
|
|
|
+ // 添加到总促销
|
|
|
+ totalPromotions.add(shopPromotion);
|
|
|
+ // 店铺满减-计算供应商总价/满减金额
|
|
|
+ // 满减叠加计算
|
|
|
+ if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
+ shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
|
|
|
+ shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
|
|
|
+ } else {
|
|
|
+ // 该供应商总价 - 满减金额
|
|
|
+ shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
|
|
|
+ // 该供应商优惠总额 + 满减金额
|
|
|
+ shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 供应商商品
|
|
|
+ shop.setCartList(productList);
|
|
|
+ // 供应商总价
|
|
|
+ shop.setTotalPrice(shopPrice.get());
|
|
|
+ // 供应商总优惠
|
|
|
+ shop.setReducedPrice(shopReducedPrice.get());
|
|
|
+ // 供应商总超级会员优惠
|
|
|
+ shop.setSvipReducedPrice(shopSvipReducedPrice.get());
|
|
|
+ // 供应商划线价
|
|
|
+ shop.setOriginalPrice(shopOriginalPrice.get());
|
|
|
+ // 添加供应商Id集合
|
|
|
+ shopIds.add(shop.getShopId());
|
|
|
+ // 计算总价
|
|
|
+ totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
|
|
|
+ // 优惠总额
|
|
|
+ reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
|
|
|
+ // 超级会员优惠总额
|
|
|
+ svipReducedPrice.set(MathUtil.add(svipReducedPrice, shop.getSvipReducedPrice()).doubleValue());
|
|
|
+ // 总划线价
|
|
|
+ totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
|
|
|
+ // 商品种类
|
|
|
+ kindCount.updateAndGet(v -> v + shopKindCount.get());
|
|
|
+ }
|
|
|
+ totalProductList.addAll(productList);
|
|
|
+ }
|
|
|
+ // 供应商下商品种类
|
|
|
+ shop.setCount(shopKindCount.get());
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 删除空数据
|
|
|
+ shopList.removeIf(shop -> (null == shop || shop.getCount() == 0));
|
|
|
+
|
|
|
+ }
|
|
|
+ // 总促销计算
|
|
|
+ // 满减满赠叠加计算
|
|
|
+ totalPromotions.forEach(promotions -> {
|
|
|
+ // 该促销内商品总价
|
|
|
+ double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
|
|
|
+ // 满足促销条件
|
|
|
+ if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
|
|
|
+ //叠加倍数
|
|
|
+ Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
|
|
|
+ // 凑单满减
|
|
|
+ if (promotions.getType() == 2 && promotions.getMode() == 2) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
+ //叠加优惠计算
|
|
|
+ // 总价 - 满减金额
|
|
|
+ totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ // 优惠总额 + 满减金额
|
|
|
+ reducedPrice.set(MathUtil.add(reducedPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
+ } else {
|
|
|
+ // 总价 - 满减金额
|
|
|
+ totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
|
|
|
+ // 优惠总额 + 满减金额
|
|
|
+ reducedPrice.set(MathUtil.add(reducedPrice, promotions.getReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ } else if (promotions.getMode() == 3) {
|
|
|
+ //满赠叠加
|
|
|
+ List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
|
|
|
+ //满足叠加
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
+ Integer in = floor.intValue();
|
|
|
+ List<CartItemVo> g = new ArrayList<>();
|
|
|
+ g.addAll(giftList);
|
|
|
+ if (in > 1) {
|
|
|
+ for (Integer i = 1; i < in; i++) {
|
|
|
+ giftList.addAll(g);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ promotions.setGiftList(giftList);
|
|
|
+ // 全部满赠
|
|
|
+ promotions.getGiftList().forEach(gift -> {
|
|
|
+ if (shopIds.contains(gift.getShopId())) {
|
|
|
+ // 赠品在当前订单内的供应商下
|
|
|
+ shopList.forEach(shop -> {
|
|
|
+ if (shop.getShopId().equals(gift.getShopId())) {
|
|
|
+ shop.getCartList().add(gift);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ // 获取赠品供应商
|
|
|
+ CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
|
|
|
+ shopIds.add(giftShop.getShopId());
|
|
|
+ giftShop.setCartList(new ArrayList<>());
|
|
|
+ giftShop.getCartList().add(gift);
|
|
|
+ shopList.add(giftShop);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 发票信息
|
|
|
+ InvoiceVo invoice = baseMapper.getUserInvoice(userId);
|
|
|
+ // 可用余额
|
|
|
+ Double availableMoney = baseMapper.getAbleUserMoney(userId);
|
|
|
+ // 可用采美豆
|
|
|
+ Integer userBeans = baseMapper.getUserBeans(userId);
|
|
|
+ // 用户可用优惠券(总)
|
|
|
+ List<CouponVo> couponList = getUserCartCoupons(totalProductList, source, userId);
|
|
|
+
|
|
|
+ // 包装返回数据
|
|
|
+ Map<String, Object> resultData = new HashMap<>();
|
|
|
+ resultData.put("list", shopList);
|
|
|
+ resultData.put("kindCount", kindCount);
|
|
|
+ resultData.put("totalCount", totalCount);
|
|
|
+ resultData.put("totalPrice", totalPrice);
|
|
|
+ resultData.put("reducedPrice", reducedPrice);
|
|
|
+ resultData.put("svipReducedPrice", svipReducedPrice);
|
|
|
+ resultData.put("totalOriginalPrice", totalOriginalPrice);
|
|
|
+ resultData.put("promotions", totalPromotions);
|
|
|
+ resultData.put("invoice", invoice);
|
|
|
+ resultData.put("userMoney", availableMoney);
|
|
|
+ resultData.put("userBeans", userBeans);
|
|
|
+ resultData.put("includeRecharge", includeRecharge);
|
|
|
+ resultData.put("couponList", couponList);
|
|
|
+ return ResponseJson.success(resultData);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 组合商品立即购买
|
|
|
+ *
|
|
|
+ * @param userId 用户ID
|
|
|
+ * @param productInfo 组合商品信息:Json字符串格式[{"id":4351,"count":1},{}]
|
|
|
+ * @param source 来源 : 1 网站 ; 2 小程序
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @Override
|
|
|
+ public ResponseJson<Map<String, Object>> MultipleBuyNow(Integer userId, String productInfo, Integer source) {
|
|
|
+ log.info("¥¥¥¥¥¥¥¥¥¥ > 组合商品立即购买");
|
|
|
+ // 商品种类
|
|
|
+ AtomicInteger kindCount = new AtomicInteger(0);
|
|
|
+ // 商品总数量
|
|
|
+ AtomicInteger totalCount = new AtomicInteger(0);
|
|
|
+ // 统计商品总金额
|
|
|
+ AtomicDouble totalPrice = new AtomicDouble(0);
|
|
|
+ // 统计总促销满减
|
|
|
+ AtomicDouble reducedPrice = new AtomicDouble(0);
|
|
|
+ // 统计总超级会员优惠
|
|
|
+ AtomicDouble svipReducedPrice = new AtomicDouble(0);
|
|
|
+ // 统计总划线价
|
|
|
+ AtomicDouble totalOriginalPrice = new AtomicDouble(0);
|
|
|
+ // 促销活动(总)
|
|
|
+ List<PromotionsVo> totalPromotions = new ArrayList<>();
|
|
|
+ // 是否包含充值商品,默认false
|
|
|
+ AtomicBoolean includeRecharge = new AtomicBoolean(false);
|
|
|
+ //所有的商品数据
|
|
|
+ List<CartItemVo> totalProductList = new ArrayList<>();
|
|
|
+ // 促销活动Id集合,用于合并促销活动
|
|
|
+ List<Integer> promotionsIds = new ArrayList<>();
|
|
|
+ // 供应商Id集合,用户判断赠品供应商是否在当前供应商中
|
|
|
+ List<Integer> shopIds = new ArrayList<>();
|
|
|
+ // 商品信息map
|
|
|
+ Map<String, Integer> productInfos = new HashMap<>();
|
|
|
+ // 前端接收商品Id信息
|
|
|
+ List<String> productIdList = new ArrayList<>();
|
|
|
+ // 用户身份
|
|
|
+ Integer userIdentity = baseMapper.getIdentityByUserId(userId);
|
|
|
+ // 超级会员标识
|
|
|
+ Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
|
|
|
+ boolean svipUserFlag = null != svipUserId;
|
|
|
+ // productInfo拆解
|
|
|
+ try {
|
|
|
+ JSONArray productArr = parseArray(productInfo);
|
|
|
+ for (Object o : productArr) {
|
|
|
+ JSONObject product = (JSONObject) o;
|
|
|
+ String productId = product.getString("id");
|
|
|
+ Integer productCount = product.getInteger("count");
|
|
|
+ productInfos.put(productId, productCount);
|
|
|
+ productIdList.add(productId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("组合商品信息格式错误", e);
|
|
|
+ return ResponseJson.error("组合商品信息格式错误!Json字符串格式[{\"id\":4351,\"count\":1},{}]", null);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 商品的供应商列表
|
|
|
+ List<CartShopVo> shopList = cartClubMapper.getShopsByProductIds(productIdList);
|
|
|
+ //按供应商分类统计商品
|
|
|
+ if (null != shopList && shopList.size() > 0) {
|
|
|
+ // 遍历供应商列表
|
|
|
+ List<String> finalIdList = productIdList;//商品id列表
|
|
|
+ shopList.forEach(shop -> {
|
|
|
+ if (null != shop) {
|
|
|
+ // 该供应商下商品种类
|
|
|
+ AtomicInteger shopKindCount = new AtomicInteger(0);
|
|
|
+ // 该供应商总价
|
|
|
+ AtomicDouble shopPrice = new AtomicDouble(0);
|
|
|
+ // 该供应商下参与店铺促销的商品总价
|
|
|
+ AtomicDouble shopPromotionFee = new AtomicDouble(0);
|
|
|
+ // 该供应商满减金额(供应商满减,单品满减)
|
|
|
+ AtomicDouble shopReducedPrice = new AtomicDouble(0);
|
|
|
+ // 该供应商svip优惠金额
|
|
|
+ AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
|
|
|
+ // 该供应商划线价
|
|
|
+ AtomicDouble shopOriginalPrice = new AtomicDouble(0);
|
|
|
+ // 供应商促销优惠活动
|
|
|
+ PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
+ if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen() == 1 && userIdentity == 1) {
|
|
|
+ shopPromotion = null;
|
|
|
+ }
|
|
|
+ // 供应商下商品列表
|
|
|
+ // 过滤保存已上架商品
|
|
|
+ List<CartItemVo> productList = cartClubMapper.getProductsByShopIdAndProductIds(shop.getShopId(), finalIdList);
|
|
|
+ productList.forEach(p -> p.setNumber(productInfos.get(p.getProductId().toString())));
|
|
|
+ if (null != productList && productList.size() > 0) {
|
|
|
+ // 去除价格不可见商品
|
|
|
+ productList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && (userIdentity == 2 || svipUserFlag))));
|
|
|
+ // 去除库存不足商品
|
|
|
+ productList.removeIf(cartItemVo -> !(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber()));
|
|
|
+ // 迭代器设置商品信息
|
|
|
+ for (CartItemVo cartItemVo : productList) {
|
|
|
+ // 设置商品图片及税费
|
|
|
+ boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
|
|
|
+ // 是否充值商品
|
|
|
+ boolean recharge = productService.isRechargeProduct(cartItemVo.getProductId());
|
|
|
+ if (recharge) {
|
|
|
+ includeRecharge.set(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (1 == cartItemVo.getSvipProductFlag()) {
|
|
|
+ // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
|
|
|
+ // 超级会员设置商品优惠价
|
|
|
+ productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
|
|
|
+ if (svipUserFlag) {
|
|
|
+ // 超级会员设置超级会员优惠总额 + 商品优惠金额
|
|
|
+ shopSvipReducedPrice.set(MathUtil.add(shopSvipReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 非超级会员优惠商品参与促销活动
|
|
|
+ // 获取商品促销信息
|
|
|
+ PromotionsVo promotions = null;
|
|
|
+ // 没有店铺促销时,商品促销才有效 单品/凑单活动
|
|
|
+ if (null == shopPromotion) {
|
|
|
+ // 获取商品促销信息
|
|
|
+ promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
+ // 如果促销活动协销不可见,移除促销
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
/*
|
|
@@ -847,7 +1212,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
//单品满减-计算供应商总价/满减金额
|
|
|
if (promotions.getType() == 1 && promotions.getMode() == 2) {
|
|
|
if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) > -1) {
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
//叠加优惠计算
|
|
|
shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -910,7 +1275,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取赠品
|
|
|
List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
|
|
|
//叠加满赠
|
|
|
- if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
Integer in = floor.intValue();
|
|
|
List<CartItemVo> g = new ArrayList<>();
|
|
|
g.addAll(giftList);
|
|
@@ -940,7 +1305,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 店铺满减-计算供应商总价/满减金额
|
|
|
// 满减叠加计算
|
|
|
if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
|
|
|
- if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount() == 0 && floor > 1) {
|
|
|
shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
|
|
|
shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
|
|
|
} else {
|
|
@@ -996,7 +1361,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
|
|
|
// 凑单满减
|
|
|
if (promotions.getType() == 2 && promotions.getMode() == 2) {
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
//叠加优惠计算
|
|
|
// 总价 - 满减金额
|
|
|
totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -1012,7 +1377,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
//满赠叠加
|
|
|
List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
|
|
|
//满足叠加
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
Integer in = floor.intValue();
|
|
|
List<CartItemVo> g = new ArrayList<>();
|
|
|
g.addAll(giftList);
|
|
@@ -1126,7 +1491,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
|
|
|
// 供应商促销优惠活动
|
|
|
PromotionsVo promotions = baseMapper.getPromotionByShopId(shop.getShopId());
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
boolean hasGift = false;
|
|
@@ -1144,7 +1509,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 获取商品促销信息
|
|
|
promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
|
|
|
//协销不可见
|
|
|
- if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
|
|
|
+ if (promotions != null && promotions.getSeen() != null && promotions.getSeen() == 1 && userIdentity == 1) {
|
|
|
promotions = null;
|
|
|
}
|
|
|
} else {
|
|
@@ -1164,7 +1529,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
// 满减
|
|
|
if (promotions.getMode() == 2) {
|
|
|
// 总价 - 满减金额
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
totalPrice.set(MathUtil.sub(totalPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
|
// 优惠总额 + 满减金额
|
|
|
reducedPrice.set(MathUtil.add(reducedPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
|
|
@@ -1178,7 +1543,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
hasGift = true;
|
|
|
List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
|
|
|
//满足叠加
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
Integer in = floor.intValue();
|
|
|
List<CartItemVo> g = new ArrayList<>();
|
|
|
g.addAll(giftList);
|
|
@@ -1241,7 +1606,7 @@ public class CartClubServiceImpl implements CartClubService {
|
|
|
Double totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice()).doubleValue();
|
|
|
Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
|
|
|
//满足叠加
|
|
|
- if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
|
|
|
+ if (promotions.getDiscount() != null && promotions.getDiscount() == 0 && floor > 1) {
|
|
|
Integer in = floor.intValue();
|
|
|
List<CartItemVo> g = new ArrayList<>();
|
|
|
g.addAll(giftList);
|