Bladeren bron

计算运费bugfix

chao 3 jaren geleden
bovenliggende
commit
6c2435f6fd

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

@@ -174,7 +174,7 @@ public class ProductService {
         // 可用采美豆
         Integer userBeans = baseMapper.getUserBeans(userId);
         postageMap.put("userBeans", userBeans);
-        // 获取商品运费 (0包邮 1到付 2默认(遵循运费规则))
+        // 获取商品运费 (商品数据库 0包邮 1到付 2默认(遵循运费规则))
         List<ProductPostageVo> postageFlagList = baseMapper.getPostageFlagList(productIdList);
         if (null != postageFlagList && postageFlagList.size() > 0) {
             for (ProductPostageVo postageVo : postageFlagList){
@@ -186,8 +186,8 @@ public class ProductService {
                         postageMap.put("postageFlag", -1);
                         postageMap.put("postage", 0.00d);
                         return postageMap;
-                    } else if (null != postageVo.getPostageFlag() && 1==postageVo.getPostageFlag()) {
-                        // 若有不包邮商品,则全部不包邮
+                    } else if (null != postageVo.getPostageFlag() && 2==postageVo.getPostageFlag()) {
+                        // 若有不包邮商品,则全部不包邮(商品数据库:2默认(遵循运费规则),这里返回前端(按照订单数据库):1遵循运费规则)
                         postageFlag = 1;
                     }
                 }

+ 122 - 118
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -645,137 +645,139 @@ public class CartClubServiceImpl implements CartClubService {
             // 遍历供应商列表
             List<String> finalIdList = productIdList;
             shopList.forEach(shop -> {
-                // 该供应商下商品种类
-                AtomicInteger shopKindCount = new AtomicInteger(0);
-                // 该供应商总价
-                AtomicDouble shopPrice = new AtomicDouble(0);
-                // 该供应商满减金额(供应商满减,单品满减)
-                AtomicDouble shopReducedPrice = new AtomicDouble(0);
-                // 供应商促销优惠活动
-                PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
-                // 供应商下商品列表
-                List<CartItemVo> productList = cartClubMapper.getCartProductsByShopIdAndProductIds(userId, shop.getShopId(), finalIdList);
-                if (null != productList && productList.size()>0) {
-                    // 去除价格不可见商品
-                    productList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2)));
-                    // 去除库存不足商品
-                    productList.removeIf(cartItemVo -> !(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber()));
-                    // 迭代器设置商品信息
-                    for (CartItemVo cartItemVo : productList) {
-                        // 设置商品图片及税费
-                        boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
-                        // 是否充值商品
-                        boolean recharge = productService.isRechargeProduct(cartItemVo.getProductId());
-                        if (recharge) {
-                            includeRecharge.set(true);
-                        }
-                        // 获取商品促销信息
-                        PromotionsVo promotions = null;
-                        // 没有店铺促销时,商品促销才有效
-                        if (null == shopPromotion) {
+                if (null != shop) {
+                    // 该供应商下商品种类
+                    AtomicInteger shopKindCount = new AtomicInteger(0);
+                    // 该供应商总价
+                    AtomicDouble shopPrice = new AtomicDouble(0);
+                    // 该供应商满减金额(供应商满减,单品满减)
+                    AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                    // 供应商促销优惠活动
+                    PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
+                    // 供应商下商品列表
+                    List<CartItemVo> productList = cartClubMapper.getCartProductsByShopIdAndProductIds(userId, shop.getShopId(), finalIdList);
+                    if (null != productList && productList.size()>0) {
+                        // 去除价格不可见商品
+                        productList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2)));
+                        // 去除库存不足商品
+                        productList.removeIf(cartItemVo -> !(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber()));
+                        // 迭代器设置商品信息
+                        for (CartItemVo cartItemVo : productList) {
+                            // 设置商品图片及税费
+                            boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
+                            // 是否充值商品
+                            boolean recharge = productService.isRechargeProduct(cartItemVo.getProductId());
+                            if (recharge) {
+                                includeRecharge.set(true);
+                            }
                             // 获取商品促销信息
-                            promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
-                            /*
-                             * 设置商品促销优惠
-                             */
-                            if (null != promotions) {
-                                // 当前促销活动的价格计算列表
-                                List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
-                                // 更新到总促销列表
-                                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) {
-                                        // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
-                                        shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
-                                        shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
+                            PromotionsVo promotions = null;
+                            // 没有店铺促销时,商品促销才有效
+                            if (null == shopPromotion) {
+                                // 获取商品促销信息
+                                promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
+                                /*
+                                 * 设置商品促销优惠
+                                 */
+                                if (null != promotions) {
+                                    // 当前促销活动的价格计算列表
+                                    List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
+                                    // 更新到总促销列表
+                                    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) {
+                                            // 如果满足促销条件,设置供应商价格-满减金额,满减总额 + 当前促销满减金额
+                                            shopPrice.set(MathUtil.sub(shopPrice.get(), promotions.getReducedPrice()).doubleValue());
+                                            shopReducedPrice.set(MathUtil.add(shopReducedPrice, promotions.getReducedPrice()).doubleValue());
+                                        }
                                     }
+                                    cartItemVo.setPromotions(promotions);
                                 }
-                                cartItemVo.setPromotions(promotions);
                             }
-                        }
-                        if (null != promotions || null != shopPromotion) {
-                            // 商品处于活动状态
-                            cartItemVo.setActStatus(1);
-                            // 关闭阶梯价格,活动优先
-                            cartItemVo.setLadderFlag(0);
-                        } else {
-                            if (cartItemVo.getLadderFlag() == 1) {
-                                // 设置阶梯价
-                                productService.setCartLadderPrices(cartItemVo, taxFlag);
+                            if (null != promotions || null != shopPromotion) {
+                                // 商品处于活动状态
+                                cartItemVo.setActStatus(1);
+                                // 关闭阶梯价格,活动优先
+                                cartItemVo.setLadderFlag(0);
                             } else {
-                                // 复购价
-                                Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
-                                if (null != repurchase && repurchase > 0) {
-                                    cartItemVo.setPrice(repurchase);
+                                if (cartItemVo.getLadderFlag() == 1) {
+                                    // 设置阶梯价
+                                    productService.setCartLadderPrices(cartItemVo, taxFlag);
+                                } else {
+                                    // 复购价
+                                    Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
+                                    if (null != repurchase && repurchase > 0) {
+                                        cartItemVo.setPrice(repurchase);
+                                    }
                                 }
                             }
+                            // 该供应商下价格累加
+                            shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                            // 该供应商下商品种类 +1
+                            shopKindCount.incrementAndGet();
+                            // 总数量 + 当前商品购买数量
+                            totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
                         }
-                        // 该供应商下价格累加
-                        shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
-                        // 该供应商下商品种类 +1
-                        shopKindCount.incrementAndGet();
-                        // 总数量 + 当前商品购买数量
-                        totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
-                    }
-                    if (shopKindCount.get() > 0) {
-                        // 店铺促销
-                        if (null != shopPromotion) {
-                            shop.setPromotions(shopPromotion);
-                            if (!promotionsIds.contains(shopPromotion.getId())) {
-                                promotionsIds.add(shopPromotion.getId());
-                                // 店铺满赠
-                                if (shopPromotion.getMode() == 3) {
-                                    // 获取赠品
-                                    List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
-                                    shopPromotion.setGiftList(giftList);
-                                }
-                                // 设置该优惠下的商品列表
-                                List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
-                                productList.forEach(item -> {
-                                    PromotionPriceVo promotionPrice = new PromotionPriceVo();
-                                    promotionPrice.setProductId(item.getProductId());
-                                    promotionPrice.setNumber(item.getNumber());
-                                    promotionPrice.setPrice(item.getPrice());
-                                    promotionPriceList.add(promotionPrice);
-                                });
-                                shopPromotion.setProductList(promotionPriceList);
-                                // 添加到总促销
-                                totalPromotions.add(shopPromotion);
-                                // 店铺满减-计算供应商总价/满减金额
-                                if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPrice, shopPromotion.getTouchPrice()) > -1) {
-                                    // 该供应商总价 - 满减金额
-                                    shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
-                                    // 该供应商优惠总额 + 满减金额
-                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                        if (shopKindCount.get() > 0) {
+                            // 店铺促销
+                            if (null != shopPromotion) {
+                                shop.setPromotions(shopPromotion);
+                                if (!promotionsIds.contains(shopPromotion.getId())) {
+                                    promotionsIds.add(shopPromotion.getId());
+                                    // 店铺满赠
+                                    if (shopPromotion.getMode() == 3) {
+                                        // 获取赠品
+                                        List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
+                                        shopPromotion.setGiftList(giftList);
+                                    }
+                                    // 设置该优惠下的商品列表
+                                    List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
+                                    productList.forEach(item -> {
+                                        PromotionPriceVo promotionPrice = new PromotionPriceVo();
+                                        promotionPrice.setProductId(item.getProductId());
+                                        promotionPrice.setNumber(item.getNumber());
+                                        promotionPrice.setPrice(item.getPrice());
+                                        promotionPriceList.add(promotionPrice);
+                                    });
+                                    shopPromotion.setProductList(promotionPriceList);
+                                    // 添加到总促销
+                                    totalPromotions.add(shopPromotion);
+                                    // 店铺满减-计算供应商总价/满减金额
+                                    if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPrice, shopPromotion.getTouchPrice()) > -1) {
+                                        // 该供应商总价 - 满减金额
+                                        shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                        // 该供应商优惠总额 + 满减金额
+                                        shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                    }
                                 }
                             }
-                        }
-                        // 供应商商品
-                        shop.setCartList(productList);
-                        // 供应商总价
-                        shop.setTotalPrice(shopPrice.get());
-                        // 供应商总优惠
-                        shop.setReducedPrice(shopReducedPrice.get());
-                        // 供应商划线价
-                        shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                            // 供应商商品
+                            shop.setCartList(productList);
+                            // 供应商总价
+                            shop.setTotalPrice(shopPrice.get());
+                            // 供应商总优惠
+                            shop.setReducedPrice(shopReducedPrice.get());
+                            // 供应商划线价
+                            shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
 
-                        // 添加供应商Id集合
-                        shopIds.add(shop.getShopId());
-                        // 计算总价
-                        totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
-                        // 优惠总额
-                        reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
-                        // 总划线价
-                        totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
-                        // 商品种类
-                        kindCount.updateAndGet(v -> v + shopKindCount.get());
+                            // 添加供应商Id集合
+                            shopIds.add(shop.getShopId());
+                            // 计算总价
+                            totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
+                            // 优惠总额
+                            reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
+                            // 总划线价
+                            totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
+                            // 商品种类
+                            kindCount.updateAndGet(v -> v + shopKindCount.get());
+                        }
+                        totalProductList.addAll(productList);
                     }
-                    totalProductList.addAll(productList);
+                    // 供应商下商品种类
+                    shop.setCount(shopKindCount.get());
                 }
-                // 供应商下商品种类
-                shop.setCount(shopKindCount.get());
             });
             // 删除空数据
             shopList.removeIf(shop -> (null == shop || shop.getCount() == 0));
@@ -915,6 +917,8 @@ public class CartClubServiceImpl implements CartClubService {
             cart.setUserId(cartDto.getUserId());
             cart.setProductId(cartDto.getProductId());
             cart.setProductCount(cartDto.getProductCount());
+            Integer shopId = baseMapper.getShopIdByproductId(cartDto.getProductId());
+            cart.setShopId(shopId);
             //判断是否是再次购买
             Double repurchase = baseMapper.getRepurchasePrice(cartDto.getProductId(), cartDto.getUserId());
             if (null != repurchase && repurchase > 0) {