Browse Source

Merge remote-tracking branch 'origin/developer' into developerA

# Conflicts:
#	src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java
#	src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java
chao 3 years ago
parent
commit
f7e6c3e1fa

+ 80 - 104
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -172,7 +172,12 @@ public class CartClubServiceImpl implements CartClubService {
                                         // 复购价
                                         Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
                                         if (null != repurchase && repurchase > 0) {
-                                            cartItemVo.setPrice(repurchase);
+                                            if (taxFlag) {
+                                                BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                                                cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                                            } else {
+                                                cartItemVo.setPrice(repurchase);
+                                            }
                                         }
                                     }
                                 }
@@ -479,7 +484,12 @@ public class CartClubServiceImpl implements CartClubService {
                         // 复购价
                         Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
                         if (null != repurchase && repurchase > 0) {
-                            cartItemVo.setPrice(repurchase);
+                            if (taxFlag) {
+                                BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                                cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                            } else {
+                                cartItemVo.setPrice(repurchase);
+                            }
                         }
                     }
                 }
@@ -656,9 +666,6 @@ public class CartClubServiceImpl implements CartClubService {
         List<Integer> shopIds = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
-        // 超级会员标识
-        Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
-        boolean svipUserFlag = null != svipUserId;
 
         // 前端接收商品Id信息
         List<String> productIdList = new ArrayList<>();
@@ -750,7 +757,12 @@ public class CartClubServiceImpl implements CartClubService {
                                         // 复购价
                                         Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
                                         if (null != repurchase && repurchase > 0) {
-                                            cartItemVo.setPrice(repurchase);
+                                            if (taxFlag) {
+                                                BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                                                cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                                            } else {
+                                                cartItemVo.setPrice(repurchase);
+                                            }
                                         }
                                     }
                                 }
@@ -926,55 +938,69 @@ public class CartClubServiceImpl implements CartClubService {
         if(!(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber())){
             return ResponseJson.error("商品库存不足!", null);
         }
+        List<CartShopVo> shopList = new ArrayList<>();
         // 设置商品图片及税费
         boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
         // 促销活动(总)
         List<PromotionsVo> totalPromotions = new ArrayList<>();
         // 统计商品总金额
-        final Double[] totalPrice = {MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice()).doubleValue()};
+        AtomicDouble originalPrice = new AtomicDouble(0);
+        AtomicDouble totalPrice = new AtomicDouble(0);
         // 统计总促销满减
-        final Double[] reducedPrice = {0d};
+        AtomicDouble reducedPrice = new AtomicDouble(0);
+
         // 供应商促销优惠活动
-        PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
-        // 获取商品促销信息
-        PromotionsVo productPromotions = null;
+        PromotionsVo promotions = baseMapper.getPromotionByShopId(shop.getShopId());
         // 没有店铺促销时,商品促销才有效
-        if (null == shopPromotion) {
+        if (null == promotions) {
             // 获取商品促销信息
-            productPromotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
-            /*
-             * 设置商品促销优惠
-             */
-            if (null != productPromotions) {
-                // 当前促销活动的价格计算列表
-                List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(productPromotions, cartItemVo, taxFlag);
-                // 更新到总促销列表
-                if (productPromotions.getMode() == 3) {
-                    // 获取赠品
-                    List<CartItemVo> giftList = baseMapper.getPromotionGifts(productPromotions.getId());
-                    productPromotions.setGiftList(giftList);
-                }
-                productPromotions.setProductList(promotionPriceList);
-                // 添加到总促销
-                totalPromotions.add(productPromotions);
-                //单品满减-计算供应商总价/满减金额
-                if (productPromotions.getType() == 1 && productPromotions.getMode() == 2) {
-                    BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
-                    if (MathUtil.compare(totalAmount, productPromotions.getTouchPrice()) > -1) {
-                        // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
-                        totalPrice[0] = MathUtil.sub(totalPrice[0], productPromotions.getReducedPrice()).doubleValue();
-                        reducedPrice[0] = MathUtil.add(reducedPrice[0], productPromotions.getReducedPrice()).doubleValue();
+            promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+        } else {
+            shop.setPromotions(promotions);
+        }
+        /*
+         * 设置商品促销优惠
+         */
+        if (null != promotions) {
+            // 当前促销活动的价格计算列表
+            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 (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);
                     }
-                }
-                cartItemVo.setPromotions(productPromotions);
+                });
+                promotions.setGiftList(giftList);
             }
-        }
-        if (null != productPromotions || null != shopPromotion) {
+            // 添加到总促销
+            totalPromotions.add(promotions);
             // 商品处于活动状态
             cartItemVo.setActStatus(1);
             // 关闭阶梯价格,活动优先
             cartItemVo.setLadderFlag(0);
+            cartItemVo.setPromotions(promotions);
         } else {
+            cartItemVo.setActStatus(0);
             if (cartItemVo.getLadderFlag() == 1) {
                 // 设置阶梯价
                 productService.setCartLadderPrices(cartItemVo, taxFlag);
@@ -982,80 +1008,30 @@ public class CartClubServiceImpl implements CartClubService {
                 // 复购价
                 Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), cartDto.getUserId());
                 if (null != repurchase && repurchase > 0) {
-                    cartItemVo.setPrice(repurchase);
+                    if (taxFlag) {
+                        BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                        cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                    } else {
+                        cartItemVo.setPrice(repurchase);
+                    }
                 }
             }
         }
