Browse Source

促销活动支持叠加

zhijiezhao 3 years ago
parent
commit
1355146187

+ 5 - 0
src/main/java/com/caimei365/order/components/ProductService.java

@@ -101,6 +101,7 @@ public class ProductService {
         List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
         PromotionPriceVo promotionPrice = new PromotionPriceVo();
         promotionPrice.setProductId(cartItemVo.getProductId());
+        //购买数量
         promotionPrice.setNumber(cartItemVo.getNumber());
         // 设置价格
         if (promotions.getType() == 1 && promotions.getMode() == 1) {
@@ -110,6 +111,7 @@ public class ProductService {
                 promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), addedValueTax).doubleValue());
             }
             promotionPrice.setPrice(promotions.getTouchPrice());
+            // 划线价/原价
             promotionPrice.setOriginalPrice(cartItemVo.getOriginalPrice());
             // 设置商品活动价
             cartItemVo.setPrice(promotions.getTouchPrice());
@@ -142,6 +144,9 @@ public class ProductService {
             if (promotions.getMode() == 3) {
                 // 获取赠品
                 List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+//                加倍数-1次
+//                giftList.addAll(giftList);
+                //todo 满赠叠加计算
                 promotions.setGiftList(giftList);
             }
             promotions.setProductList(promotionPriceList);

+ 9 - 1
src/main/java/com/caimei365/order/model/vo/PromotionsVo.java

@@ -16,6 +16,14 @@ import java.util.List;
 @Data
 public class PromotionsVo implements Serializable {
     private static final long serialVersionUID = 1L;
+    /**
+     * 活动可见度,0所有人,1仅对机构
+     */
+    private String seen;
+    /**
+     * 是否支持叠加优惠,0支持,1不支持
+     */
+    private String discount;
     /**
      * 促销id
      */
@@ -71,7 +79,7 @@ public class PromotionsVo implements Serializable {
      */
     private List<PromotionPriceVo> productList;
     /**
-     * 该优惠下赠品
+     * 该优惠下赠品
      */
     private List<CartItemVo> giftList;
     /**

+ 129 - 30
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -85,6 +85,7 @@ public class CartClubServiceImpl implements CartClubService {
         List<CartItemVo> cartAllProducts = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
+
         // 超级会员标识
         Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
         boolean svipUserFlag = null != svipUserId;
@@ -107,9 +108,9 @@ public class CartClubServiceImpl implements CartClubService {
                 AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 该供应商划线价
                 AtomicDouble shopOriginalPrice = new AtomicDouble(0);
-                // 供应商促销优惠活动
+                // 供应商促销优惠活动,以活动分类排序,店铺>凑单>单品
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
-                // 供应商下商品列表
+                // 供应商下商品列表 ,购物车里的该供应商商品
                 List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shop.getShopId(), userId);
 
                 // 迭代器设置商品信息
@@ -144,6 +145,10 @@ public class CartClubServiceImpl implements CartClubService {
                                 if (null == shopPromotion) {
                                     // 获取商品促销信息
                                     promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                                    // 促销活动如果协销不可见直接置空
+                                    if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
+                                        promotions = null;
+                                    }
                                     /*
                                      * 设置商品促销优惠
                                      */
@@ -153,9 +158,16 @@ public class CartClubServiceImpl implements CartClubService {
                                         // 更新到总促销列表
                                         productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
                                         //单品满减-计算供应商总价/满减金额
+                                        // 叠加优惠计算
                                         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")) {
+                                                //叠加优惠计算
+                                                //叠加倍数
+                                                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 {
                                                 // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
                                                 shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
                                                 shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
@@ -309,10 +321,20 @@ public class CartClubServiceImpl implements CartClubService {
                     // 该促销内商品总价
                     double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
                     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")) {
+                            //叠加优惠计算
+                            //叠加倍数
+                            Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
+                            // 总价 - 满减金额
+                            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());
+                        }
                     }
                 }
             });
@@ -478,6 +500,10 @@ public class CartClubServiceImpl implements CartClubService {
                 boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
                 // 获取商品促销信息
                 PromotionsVo promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                // 如果促销活动协销不可见,移除促销
+                if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
+                    promotions = null;
+                }
                 /*
                  * 设置商品促销优惠
                  */
