Procházet zdrojové kódy

促销活动协销不可见控制

zhijiezhao před 3 roky
rodič
revize
0321af5bfd

+ 37 - 23
src/main/java/com/caimei365/order/components/ProductService.java

@@ -33,6 +33,7 @@ public class ProductService {
 
     /**
      * 设置商品图片及税费
+     *
      * @param cartItemVo 购物车商品
      * @return taxFlag 是否需要设置税费
      */
@@ -53,6 +54,7 @@ public class ProductService {
 
     /**
      * 设置购物车阶梯价
+     *
      * @param cartItemVo
      * @param taxFlag
      */
@@ -124,12 +126,13 @@ public class ProductService {
 
     /**
      * 把当前促销更新购物车总促销
-     * @param totalPromotions 总促销列表
-     * @param promotionsIds   总促销Id集合
-     * @param promotions      当前促销
-     * @param promotionPriceList  当前促销商品价格计算列表
+     *
+     * @param totalPromotions    总促销列表
+     * @param promotionsIds      总促销Id集合
+     * @param promotions         当前促销
+     * @param promotionPriceList 当前促销商品价格计算列表
      */
-    public void updateTotalPromotions(List<PromotionsVo> totalPromotions, List<Integer> promotionsIds, PromotionsVo promotions, List<PromotionPriceVo> promotionPriceList) {
+    public void updateTotalPromotions(List<PromotionsVo> totalPromotions, List<Integer> promotionsIds, PromotionsVo promotions, List<PromotionPriceVo> promotionPriceList, Double floor) {
         if (promotionsIds.contains(promotions.getId())) {
             // 列表已有该促销活动
             totalPromotions.forEach(item -> {
@@ -144,9 +147,14 @@ public class ProductService {
             if (promotions.getMode() == 3) {
                 // 获取赠品
                 List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
-//                加倍数-1次
-//                giftList.addAll(giftList);
-                //todo 满赠叠加计算
+                // 符合条件赠品翻倍
+                if (floor != null && promotions.getDiscount() != null && floor > 1 && promotions.getDiscount().equals("0")) {
+                    Integer in = floor.intValue();
+                    List<CartItemVo> g = new ArrayList<>();
+                    for (Integer i = 1; i < in; i++) {
+                        giftList.addAll(g);
+                    }
+                }
                 promotions.setGiftList(giftList);
             }
             promotions.setProductList(promotionPriceList);
@@ -157,18 +165,20 @@ public class ProductService {
 
     /**
      * 是否订单充值商品或定金商品
+     *
      * @param productId 商品id
      * @return Boolean
      */
-    public boolean isRechargeProduct(Integer productId){
+    public boolean isRechargeProduct(Integer productId) {
         int[] products = {6060, 6061, 6062, 6063, 6064, 6065, 6066, 6067, 6068, 6069};
         return ArrayUtils.contains(products, productId);
     }
 
     /**
      * 计算运费
-     * @param userId     用户ID
-     * @param townId     地区Id
+     *
+     * @param userId        用户ID
+     * @param townId        地区Id
      * @param productIdList 商品Id列表
      */
     public Map<String, Object> computePostage(Integer userId, Integer townId, List<String> productIdList) {
@@ -184,7 +194,7 @@ public class ProductService {
         // 获取商品运费 (商品数据库 0包邮 1到付 2默认(遵循运费规则))
         List<ProductPostageVo> postageFlagList = baseMapper.getPostageFlagList(productIdList);
         if (null != postageFlagList && postageFlagList.size() > 0) {
-            for (ProductPostageVo postageVo : postageFlagList){
+            for (ProductPostageVo postageVo : postageFlagList) {
                 if (null != postageVo) {
                     // 是否是仪器 或 设置了运费到付
                     boolean flag = (null == postageVo.getCommodityType() || 2 == postageVo.getCommodityType() || (null != postageVo.getPostageFlag() && 1 == postageVo.getPostageFlag()));
@@ -219,7 +229,7 @@ public class ProductService {
             if (null != address && 202 == address.getCityId()) {
                 // 深圳市内运费10
                 postage = 10.00d;
-            } else if (null != address && 19 == address.getProvinceId()){
+            } else if (null != address && 19 == address.getProvinceId()) {
                 // 广东省内运费15元
                 postage = 15.00d;
             } else {
@@ -234,10 +244,11 @@ public class ProductService {
 
     /**
      * 更新复购价格库
-     * @param order         主订单
-     * @param orderProduct  订单商品
-     * @param secondFlag    是否二手商品
-     * @param note          日志备注
+     *
+     * @param order        主订单
+     * @param orderProduct 订单商品
+     * @param secondFlag   是否二手商品
+     * @param note         日志备注
      */
     public void savePurchasePrice(OrderPo order, OrderProductPo orderProduct, boolean secondFlag, String note) {
         // 非二手订单, 非活动商品,非阶梯价商品,非运费商品,非赠品 才可以写入复购价
@@ -308,6 +319,7 @@ public class ProductService {
 
     /**
      * 保存余额抵扣到收款记录
+     *
      * @param balancePayFee 余额抵扣
      * @param orderId       主订单Id
      * @param note          日志备注
@@ -345,21 +357,23 @@ public class ProductService {
 
     /**
      * 更新用户采美豆
-     * @param beansHistory  采美豆使用记录
-     * @param userBeans     用户原有采美豆数量
-     * @param note          日志备注
+     *
+     * @param beansHistory 采美豆使用记录
+     * @param userBeans    用户原有采美豆数量
+     * @param note         日志备注
      */
     public void updateUserBeans(UserBeansHistoryPo beansHistory, Integer userBeans, String note) {
         // 保存 采美豆使用记录
         baseMapper.insertBeansHistory(beansHistory);
         baseMapper.updateUserBeans(beansHistory.getUserId(), userBeans);
-        log.info(note + ">>>>>更新用户采美豆(update[user(userBeans:"+ userBeans +")]),userId:" + beansHistory.getUserId());
+        log.info(note + ">>>>>更新用户采美豆(update[user(userBeans:" + userBeans + ")]),userId:" + beansHistory.getUserId());
     }
 
     /**
      * 设置超级会员优惠商品价格
-     * @param cartItemVo    当前购物车商品
-     * @param taxFlag       计算税费标志
+     *
+     * @param cartItemVo   当前购物车商品
+     * @param taxFlag      计算税费标志
      * @param svipUserFlag
      */
     public void setSvipProductPrice(CartItemVo cartItemVo, boolean taxFlag, boolean svipUserFlag) {

+ 105 - 42
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -110,6 +110,9 @@ 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) {
+                    shopPromotion = null;
+                }
                 // 供应商下商品列表 ,购物车里的该供应商商品
                 List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shop.getShopId(), userId);
 
@@ -155,16 +158,16 @@ public class CartClubServiceImpl implements CartClubService {
                                     if (null != promotions) {
                                         // 当前促销活动的价格计算列表
                                         List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
+                                        BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
+                                        Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                                         // 更新到总促销列表
-                                        productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
+                                        productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
                                         //单品满减-计算供应商总价/满减金额
                                         // 叠加优惠计算
                                         if (promotions.getType() == 1 && promotions.getMode() == 2) {
-                                            BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
-                                            if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                                            if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
                                                 //叠加优惠计算
                                                 //叠加倍数
-                                                Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                                                 shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                                                 shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                                             } else {
@@ -259,9 +262,21 @@ public class CartClubServiceImpl implements CartClubService {
                         if (!promotionsIds.contains(shopPromotion.getId())) {
                             promotionsIds.add(shopPromotion.getId());
                             // 店铺满赠
+                            Double floor = Math.floor(MathUtil.div(shopPromotionFee, shopPromotion.getTouchPrice()).doubleValue());
                             if (shopPromotion.getMode() == 3) {
                                 // 获取赠品
                                 List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
+                                // 叠加赠品
+                                if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("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);
                             }
                             // 设置该优惠下的商品列表
@@ -281,10 +296,17 @@ public class CartClubServiceImpl implements CartClubService {
                             totalPromotions.add(shopPromotion);
                             // 店铺满减-计算供应商总价/满减金额
                             if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
-                                // 该供应商总价 - 满减金额
-                                shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
-                                // 该供应商优惠总额 + 满减金额
-                                shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
+                                    // 该供应商总价 - 满减金额
+                                    shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
+                                    // 该供应商优惠总额 + 满减金额
+                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), 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());
+                                }
                             }
                         }
                     }
@@ -320,11 +342,11 @@ public class CartClubServiceImpl implements CartClubService {
                 if (promotions.getType() == 2 && promotions.getMode() == 2) {
                     // 该促销内商品总价
                     double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
+                    //叠加倍数
+                    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")) {
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
                             //叠加优惠计算
-                            //叠加倍数
-                            Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
                             // 总价 - 满减金额
                             totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                             // 优惠总额 + 满减金额
@@ -508,6 +530,8 @@ public class CartClubServiceImpl implements CartClubService {
                  * 设置商品促销优惠
                  */
                 if (null != promotions) {
+                    BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
+                    Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                     // 关闭阶梯价格,活动优先
                     cartItemVo.setLadderFlag(0);
                     // 商品处于活动状态
@@ -515,7 +539,7 @@ public class CartClubServiceImpl implements CartClubService {
                     // 当前促销活动的价格计算列表
                     List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
                     // 更新到总促销列表
-                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
+                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
                 } else {
                     if (cartItemVo.getLadderFlag() == 1) {
                         // 设置阶梯价
@@ -549,11 +573,11 @@ public class CartClubServiceImpl implements CartClubService {
                 if (promotions.getMode() == 2) {
                     // 该促销内商品总价
                     double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
+                    //叠加倍数
+                    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")) {
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
                             //叠加优惠计算
-                            //叠加倍数
-                            Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
                             // 总价 - 满减金额
                             totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                         } else {
@@ -768,6 +792,9 @@ 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) {
+                        shopPromotion = null;
+                    }
                     // 供应商下商品列表
                     // 过滤保存已上架商品
                     List<CartItemVo> productList = cartClubMapper.getCartProductsByShopIdAndProductIds(userId, shop.getShopId(), finalIdList);
@@ -810,18 +837,18 @@ public class CartClubServiceImpl implements CartClubService {
                                      * 设置商品促销优惠
                                      */
                                     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);
+                                        productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
                                         //单品满减-计算供应商总价/满减金额
                                         if (promotions.getType() == 1 && promotions.getMode() == 2) {
-                                            BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
                                             if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) > -1) {
-                                                if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                                                if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
                                                     //叠加优惠计算
-                                                    //叠加倍数
-                                                    Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                                                     shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                                                     shopReducedPrice.set(MathUtil.add(shopReducedPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                                                 } else {
@@ -883,17 +910,17 @@ public class CartClubServiceImpl implements CartClubService {
                                         // 获取赠品
                                         List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
                                         //叠加满赠
-                                        if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0")) {
-                                            Integer in = Integer.valueOf(String.valueOf(floor));
+                                        if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("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(giftList);
+                                                    giftList.addAll(g);
                                                 }
                                             }
-                                            shopPromotion.setGiftList(giftList);
-                                        } else {
-                                            shopPromotion.setGiftList(giftList);
                                         }
+                                        shopPromotion.setGiftList(giftList);
                                     }
                                     // 设置该优惠下的商品列表
                                     List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
@@ -913,7 +940,7 @@ public class CartClubServiceImpl implements CartClubService {
                                     // 店铺满减-计算供应商总价/满减金额
                                     // 满减叠加计算
                                     if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
-                                        if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0")) {
+                                        if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("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 {
@@ -965,16 +992,16 @@ public class CartClubServiceImpl implements CartClubService {
             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().equals("0")) {
+                    if (promotions.getDiscount() != null && promotions.getDiscount().equals("0") && floor > 1) {
                         //叠加优惠计算
-                        //叠加倍数
-                        Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
                         // 总价 - 满减金额
-                        totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(),floor)).doubleValue());
+                        totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
                         // 优惠总额 + 满减金额
-                        reducedPrice.set(MathUtil.add(reducedPrice, 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());
@@ -982,6 +1009,20 @@ public class CartClubServiceImpl implements CartClubService {
                         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().equals("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())) {
@@ -1085,6 +1126,9 @@ public class CartClubServiceImpl implements CartClubService {
 
         // 供应商促销优惠活动
         PromotionsVo promotions = baseMapper.getPromotionByShopId(shop.getShopId());
+        if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
+            promotions = null;
+        }
         boolean hasGift = false;
         if (1 == cartItemVo.getSvipProductFlag()) {
             // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
@@ -1099,6 +1143,10 @@ public class CartClubServiceImpl implements CartClubService {
             if (null == promotions) {
                 // 获取商品促销信息
                 promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                //协销不可见
+                if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
+                    promotions = null;
+                }
             } else {
                 shop.setPromotions(promotions);
             }
@@ -1110,13 +1158,13 @@ public class CartClubServiceImpl implements CartClubService {
                 List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
                 promotions.setProductList(promotionPriceList);
                 Double totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice()).doubleValue();
+                Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                 // 满足促销条件
                 if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) >= 0) {
-                    Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                     // 满减
                     if (promotions.getMode() == 2) {
                         // 总价 - 满减金额
-                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("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());
@@ -1128,20 +1176,19 @@ public class CartClubServiceImpl implements CartClubService {
                     } else if (promotions.getMode() == 3) {
                         // 满足满赠
                         hasGift = true;
+                        List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
                         //满足叠加
-                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
-                            List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
-                            Integer in = Integer.valueOf(String.valueOf(floor));
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("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(giftList);
+                                    giftList.addAll(g);
                                 }
                             }
-                            promotions.setGiftList(giftList);
-                        } else {
-                            List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
-                            promotions.setGiftList(giftList);
                         }
+                        promotions.setGiftList(giftList);
                     }
                 }
                 // 添加到总促销
@@ -1190,6 +1237,22 @@ public class CartClubServiceImpl implements CartClubService {
         shopList.add(0, shop);
         // 满足促销满赠
         if (hasGift) {
+            List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+            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) {
+                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())) {
                     // 赠品在当前订单内的供应商下

+ 124 - 32
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -89,7 +89,7 @@ public class CartSellerServiceImpl implements CartSellerService {
         PageHelper.startPage(pageNum, pageSize);
         // 协销购物车供应商列表
         List<CartShopVo> shopInfoList = cartSellerMapper.getSellerCartShops(serviceProviderId, clubId);
-        if (null != shopInfoList && shopInfoList.size()>0) {
+        if (null != shopInfoList && shopInfoList.size() > 0) {
             shopInfoList.removeIf(Objects::isNull);
             // 遍历供应商列表
             shopInfoList.forEach(shop -> {
@@ -107,6 +107,9 @@ public class CartSellerServiceImpl implements CartSellerService {
                 AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
+                if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen().equals("1")) {
+                    shopPromotion = null;
+                }
                 // 供应商下商品列表
                 List<CartItemVo> productList = cartSellerMapper.getSellerCartProducts(serviceProviderId, clubId, shop.getShopId());
                 // 迭代器设置商品信息
@@ -143,21 +146,33 @@ public class CartSellerServiceImpl implements CartSellerService {
                             if (null == shopPromotion) {
                                 // 获取商品促销信息
                                 promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                                // 促销活动如果协销不可见直接置空
+                                if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1")) {
+                                    promotions = null;
+                                }
                                 /*
                                  * 设置商品促销优惠
                                  */
-                                if (null != promotions) {
+                                if (null != promotions && !promotions.getSeen().equals("1")) {
+                                    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);
+                                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
                                     //单品满减-计算供应商总价/满减金额
                                     if (promotions.getType() == 1 && promotions.getMode() == 2) {
-                                        BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
                                         if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) > -1) {
-                                            // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
-                                            shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
-                                            shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
+                                            if (promotions.getDiscount() != null && promotions.getDiscount().equals("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);
@@ -206,10 +221,22 @@ public class CartSellerServiceImpl implements CartSellerService {
                     shop.setPromotions(shopPromotion);
                     if (!promotionsIds.contains(shopPromotion.getId())) {
                         promotionsIds.add(shopPromotion.getId());
+                        Double floor = Math.floor(MathUtil.div(shopPromotionFee, shopPromotion.getTouchPrice()).doubleValue());
                         // 店铺满赠
                         if (shopPromotion.getMode() == 3) {
                             // 获取赠品
                             List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
+                            // 叠加赠品
+                            if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("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);
                         }
                         // 设置该优惠下的商品列表
@@ -226,10 +253,17 @@ public class CartSellerServiceImpl implements CartSellerService {
                         totalPromotions.add(shopPromotion);
                         // 店铺满减-计算供应商总价/满减金额
                         if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPrice, shopPromotion.getTouchPrice()) > -1) {
-                            // 该供应商总价 - 满减金额
-                            shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
-                            // 该供应商优惠总额 + 满减金额
-                            shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                            if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
+                                // 该供应商总价 - 满减金额
+                                shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
+                                // 该供应商优惠总额 + 满减金额
+                                shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), 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());
+                            }
                         }
                     }
                 }
@@ -251,7 +285,7 @@ public class CartSellerServiceImpl implements CartSellerService {
             // 删除空数据
             shopInfoList.removeIf(shop -> (null == shop || shop.getCount() == 0));
         }
-        if (null == shopInfoList){
+        if (null == shopInfoList) {
             shopInfoList = new ArrayList<>();
         }
         PageInfo<CartShopVo> pageInfo = new PageInfo(shopInfoList);
@@ -320,6 +354,7 @@ public class CartSellerServiceImpl implements CartSellerService {
 
     /**
      * 添加购物车,插入数据库
+     *
      * @param sellerCartDto SellerCartDto
      */
     private void addSellerCart(SellerCartDto sellerCartDto) {
@@ -357,7 +392,7 @@ public class CartSellerServiceImpl implements CartSellerService {
     public ResponseJson<Integer> updateSellerCart(SellerCartDto sellerCartDto) {
         SellerCartPo cart = cartSellerMapper.getSellerCartById(sellerCartDto.getId());
         if (!sellerCartDto.getServiceProviderId().equals(cart.getServiceProviderId())) {
-            return ResponseJson.error("协销Id不正确!",null);
+            return ResponseJson.error("协销Id不正确!", null);
         }
         cart.setNum(sellerCartDto.getProductCount());
         cart.setAddTime(new Date());
@@ -433,7 +468,7 @@ public class CartSellerServiceImpl implements CartSellerService {
         boolean svipUserFlag = null != svipUserId;
         // 供应商列表
         List<CartShopVo> shopList = cartSellerMapper.getCartShopsByProductIds(serviceProviderId, clubId, productIdList);
-        if (null != shopList && shopList.size()>0) {
+        if (null != shopList && shopList.size() > 0) {
             // 遍历供应商列表
             List<String> finalIdList = productIdList;
             shopList.forEach(shop -> {
@@ -449,9 +484,12 @@ public class CartSellerServiceImpl implements CartSellerService {
                 AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
+                if (shopPromotion != null && shopPromotion.getSeen() != null && shopPromotion.getSeen().equals("1")) {
+                    shopPromotion = null;
+                }
                 // 供应商下商品列表
                 List<CartItemVo> productList = cartSellerMapper.getCartProductsByProductIds(serviceProviderId, clubId, shop.getShopId(), finalIdList);
-                if (null != productList && productList.size()>0) {
+                if (null != productList && productList.size() > 0) {
                     for (CartItemVo cartItemVo : productList) {
                         // 设置商品图片及税费
                         boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
@@ -468,28 +506,40 @@ public class CartSellerServiceImpl implements CartSellerService {
                                 // 超级会员设置超级会员优惠总额 + 商品优惠金额
                                 shopReducedPrice.set(MathUtil.add(shopReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
                             }
-                        } else{
+                        } else {
                             // 获取商品促销信息
                             PromotionsVo promotions = null;
                             // 没有店铺促销时,商品促销才有效
                             if (null == shopPromotion) {
                                 // 获取商品促销信息
                                 promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                                // 促销活动如果协销不可见直接置空
+                                if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("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);
+                                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList, floor);
                                     //单品满减-计算供应商总价/满减金额
                                     if (promotions.getType() == 1 && promotions.getMode() == 2) {
-                                        BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
                                         if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) > -1) {
-                                            // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
-                                            shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
-                                            shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
+                                            if (promotions.getDiscount() != null && promotions.getDiscount().equals("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);
@@ -532,20 +582,32 @@ public class CartSellerServiceImpl implements CartSellerService {
                     }
                     if (shopKindCount.get() > 0) {
                         // 店铺促销
-                        if (null != shopPromotion) {
+                        if (null != shopPromotion && !shopPromotion.getSeen().equals("1")) {
                             shop.setPromotions(shopPromotion);
                             if (!promotionsIds.contains(shopPromotion.getId())) {
                                 promotionsIds.add(shopPromotion.getId());
                                 // 店铺满赠
+                                Double floor = Math.floor(MathUtil.div(shopPromotionFee, shopPromotion.getTouchPrice()).doubleValue());
                                 if (shopPromotion.getMode() == 3) {
                                     // 获取赠品
                                     List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
+                                    // 叠加赠品
+                                    if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("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)){
+                                    if (!(1 == item.getSvipProductFlag() && svipUserFlag)) {
                                         // 超级会员购买svip商品不享受店铺促销优惠
                                         PromotionPriceVo promotionPrice = new PromotionPriceVo();
                                         promotionPrice.setProductId(item.getProductId());
@@ -559,10 +621,17 @@ public class CartSellerServiceImpl implements CartSellerService {
                                 totalPromotions.add(shopPromotion);
                                 // 店铺满减-计算供应商总价/满减金额
                                 if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
-                                    // 该供应商总价 - 满减金额
-                                    shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
-                                    // 该供应商优惠总额 + 满减金额
-                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                    if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0") && floor > 1) {
+                                        // 该供应商总价 - 满减金额
+                                        shopPrice.set(MathUtil.sub(shopPrice.get(), MathUtil.mul(shopPromotion.getReducedPrice(), floor)).doubleValue());
+                                        // 该供应商优惠总额 + 满减金额
+                                        shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), 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());
+                                    }
                                 }
                             }
                         }
@@ -604,14 +673,37 @@ public class CartSellerServiceImpl implements CartSellerService {
             // 该促销内商品总价
             double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
             // 凑单满减
+            Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
             if (promotions.getType() == 2 && promotions.getMode() == 2) {
                 if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
-                    // 总价 - 满减金额
-                    totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
-                    // 优惠总额 + 满减金额
-                    reducedPrice.set(MathUtil.add(reducedPrice, promotions.getReducedPrice()).doubleValue());
+                    if (promotions.getDiscount() != null && promotions.getDiscount().equals("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().equals("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())) {
@@ -789,7 +881,7 @@ public class CartSellerServiceImpl implements CartSellerService {
         if (productList.size() == 0) {
             return ResponseJson.error(-2, "订单内的商品已全部失效,不能下单!", null);
         }
-        if (invalid > 0 && (null == againBuyDto.getConfirmFlag() || 1 != againBuyDto.getConfirmFlag())){
+        if (invalid > 0 && (null == againBuyDto.getConfirmFlag() || 1 != againBuyDto.getConfirmFlag())) {
             resultData.put("productList", productList);
             return ResponseJson.error(-3, "部分商品已失效,不能进行购买。是否先将以下商品加入购物车?", resultData);
         }

+ 33 - 33
src/test/java/com/caimei365/order/OrderApplicationTests.java

@@ -1,33 +1,33 @@
-package com.caimei365.order;
-
-import com.caimei365.order.utils.MathUtil;
-import org.junit.jupiter.api.Test;
-import org.springframework.boot.test.context.SpringBootTest;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Random;
-
-/**
- * Description
- *
- * @author : Charles
- * @date : 2021/6/25
- */
-@SpringBootTest
-class OrderApplicationTests {
-
-    @Test
-    void contextLoads() {
-//        Random rand = new Random();
-//        String code = "";
-//        for (int j = 0; j < 5; j++) {
-//            code += rand.nextInt(10) + "";
-//        }
-//        System.out.println(code);
-//        System.out.println(System.currentTimeMillis());
-//        System.out.println(System.currentTimeMillis()/1000);
-//        System.out.println(Math.floor(MathUtil.div(100, 1.7).doubleValue()));
-    }
-
-}
+//package com.caimei365.order;
+//
+//import com.caimei365.order.utils.MathUtil;
+//import org.junit.jupiter.api.Test;
+//import org.springframework.boot.test.context.SpringBootTest;
+//
+//import java.util.ArrayList;
+//import java.util.List;
+//import java.util.Random;
+//import java.util.concurrent.atomic.AtomicReference;
+//
+///**
+// * Description
+// *
+// * @author : Charles
+// * @date : 2021/6/25
+// */
+//@SpringBootTest
+//class OrderApplicationTests {
+//
+//    @Test
+//    void contextLoads() {
+////        Random rand = new Random();
+////        String code = "";
+////        for (int j = 0; j < 5; j++) {
+////            code += rand.nextInt(10) + "";
+////        }
+////        System.out.println(code);
+////        System.out.println(System.currentTimeMillis());
+////        System.out.println(System.currentTimeMillis()/1000);
+////        System.out.println(Math.floor(MathUtil.div(100, 1.7).doubleValue()));
+//    }
+//}