-        // 店铺促销
-        if (null != shopPromotion) {
-            shop.setPromotions(shopPromotion);
-            // 店铺满赠
-            if (shopPromotion.getMode() == 3) {
-                // 获取赠品
-                List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
-                shopPromotion.setGiftList(giftList);
-            }
-            // 设置该优惠下的商品列表
-            List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
-            PromotionPriceVo promotionPrice = new PromotionPriceVo();
-            promotionPrice.setProductId(cartItemVo.getProductId());
-            promotionPrice.setNumber(cartItemVo.getNumber());
-            promotionPrice.setPrice(cartItemVo.getPrice());
-            promotionPriceList.add(promotionPrice);
-            shopPromotion.setProductList(promotionPriceList);
-            // 添加到总促销
-            totalPromotions.add(shopPromotion);
-            // 店铺满减-计算供应商总价/满减金额
-            if (shopPromotion.getMode() == 2 && MathUtil.compare(totalPrice[0], shopPromotion.getTouchPrice()) > -1) {
-                // 该供应商总价 - 满减金额
-                totalPrice[0] = MathUtil.sub(totalPrice[0], shopPromotion.getReducedPrice()).doubleValue();
-                // 该供应商优惠总额 + 满减金额
-                reducedPrice[0] = MathUtil.add(reducedPrice[0], shopPromotion.getReducedPrice()).doubleValue();
-            }
-        }
+        // 商品总金额累加
+        originalPrice.set(MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getOriginalPrice()).doubleValue());
+        totalPrice.set(MathUtil.add(totalPrice.get(), MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
         // 供应商商品
         List<CartItemVo> cartList = new ArrayList<>(1);
         cartList.add(cartItemVo);
         shop.setCartList(cartList);
         shop.setCount(1);
         // 供应商总价
-        shop.setTotalPrice(totalPrice[0]);
+        shop.setTotalPrice(totalPrice.get());
         // 供应商总优惠
-        shop.setReducedPrice(reducedPrice[0]);
+        shop.setReducedPrice(reducedPrice.get());
         // 供应商划线价
-        shop.setOriginalPrice(MathUtil.add(totalPrice[0], reducedPrice[0]).doubleValue());
-        List<CartShopVo> shopList = new ArrayList<>();
+        shop.setOriginalPrice(originalPrice.get());
         shopList.add(shop);
-        // 总促销计算
-        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) {
-                    // 总价 - 满减金额
-                    totalPrice[0] = MathUtil.sub(totalPrice[0], promotions.getReducedPrice()).doubleValue();
-                    // 优惠总额 + 满减金额
-                    reducedPrice[0] = MathUtil.add(reducedPrice[0], promotions.getReducedPrice()).doubleValue();
-                }
-            } else if (promotions.getMode() == 3) {
-                // 全部满赠
-                promotions.getGiftList().forEach(gift -> {
-                    if (shop.getShopId().equals(gift.getShopId())) {
-                        // 赠品在当前订单内的供应商下
-                        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);
-                    }
-                });
-            }
-        });
         // 是否充值商品
         boolean includeRecharge = false;
         boolean recharge = productService.isRechargeProduct(cartDto.getProductId());
@@ -1075,9 +1051,9 @@ public class CartClubServiceImpl implements CartClubService {
         resultData.put("list", shopList);
         resultData.put("kindCount", 1);
         resultData.put("totalCount", cartDto.getProductCount());
-        resultData.put("totalPrice", totalPrice[0]);
-        resultData.put("reducedPrice", reducedPrice[0]);
-        resultData.put("totalOriginalPrice", shop.getOriginalPrice());
+        resultData.put("totalPrice", totalPrice.get());
+        resultData.put("reducedPrice", reducedPrice.get());
+        resultData.put("totalOriginalPrice", originalPrice.get());
         resultData.put("invoice", invoice);
         resultData.put("userMoney", availableMoney);
         resultData.put("userBeans", userBeans);

+ 12 - 7
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -160,7 +160,12 @@ public class CartSellerServiceImpl implements CartSellerService {
                                 // 复购价
                                 Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), clubUserId);
                                 if (null != repurchase && repurchase > 0) {
-                                    cartItemVo.setPrice(repurchase);
+                                    if (taxFlag) {
+                                        BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                                        cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                                    } else {
+                                        cartItemVo.setPrice(repurchase);
+                                    }
                                 }
                             }
                         }
@@ -397,9 +402,6 @@ public class CartSellerServiceImpl implements CartSellerService {
         }
         // 获取机构用户Id
         Integer clubUserId = baseMapper.getUserIdByClubId(clubId);
-        // 超级会员标识
-        Integer svipUserId = baseMapper.getSvipUserIdByClubId(clubId);
-        boolean svipUserFlag = null != svipUserId;
         // 供应商列表
         List<CartShopVo> shopList = cartSellerMapper.getCartShopsByProductIds(serviceProviderId, clubId, productIdList);
         if (null != shopList && shopList.size()>0) {
@@ -410,8 +412,6 @@ public class CartSellerServiceImpl implements CartSellerService {
                 AtomicInteger shopKindCount = new AtomicInteger(0);
                 // 该供应商总价
                 AtomicDouble shopPrice = new AtomicDouble(0);
-                // 该供应商下参与店铺促销的商品总价
-                AtomicDouble shopPromotionPrice = new AtomicDouble(0);
                 // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
@@ -476,7 +476,12 @@ public class CartSellerServiceImpl implements CartSellerService {
                                     // 复购价
                                     Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), clubUserId);
                                     if (null != repurchase && repurchase > 0) {
-                                        cartItemVo.setPrice(repurchase);
+                                        if (taxFlag) {
+                                            BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
+                                            cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                                        } else {
+                                            cartItemVo.setPrice(repurchase);
+                                        }
                                     }
                                 }
                             }