@@ -519,12 +545,21 @@ public class CartClubServiceImpl implements CartClubService {
             // 总促销-满减计算
             totalPromotions.forEach(promotions -> {
                 // 满减
+                // 满减叠加
                 if (promotions.getMode() == 2) {
                     // 该促销内商品总价
                     double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
                     if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
-                        // 总价 - 满减金额
-                        totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                            //叠加优惠计算
+                            //叠加倍数
+                            Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
+                            // 总价 - 满减金额
+                            totalPrice.set(MathUtil.sub(totalPrice, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
+                        } else {
+                            // 总价 - 满减金额
+                            totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
+                        }
                     }
                 }
             });
@@ -712,11 +747,11 @@ public class CartClubServiceImpl implements CartClubService {
             productIdList.add(productIds);
         }
 
-        // 供应商列表
+        // 购物车商品的供应商列表
         List<CartShopVo> shopList = cartClubMapper.getCartShopsByProductIds(userId, productIdList);
         if (null != shopList && shopList.size() > 0) {
             // 遍历供应商列表
-            List<String> finalIdList = productIdList;
+            List<String> finalIdList = productIdList;//购物车商品id列表
             shopList.forEach(shop -> {
                 if (null != shop) {
                     // 该供应商下商品种类
@@ -734,6 +769,7 @@ public class CartClubServiceImpl implements CartClubService {
                     // 供应商促销优惠活动
                     PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                     // 供应商下商品列表
+                    // 过滤保存已上架商品
                     List<CartItemVo> productList = cartClubMapper.getCartProductsByShopIdAndProductIds(userId, shop.getShopId(), finalIdList);
                     if (null != productList && productList.size() > 0) {
                         // 去除价格不可见商品
@@ -749,6 +785,7 @@ public class CartClubServiceImpl implements CartClubService {
                             if (recharge) {
                                 includeRecharge.set(true);
                             }
+
                             if (1 == cartItemVo.getSvipProductFlag()) {
                                 // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
                                 // 超级会员设置商品优惠价
@@ -758,12 +795,17 @@ public class CartClubServiceImpl implements CartClubService {
                                     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().equals("1") && userIdentity == 1) {
+                                        promotions = null;
+                                    }
                                     /*
                                      * 设置商品促销优惠
                                      */
@@ -776,9 +818,17 @@ public class CartClubServiceImpl implements CartClubService {
                                         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")) {
+                                                    //叠加优惠计算
+                                                    //叠加倍数
+                                                    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 {
+                                                    // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
+                                                    shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
+                                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
+                                                }
                                             }
                                         }
                                         cartItemVo.setPromotions(promotions);
@@ -820,17 +870,30 @@ public class CartClubServiceImpl implements CartClubService {
                             // 总数量 + 当前商品购买数量
                             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) {
+                                    if (shopPromotion.getMode() == 3 && MathUtil.compare(shopPromotionFee, shopPromotion.getTouchPrice()) > -1) {
                                         // 获取赠品
                                         List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
-                                        shopPromotion.setGiftList(giftList);
+                                        //叠加满赠
+                                        if (shopPromotion.getDiscount() != null && shopPromotion.getDiscount().equals("0")) {
+                                            Integer in = Integer.valueOf(String.valueOf(floor));
+                                            if (in > 1) {
+                                                for (Integer i = 1; i < in; i++) {
+                                                    giftList.addAll(giftList);
+                                                }
+                                            }
+                                            shopPromotion.setGiftList(giftList);
+                                        } else {
+                                            shopPromotion.setGiftList(giftList);
+                                        }
                                     }
                                     // 设置该优惠下的商品列表
                                     List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
@@ -848,11 +911,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")) {
+                                            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());
+                                        }
                                     }
                                 }
                             }
@@ -890,6 +959,7 @@ public class CartClubServiceImpl implements CartClubService {
 
         }
         // 总促销计算
+        // 满减满赠叠加计算
         totalPromotions.forEach(promotions -> {
             // 该促销内商品总价
             double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
@@ -897,10 +967,20 @@ public class CartClubServiceImpl implements CartClubService {
             if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
                 // 凑单满减
                 if (promotions.getType() == 2 && promotions.getMode() == 2) {
-                    // 总价 - 满减金额
-                    totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
-                    // 优惠总额 + 满减金额
-                    reducedPrice.set(MathUtil.add(reducedPrice, promotions.getReducedPrice()).doubleValue());
+                    if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                        //叠加优惠计算
+                        //叠加倍数
+                        Double floor = Math.floor(MathUtil.div(touchPrice, promotions.getTouchPrice()).doubleValue());
+                        // 总价 - 满减金额
+                        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) {
                     // 全部满赠
                     promotions.getGiftList().forEach(gift -> {
@@ -1032,17 +1112,36 @@ public class CartClubServiceImpl implements CartClubService {
                 Double totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice()).doubleValue();
                 // 满足促销条件
                 if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) >= 0) {
+                    Double floor = Math.floor(MathUtil.div(totalAmount, promotions.getTouchPrice()).doubleValue());
                     // 满减
                     if (promotions.getMode() == 2) {
                         // 总价 - 满减金额
-                        totalPrice.set(MathUtil.sub(totalPrice.get(), promotions.getReducedPrice()).doubleValue());
-                        // 优惠总额 + 满减金额
-                        reducedPrice.set(MathUtil.add(reducedPrice.get(), promotions.getReducedPrice()).doubleValue());
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                            totalPrice.set(MathUtil.sub(totalPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
+                            // 优惠总额 + 满减金额
+                            reducedPrice.set(MathUtil.add(reducedPrice.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
+                        } else {
+                            totalPrice.set(MathUtil.sub(totalPrice.get(), promotions.getReducedPrice()).doubleValue());
+                            // 优惠总额 + 满减金额
+                            reducedPrice.set(MathUtil.add(reducedPrice.get(), promotions.getReducedPrice()).doubleValue());
+                        }
                     } else if (promotions.getMode() == 3) {
                         // 满足满赠
                         hasGift = true;
-                        List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
-                        promotions.setGiftList(giftList);
+                        //满足叠加
+                        if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                            List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+                            Integer in = Integer.valueOf(String.valueOf(floor));
+                            if (in > 1) {
+                                for (Integer i = 1; i < in; i++) {
+                                    giftList.addAll(giftList);
+                                }
+                            }
+                            promotions.setGiftList(giftList);
+                        } else {
+                            List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+                            promotions.setGiftList(giftList);
+                        }
                     }
                 }
                 // 添加到总促销

+ 134 - 86
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -59,6 +59,7 @@ public class SubmitServiceImpl implements SubmitService {
     private CartSellerMapper cartSellerMapper;
     @Resource
     private RemoteCallService remoteCallService;
+
     /**
      * 生成订单
      *
@@ -71,49 +72,49 @@ public class SubmitServiceImpl implements SubmitService {
      *                  "serviceProviderId": 1378,  //协销ID(小程序忽略)
      *                  "clubCouponId": ""          //优惠券Id
      *                  "orderInfo": [              //【订单商品】
-     *                      { "shopId":1001,                         // 供应商Id
-     *                          "note":备注,
-     *                          "productInfo":[                      // 商品id,数量,赠品数,商品类型
-     *                              {"productId": 2789, "productNum": 1, "presentNum":0,"productType":2},
-     *                              {"productId": 2789, "productNum": 1, "presentNum":0,"productType":0}
-     *                          ]
-     *                      },{多个供应商商品数据结构同上}
+     *                  { "shopId":1001,                         // 供应商Id
+     *                  "note":备注,
+     *                  "productInfo":[                      // 商品id,数量,赠品数,商品类型
+     *                  {"productId": 2789, "productNum": 1, "presentNum":0,"productType":2},
+     *                  {"productId": 2789, "productNum": 1, "presentNum":0,"productType":0}
+     *                  ]
+     *                  },{多个供应商商品数据结构同上}
      *                  ],
      *                  "payInfo": {                //【订单金额】
-     *                      "orderShouldPayFee": 609.11,
-     *                      "balancePayFlag": 0,
-     *                      "clauseId": "2",
-     *                      "postage": "15",
-     *                      "postageFlag": 1, //运费标志:0包邮 -1到付 1遵循运费规则
-     *                      "userBeans": 100,//抵扣采美豆数量
-     *                      "rebateFlag":0
+     *                  "orderShouldPayFee": 609.11,
+     *                  "balancePayFlag": 0,
+     *                  "clauseId": "2",
+     *                  "postage": "15",
+     *                  "postageFlag": 1, //运费标志:0包邮 -1到付 1遵循运费规则
+     *                  "userBeans": 100,//抵扣采美豆数量
+     *                  "rebateFlag":0
      *                  },
      *                  "orderInvoice":             //【发票信息】
-     *                          {"type": 0 // 不开发票  }
-     *                      或: { // 普通发票
-     *                              "type": 1,
-     *                              "invoiceTitle": "企业抬头",
-     *                              "invoiceTitleType": 1,
-     *                              "corporationTaxNum": "XXX4156465465",
-     *                              "invoiceContent": "明细 "
-     *                          }
-     *                      或: { // 增值税发票
-     *                              "type": 2,
-     *                              "invoiceTitle": "单位名称",
-     *                              "corporationTaxNum": "NSRSBM97897",
-     *                              "registeredAddress": "注册地址",
-     *                              "registeredPhone": "15814011616",
-     *                              "openBank": "开户银行",
-     *                              "bankAccountNo": "987987465465464"
-     *                          }
-     *              }
+     *                  {"type": 0 // 不开发票  }
+     *                  或: { // 普通发票
+     *                  "type": 1,
+     *                  "invoiceTitle": "企业抬头",
+     *                  "invoiceTitleType": 1,
+     *                  "corporationTaxNum": "XXX4156465465",
+     *                  "invoiceContent": "明细 "
+     *                  }
+     *                  或: { // 增值税发票
+     *                  "type": 2,
+     *                  "invoiceTitle": "单位名称",
+     *                  "corporationTaxNum": "NSRSBM97897",
+     *                  "registeredAddress": "注册地址",
+     *                  "registeredPhone": "15814011616",
+     *                  "openBank": "开户银行",
+     *                  "bankAccountNo": "987987465465464"
+     *                  }
+     *                  }
      */
     @Transactional(rollbackFor = Exception.class)
     @Override
     public ResponseJson<Map<String, Object>> generateOrder(SubmitDto submitDto) {
         // 获取机构用户Id
         Integer clubUserId = baseMapper.getUserIdByClubId(submitDto.getClubId());
-        if (null == clubUserId || clubUserId == 0){
+        if (null == clubUserId || clubUserId == 0) {
             return ResponseJson.error("机构用户信息异常!", null);
         }
         JSONArray orderInfo = null;
@@ -127,34 +128,37 @@ public class SubmitServiceImpl implements SubmitService {
             log.error("订单参数解析异常try-catch:", e);
             return ResponseJson.error("订单参数解析异常!", null);
         }
-        if (null == orderInfo || orderInfo.isEmpty()){
+        if (null == orderInfo || orderInfo.isEmpty()) {
             return ResponseJson.error("订单商品数据异常!", null);
         }
-        if (null == payInfo || payInfo.isEmpty()){
+        if (null == payInfo || payInfo.isEmpty()) {
             return ResponseJson.error("订单金额数据异常!", null);
         }
-        if (null == orderInvoice || orderInvoice.isEmpty()){
+        if (null == orderInvoice || orderInvoice.isEmpty()) {
             return ResponseJson.error("发票信息数据异常!", null);
         }
         // 打印参数
-        if (3 == submitDto.getCartType()){
-            log.info("******************** 【协销订单】提交订单参数:"+ submitDto);
+        if (3 == submitDto.getCartType()) {
+            log.info("******************** 【协销订单】提交订单参数:" + submitDto);
         } else if (2 == submitDto.getCartType()) {
-            log.info("******************** 【自主订单】立即购买提交订单参数:"+ submitDto);
+            log.info("******************** 【自主订单】立即购买提交订单参数:" + submitDto);
         } else {
-            log.info("******************** 【自主订单】购物车提交订单参数:"+ submitDto);
+            log.info("******************** 【自主订单】购物车提交订单参数:" + submitDto);
         }
         // 机构用户
         OrderParamBo orderParamBo = submitMapper.getOrderUserBoById(clubUserId);
+        //订单来源
         orderParamBo.setOrderSource(submitDto.getOrderSource());
+        //订单商品
         orderParamBo.setOrderInfo(orderInfo);
         // 余额支付标识,0不使用,1使用
         Integer balancePayFlag = (Integer) payInfo.get("balancePayFlag");
-        // 判断用户可用余额是否wei0
+        // 判断用户可用余额是否0
         if (1 == balancePayFlag && null != orderParamBo.getAbleUserMoney() && MathUtil.compare(orderParamBo.getAbleUserMoney(), BigDecimal.ZERO) == 0) {
             return ResponseJson.error("用户可用余额为0.00元!", null);
         }
         orderParamBo.setBalancePayFlag(balancePayFlag);
+        //订单应付总额
         String orderShouldPayFee = (String) payInfo.get("orderShouldPayFee");
         orderParamBo.setOrderShouldPayFee(Double.parseDouble(orderShouldPayFee));
         // 运费标志:0包邮 -1到付 1遵循运费规则                               
@@ -176,10 +180,10 @@ public class SubmitServiceImpl implements SubmitService {
                 offsetBeans = 3000;
             }
             // 与前端传入采美豆数量比较
-            if (null == orderParamBo.getUserBeans() || !userBeans.equals(offsetBeans)){
+            if (null == orderParamBo.getUserBeans() || !userBeans.equals(offsetBeans)) {
                 return ResponseJson.error("采美豆数据异常!", null);
             }
-            if (orderParamBo.getUserBeans()<=0) {
+            if (orderParamBo.getUserBeans() <= 0) {
                 return ResponseJson.error("用户没有剩余采美豆!", null);
             }
         } else {
@@ -192,20 +196,20 @@ public class SubmitServiceImpl implements SubmitService {
             return ResponseJson.error("发票类型不能为空!", null);
         }
         orderParamBo.setInvoiceType(invoiceType);
-        if (1== invoiceType || 2 == invoiceType) {
+        if (1 == invoiceType || 2 == invoiceType) {
             InvoicePo invoice = new InvoicePo();
             String invoiceTitle = (String) orderInvoice.get("invoiceTitle");
-            if (StringUtils.isEmpty(invoiceTitle)){
+            if (StringUtils.isEmpty(invoiceTitle)) {
                 return ResponseJson.error("发票抬头信息不正确!", null);
             }
             String corporationTaxNum = (String) orderInvoice.get("corporationTaxNum");
-            if (StringUtils.isEmpty(corporationTaxNum)){
+            if (StringUtils.isEmpty(corporationTaxNum)) {
                 return ResponseJson.error("纳税人识别号信息不正确!", null);
             }
             invoice.setType(invoiceType);
             invoice.setInvoiceTitle(invoiceTitle);
             invoice.setCorporationTaxNum(corporationTaxNum);
-            if (1== invoiceType) {
+            if (1 == invoiceType) {
                 // 普通发票:发票类型、发票内容(商品明细)、抬头(公司名称)、纳税人识别号[普通发票的公司]
                 String invoiceContent = (String) orderInvoice.get("invoiceContent");
                 Integer invoiceTitleType = (Integer) orderInvoice.get("invoiceTitleType");
@@ -215,7 +219,7 @@ public class SubmitServiceImpl implements SubmitService {
                 invoice.setInvoiceContent(invoiceContent);
                 invoice.setInvoiceTitleType(invoiceTitleType);
             }
-            if (2== invoiceType) {
+            if (2 == invoiceType) {
                 // 增值税发票:发票类型、发票、抬头(公司名称)、纳税人识别号、注册地址、注册电话、开户银行、开户银行账户
                 String registeredAddress = (String) orderInvoice.get("registeredAddress");
                 String registeredPhone = (String) orderInvoice.get("registeredPhone");
@@ -241,20 +245,20 @@ public class SubmitServiceImpl implements SubmitService {
         orderParamBo.setCartType(submitDto.getCartType());
         // 下单人
         Integer buyUserId = null;
-        if (1 == submitDto.getCartType() || 2 == submitDto.getCartType()){
+        if (1 == submitDto.getCartType() || 2 == submitDto.getCartType()) {
             // 自主下单
             buyUserId = clubUserId;
             if (StringUtils.isNotEmpty(submitDto.getUnionId())) {
                 // 运营人员Id
                 Integer operationId = submitMapper.getOperationIdByUnionId(submitDto.getUnionId(), clubUserId);
-                if (null != operationId && operationId>0) {
+                if (null != operationId && operationId > 0) {
                     buyUserId = operationId;
                 }
             }
-        } else if (3 == submitDto.getCartType()){
+        } else if (3 == submitDto.getCartType()) {
             // 协销下单, 获取协销用户Id
             Integer spUserId = submitMapper.getServiceProviderUserId(submitDto.getServiceProviderId());
-            if (null != spUserId && spUserId>0) {
+            if (null != spUserId && spUserId > 0) {
                 buyUserId = spUserId;
             } else {
                 return ResponseJson.error("协销用户异常!", null);
@@ -284,7 +288,7 @@ public class SubmitServiceImpl implements SubmitService {
         OrderPo mainOrder = new OrderPo();
         // 订单来源
         mainOrder.setOrderSource(orderParamBo.getOrderSource());
-        // 订单号
+        // 生成订单号
         String orderNo = CodeUtil.generateOrderNo(orderParamBo.getOrderSource());
         mainOrder.setOrderNo(orderNo);
         // 用户Id
@@ -298,6 +302,7 @@ public class SubmitServiceImpl implements SubmitService {
         mainOrder.setUpdateDate(curDateStr);
         // 订单状态 0 有效  其它无效
         mainOrder.setDelFlag(0);
+        //协销下单
         if (3 == orderParamBo.getCartType()) {
             mainOrder.setSpId(orderParamBo.getServiceProviderId());
             // 协销订单
@@ -368,7 +373,7 @@ public class SubmitServiceImpl implements SubmitService {
         //促销活动ids
         List<Integer> promotionsIds = new ArrayList<>();
         // 促销活动信息
-        List<PromotionsVo> promotionList= new ArrayList<>();
+        List<PromotionsVo> promotionList = new ArrayList<>();
         // 订单商品列表
         List<OrderProductPo> orderProductList = new ArrayList<>();
         List<String> productIdList = new ArrayList<>();
@@ -376,7 +381,7 @@ public class SubmitServiceImpl implements SubmitService {
         // 子订单订单列表
         List<OrderShopPo> shopOrderList = new ArrayList<>();
         JSONArray orderInfo = orderParamBo.getOrderInfo();
-        for (Object infoObject: orderInfo) {
+        for (Object infoObject : orderInfo) {
             JSONObject shopInfo = (JSONObject) infoObject;
             Integer shopId = (Integer) shopInfo.get("shopId");
             String shopNote = (String) shopInfo.get("note");
@@ -481,8 +486,7 @@ public class SubmitServiceImpl implements SubmitService {
                     product.setTaxRate(0d);
                     product.setAddedValueTax(0d);
                     product.setTotalAddedValueTax(0d);
-                }
-                else {
+                } else {
                     // 获取商品购买价格(超级会员优惠商品价格>>>活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
                     Double productPrice = product.getPrice();
                     Double discountPrice = product.getPrice();
@@ -495,6 +499,14 @@ public class SubmitServiceImpl implements SubmitService {
                     if (null == shopPromotions) {
                         promotions = baseMapper.getPromotionByProductId(productId);
                     }
+                    //促销活动如果协销不可见,置为空
+                    Integer userIdentity = baseMapper.getIdentityByUserId(orderParamBo.getUserId());
+                    if (promotions != null && promotions.getSeen() != null && promotions.getSeen().equals("1") && userIdentity == 1) {
+                        promotions = null;
+                    }
+                    if (shopPromotions != null && shopPromotions.getSeen() != null && shopPromotions.getSeen().equals("1") && userIdentity == 1) {
+                        shopPromotions = null;
+                    }
                     // 计算单价
                     if (null != svipProductPo && 1 == svipProductPo.getSvipProductFlag()) {
                         // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
@@ -587,13 +599,22 @@ public class SubmitServiceImpl implements SubmitService {
                         // 单品优惠
                         if (promotions.getType() == 1) {
                             // 是否满足单品优惠条件
-                            if (promotions.getMode()==1 || MathUtil.compare(productFee, promotions.getTouchPrice()) >= 0) {
+                            if (promotions.getMode() == 1 || MathUtil.compare(productFee, promotions.getTouchPrice()) >= 0) {
                                 // 满减
                                 if (promotions.getMode() == 2) {
-                                    // 统计订单总满减金额
-                                    promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
-                                    // 统计单个商品的折后金额
-                                    productFee = MathUtil.sub(productFee, promotions.getReducedPrice()).doubleValue();
+
+                                    if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                                        //叠加优惠计算
+                                        //叠加倍数
+                                        Double floor = Math.floor(MathUtil.div(productFee, promotions.getTouchPrice()).doubleValue());
+                                        promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue());
+                                        productFee = MathUtil.sub(productFee, MathUtil.mul(promotions.getReducedPrice(), floor)).doubleValue();
+                                    } else {
+                                        // 统计订单总满减金额
+                                        promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
+                                        // 统计单个商品的折后金额
+                                        productFee = MathUtil.sub(productFee, promotions.getReducedPrice()).doubleValue();
+                                    }
                                 }
                                 // 添加到总促销
                                 if (!promotionsIds.contains(promotions.getId())) {
@@ -603,14 +624,14 @@ public class SubmitServiceImpl implements SubmitService {
                                 }
                                 product.setOrderPromotionsId(promotions.getId());
                             }
-                        // 凑单优惠
+                            // 凑单优惠
                         } else if (promotions.getType() == 2) {
                             // 商品添加到总促销
                             PromotionPriceVo promotionPrice = new PromotionPriceVo();
                             promotionPrice.setProductId(productId);
                             promotionPrice.setNumber(productNum);
                             promotionPrice.setPrice(discountTaxPrice);
-                            if (null == promotions.getProductList()){
+                            if (null == promotions.getProductList()) {
                                 promotions.setProductList(new ArrayList<>());
                             }
                             promotions.getProductList().add(promotionPrice);
@@ -621,7 +642,7 @@ public class SubmitServiceImpl implements SubmitService {
                             } else {
                                 PromotionsVo finalPromotions = promotions;
                                 promotionList.forEach(promotionsTemp -> {
-                                    if (finalPromotions.getId().equals(promotionsTemp.getId())){
+                                    if (finalPromotions.getId().equals(promotionsTemp.getId())) {
                                         promotionsTemp.getProductList().add(promotionPrice);
                                     }
                                 });
@@ -712,7 +733,7 @@ public class SubmitServiceImpl implements SubmitService {
                  * 子订单金额计算
                  */
                 // 供应商商品数量
-                shopProductCount.set(shopProductCount.get()+product.getNum());
+                shopProductCount.set(shopProductCount.get() + product.getNum());
                 // 佣金 = 应付采美
                 brokerage.set(MathUtil.add(brokerage.get(), product.getCmFee()).doubleValue());
                 // 需要支付金额 shouldPayFee +运费
@@ -743,16 +764,32 @@ public class SubmitServiceImpl implements SubmitService {
                     hasActProductFlag = true;
                     // 满减
                     if (shopPromotions.getMode() == 2) {
-                        // 供应商满减金额
-                        shopOrder.setPromotionFullReduction(shopPromotions.getReducedPrice());
-                        // 统计订单总满减金额
-                        promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), shopPromotions.getReducedPrice()).doubleValue());
-                        // 统计店铺商品总金额
-                        shopProductFee.set(MathUtil.sub(shopProductFee.get(), shopPromotions.getReducedPrice()).doubleValue());
-                        // 统计需要支付金额
-                        needPayAmount.set(MathUtil.sub(needPayAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
-                        // 统计需要支付金额
-                        shopAmount.set(MathUtil.sub(shopAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
+                        if (shopPromotions.getDiscount() != null && shopPromotions.getDiscount().equals("0")) {
+                            //叠加优惠计算
+                            //叠加倍数
+                            Double floor = Math.floor(MathUtil.div(shopPromotionFee.get(), shopPromotions.getTouchPrice()).doubleValue());
+                            // 供应商满减金额
+                            shopOrder.setPromotionFullReduction(MathUtil.mul(shopPromotions.getReducedPrice(), floor).doubleValue());
+                            // 统计订单总满减金额
+                            promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
+                            // 统计店铺商品总金额
+                            shopProductFee.set(MathUtil.sub(shopProductFee.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
+                            // 统计需要支付金额
+                            needPayAmount.set(MathUtil.sub(needPayAmount.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
+                            // 统计需要支付金额
+                            shopAmount.set(MathUtil.sub(shopAmount.get(), MathUtil.mul(shopPromotions.getReducedPrice(), floor)).doubleValue());
+                        } else {
+                            // 供应商满减金额
+                            shopOrder.setPromotionFullReduction(shopPromotions.getReducedPrice());
+                            // 统计订单总满减金额
+                            promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), shopPromotions.getReducedPrice()).doubleValue());
+                            // 统计店铺商品总金额
+                            shopProductFee.set(MathUtil.sub(shopProductFee.get(), shopPromotions.getReducedPrice()).doubleValue());
+                            // 统计需要支付金额
+                            needPayAmount.set(MathUtil.sub(needPayAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
+                            // 统计需要支付金额
+                            shopAmount.set(MathUtil.sub(shopAmount.get(), shopPromotions.getReducedPrice()).doubleValue());
+                        }
                     }
                     // 添加到总促销
                     if (!promotionsIds.contains(shopPromotions.getId())) {
@@ -801,7 +838,7 @@ public class SubmitServiceImpl implements SubmitService {
             // 统计商品总金额
             productTotalFee.set(MathUtil.add(productTotalFee.get(), shopProductFee.get()).doubleValue());
         }
-        if (orderProductList.isEmpty()){
+        if (orderProductList.isEmpty()) {
             return ResponseJson.error("订单商品数据异常!", null);
         }
         // 设置是否是二手订单
@@ -829,10 +866,21 @@ public class SubmitServiceImpl implements SubmitService {
                         //判断是否达到满减满赠要求
                         if (MathUtil.compare(tempProductFee.get(), promotions.getTouchPrice()) >= 0) {
                             if (promotions.getMode() == 2) {
-                                // 满减
-                                promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
-                                // 统计商品总金额
-                                productTotalFee.set(MathUtil.sub(productTotalFee.get(), promotions.getReducedPrice()).doubleValue());
+                                if (promotions.getDiscount() != null && promotions.getDiscount().equals("0")) {
+                                    //叠加优惠计算
+                                    //叠加倍数
+                                    Double floor = Math.floor(MathUtil.div(tempProductFee.get(), promotions.getTouchPrice()).doubleValue());
+                                    // 满减
+                                    promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), MathUtil.mul(promotions.getReducedPrice(),floor)).doubleValue());
+                                    // 统计商品总金额
+                                    productTotalFee.set(MathUtil.sub(productTotalFee.get(), MathUtil.mul(promotions.getReducedPrice(),floor)).doubleValue());
+                                }
+                                else{
+                                    // 满减
+                                    promotionFullReduction.set(MathUtil.add(promotionFullReduction.get(), promotions.getReducedPrice()).doubleValue());
+                                    // 统计商品总金额
+                                    productTotalFee.set(MathUtil.sub(productTotalFee.get(), promotions.getReducedPrice()).doubleValue());
+                                }
                             }
                         } else {
                             // 删除不满足条件的凑单促销
@@ -868,7 +916,7 @@ public class SubmitServiceImpl implements SubmitService {
         /*
          * 计算运费
          */
-        if (3 != orderParamBo.getCartType()){
+        if (3 != orderParamBo.getCartType()) {
             // 机构用户 校验商品运费
             if (orderParamBo.getPostageFlag() != -1) {
                 Integer townId = baseMapper.getTownIdByAddressId(orderParamBo.getAddressId());
@@ -1021,7 +1069,7 @@ public class SubmitServiceImpl implements SubmitService {
             shopOrderIndex.incrementAndGet();
             shopOrder.setShopOrderNo(shopOrderNo.toString());
             // 订单能否拆分 1 为可拆分, 0为不可拆分
-            if (shopOrder.getItemCount() >1) {
+            if (shopOrder.getItemCount() > 1) {
                 shopOrder.setSplitFlag(1);
             } else {
                 shopOrder.setSplitFlag(0);
@@ -1308,7 +1356,7 @@ public class SubmitServiceImpl implements SubmitService {
             beansHistory.setDelFlag(0);
             // 更新用户剩余采美豆数量
             int beans = orderParamBo.getUserBeans() - beansHistory.getNum();
-            productService.updateUserBeans(beansHistory, beans,"【提交订单】");
+            productService.updateUserBeans(beansHistory, beans, "【提交订单】");
         }
 
         /*
@@ -1402,12 +1450,12 @@ public class SubmitServiceImpl implements SubmitService {
     public ResponseJson<Map<String, Object>> generateRechargeOrder(RechargeDto rechargeDto) {
         // 获取机构用户Id
         Integer clubUserId = baseMapper.getUserIdByClubId(rechargeDto.getClubId());
-        if (null == clubUserId || clubUserId == 0){
+        if (null == clubUserId || clubUserId == 0) {
             return ResponseJson.error("机构用户信息异常!", null);
         }
         // 获取协销用户Id
         Integer spUserId = submitMapper.getServiceProviderUserId(rechargeDto.getServiceProviderId());
-        if (null == spUserId || spUserId == 0){
+        if (null == spUserId || spUserId == 0) {
             return ResponseJson.error("协销用户异常!", null);
         }
         log.info("******************** 提交充值订单逻辑处理 start *******************");

+ 6 - 2
src/main/resources/mapper/BaseMapper.xml

@@ -102,7 +102,9 @@
                pr.endTime,
                pr.status,
                prp.productId,
-               prp.supplierId AS shopId
+               prp.supplierId AS shopId,
+               pr.seen,
+               pr.discount
         FROM cm_promotions pr
                  LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
         WHERE prp.supplierId = #{shopId}
@@ -124,7 +126,9 @@
                pr.endTime,
                pr.status,
                prp.productId,
-               prp.supplierId AS shopId
+               prp.supplierId AS shopId,
+               pr.discount,
+               pr.seen
         FROM cm_promotions pr
                  LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
         WHERE prp.productId = #{productId}

+ 7 - 3
src/test/java/com/caimei365/order/OrderApplicationTests.java

@@ -1,8 +1,11 @@
 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;
 
 /**
@@ -14,8 +17,8 @@ import java.util.Random;
 @SpringBootTest
 class OrderApplicationTests {
 
-//    @Test
-//    void contextLoads() {
+    @Test
+    void contextLoads() {
 //        Random rand = new Random();
 //        String code = "";
 //        for (int j = 0; j < 5; j++) {
@@ -24,6 +27,7 @@ class OrderApplicationTests {
 //        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()));
+    }
 
 }