Browse Source

订单模块-赠品和画线价格bugfix

chao 3 years ago
parent
commit
317d3eb532

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

@@ -45,6 +45,7 @@ public class ProductService {
         if (taxFlag) {
             BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
             cartItemVo.setPrice(MathUtil.add(cartItemVo.getPrice(), cartItemTax).doubleValue());
+            cartItemVo.setOriginalPrice(MathUtil.add(cartItemVo.getOriginalPrice(), cartItemTax).doubleValue());
         }
         return taxFlag;
     }

+ 56 - 48
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -96,6 +96,8 @@ public class CartClubServiceImpl implements CartClubService {
                 AtomicDouble shopPrice = new AtomicDouble(0);
                 // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                // 该供应商划线价
+                AtomicDouble shopOriginalPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                 // 供应商下商品列表
@@ -168,6 +170,7 @@ public class CartClubServiceImpl implements CartClubService {
                             }
                             // 该供应商下价格累加
                             shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                            shopOriginalPrice.set(MathUtil.sub(shopOriginalPrice.get(), MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getOriginalPrice())).doubleValue());
                             // 该供应商下商品种类 +1
                             shopKindCount.incrementAndGet();
                             // 购物车总数量 + 当前商品购买数量
@@ -257,7 +260,7 @@ public class CartClubServiceImpl implements CartClubService {
                     // 供应商总优惠
                     shop.setReducedPrice(shopReducedPrice.get());
                     // 供应商划线价
-                    shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                    shop.setOriginalPrice(shopOriginalPrice.get());
                     // 计算总价
                     totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
                     // 优惠总额
@@ -664,6 +667,8 @@ public class CartClubServiceImpl implements CartClubService {
                     AtomicDouble shopPrice = new AtomicDouble(0);
                     // 该供应商满减金额(供应商满减,单品满减)
                     AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                    // 该供应商划线价
+                    AtomicDouble shopOriginalPrice = new AtomicDouble(0);
                     // 供应商促销优惠活动
                     PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                     // 供应商下商品列表
@@ -732,6 +737,7 @@ public class CartClubServiceImpl implements CartClubService {
                             }
                             // 该供应商下价格累加
                             shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                            shopOriginalPrice.set(MathUtil.sub(shopOriginalPrice.get(), MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getOriginalPrice())).doubleValue());
                             // 该供应商下商品种类 +1
                             shopKindCount.incrementAndGet();
                             // 总数量 + 当前商品购买数量
@@ -777,8 +783,7 @@ public class CartClubServiceImpl implements CartClubService {
                             // 供应商总优惠
                             shop.setReducedPrice(shopReducedPrice.get());
                             // 供应商划线价
-                            shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
-
+                            shop.setOriginalPrice(shopOriginalPrice.get());
                             // 添加供应商Id集合
                             shopIds.add(shop.getShopId());
                             // 计算总价
@@ -804,33 +809,34 @@ public class CartClubServiceImpl implements CartClubService {
         totalPromotions.forEach(promotions -> {
             // 该促销内商品总价
             double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
-            // 凑单满减
-            if (promotions.getType() == 2 && promotions.getMode() == 2) {
-                if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
+            // 满足促销条件
+            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());
+                } else if (promotions.getMode() == 3) {
+                    // 全部满赠
+                    promotions.getGiftList().forEach(gift -> {
+                        if (shopIds.contains(gift.getShopId())) {
+                            // 赠品在当前订单内的供应商下
+                            shopList.forEach(shop -> {
+                                if (shop.getShopId().equals(gift.getShopId())) {
+                                    shop.getCartList().add(gift);
+                                }
+                            });
+                        } else {
+                            // 获取赠品供应商
+                            CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
+                            shopIds.add(giftShop.getShopId());
+                            giftShop.setCartList(new ArrayList<>());
+                            giftShop.getCartList().add(gift);
+                            shopList.add(giftShop);
+                        }
+                    });
                 }
-            } else if (promotions.getMode() == 3) {
-                // 全部满赠
-                promotions.getGiftList().forEach(gift -> {
-                    if (shopIds.contains(gift.getShopId())) {
-                        // 赠品在当前订单内的供应商下
-                        shopList.forEach(shop -> {
-                            if (shop.getShopId().equals(gift.getShopId())) {
-                                shop.getCartList().add(gift);
-                            }
-                        });
-                    } else {
-                        // 获取赠品供应商
-                        CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
-                        shopIds.add(giftShop.getShopId());
-                        giftShop.setCartList(new ArrayList<>());
-                        giftShop.getCartList().add(gift);
-                        shopList.add(giftShop);
-                    }
-                });
             }
         });
 
@@ -921,31 +927,33 @@ 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();
-            // 满减
-            if (promotions.getMode() == 2 && MathUtil.compare(totalAmount, promotions.getTouchPrice()) >= 0) {
-                // 总价 - 满减金额
-                totalPrice.set(MathUtil.sub(totalPrice.get(), promotions.getReducedPrice()).doubleValue());
-                // 优惠总额 + 满减金额
-                reducedPrice.set(MathUtil.add(reducedPrice.get(), promotions.getReducedPrice()).doubleValue());
-            }
-            if (promotions.getMode() == 3) {
-                // 获取赠品
-                List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
-                giftList.forEach(gift -> {
-                    if (shop.getShopId().equals(gift.getShopId())) {
-                        // 赠品在当前订单内的供应商下
+            // 满足促销条件
+            if (MathUtil.compare(totalAmount, promotions.getTouchPrice()) >= 0) {
+                // 满减
+                if (promotions.getMode() == 2) {
+                    // 总价 - 满减金额
+                    totalPrice.set(MathUtil.sub(totalPrice.get(), promotions.getReducedPrice()).doubleValue());
+                    // 优惠总额 + 满减金额
+                    reducedPrice.set(MathUtil.add(reducedPrice.get(), promotions.getReducedPrice()).doubleValue());
+                } else if (promotions.getMode() == 3) {
+                    // 满赠
+                    List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+                    giftList.forEach(gift -> {
                         if (shop.getShopId().equals(gift.getShopId())) {
-                            shop.getCartList().add(gift);
+                            // 赠品在当前订单内的供应商下
+                            if (shop.getShopId().equals(gift.getShopId())) {
+                                shop.getCartList().add(gift);
+                            }
+                        } else {
+                            // 获取赠品供应商
+                            CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
+                            giftShop.setCartList(new ArrayList<>());
+                            giftShop.getCartList().add(gift);
+                            shopList.add(giftShop);
                         }
-                    } else {
-                        // 获取赠品供应商
-                        CartShopVo giftShop = baseMapper.getShopByProductId(gift.getProductId());
-                        giftShop.setCartList(new ArrayList<>());
-                        giftShop.getCartList().add(gift);
-                        shopList.add(giftShop);
-                    }
-                });
-                promotions.setGiftList(giftList);
+                    });
+                    promotions.setGiftList(giftList);
+                }
             }
             // 添加到总促销
             totalPromotions.add(promotions);

+ 2 - 0
src/main/java/com/caimei365/order/service/impl/SubmitServiceImpl.java

@@ -717,6 +717,8 @@ public class SubmitServiceImpl implements SubmitService {
             shopOrder.setShopTaxFee(shopTaxFee.get());
             // 付供应商 = 商品费 + 运费 + 税费
             shopOrder.setShouldPayShopAmount(MathUtil.add(shopProductAmount.get(), shopTaxFee.get()).doubleValue());
+            // 付给供应商运费
+            shopOrder.setShopPostFee(0d);
             // 已付供应商金额
             shopOrder.setPayedShopAmount(0d);
             // (付款供应商)付款状态:1待付款、2部分付款、3已付款