Sfoglia il codice sorgente

提交订单/统计超级会员优惠

Aslee 3 anni fa
parent
commit
4fdc4d4bc9

+ 4 - 0
src/main/java/com/caimei365/order/model/vo/CartShopVo.java

@@ -34,6 +34,10 @@ public class CartShopVo implements Serializable {
      * 减免价格
      */
     private Double reducedPrice;
+    /**
+     * 超级会员优惠
+     */
+    private Double svipReducedPrice;
     /**
      * 划线价格
      */

+ 27 - 10
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -70,6 +70,8 @@ public class CartClubServiceImpl implements CartClubService {
         AtomicDouble totalPrice = new AtomicDouble(0);
         // 统计总促销满减
         AtomicDouble reducedPrice = new AtomicDouble(0);
+        // 统计总超级会员优惠
+        AtomicDouble svipReducedPrice = new AtomicDouble(0);
         // 统计总划线价
         AtomicDouble totalOriginalPrice = new AtomicDouble(0);
         /*
@@ -99,8 +101,10 @@ public class CartClubServiceImpl implements CartClubService {
                 AtomicDouble shopPrice = new AtomicDouble(0);
                 // 该供应商下可参与店铺促销的商品总价
                 AtomicDouble shopPromotionFee = new AtomicDouble(0);
-                // 该供应商满减金额(svip优惠,供应商满减,单品满减)
+                // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                // 该供应商svip优惠金额
+                AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                 // 供应商下商品列表
@@ -128,9 +132,8 @@ public class CartClubServiceImpl implements CartClubService {
                                 // 超级会员设置商品优惠价
                                 productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
                                 if (svipUserFlag) {
-                                    // 超级会员设置供应商价格-商品优惠金额,店铺优惠总额 + 商品优惠金额
-                                    shopPrice.set(MathUtil.sub(shopPrice.get(), cartItemVo.getSvipTotalReducedPrice()).doubleValue());
-                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
+                                    // 超级会员设置超级会员优惠总额 + 商品优惠金额
+                                    shopSvipReducedPrice.set(MathUtil.add(shopSvipReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
                                 }
                             } else {
                                 // 获取商品促销信息
@@ -278,10 +281,14 @@ public class CartClubServiceImpl implements CartClubService {
                     shop.setCartList(productList);
                     // 供应商总价
                     shop.setTotalPrice(shopPrice.get());
+                    // 当有超级会员优惠时,取超级会员优惠
+                    Double shopReduction = MathUtil.compare(shopSvipReducedPrice, 0) > 0 ? shopSvipReducedPrice.get() : shopReducedPrice.get();
                     // 供应商总优惠
                     shop.setReducedPrice(shopReducedPrice.get());
+                    // 供应商总超级会员优惠
+                    shop.setSvipReducedPrice(shopSvipReducedPrice.get());
                     // 供应商划线价
-                    shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                    shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReduction).doubleValue());
                     // 计算总价
                     totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
                     // 优惠总额
@@ -652,6 +659,8 @@ public class CartClubServiceImpl implements CartClubService {
         AtomicDouble totalPrice = new AtomicDouble(0);
         // 统计总促销满减
         AtomicDouble reducedPrice = new AtomicDouble(0);
+        // 统计总超级会员优惠
+        AtomicDouble svipReducedPrice = new AtomicDouble(0);
         // 统计总划线价
         AtomicDouble totalOriginalPrice = new AtomicDouble(0);
         // 促销活动(总)
@@ -691,8 +700,10 @@ public class CartClubServiceImpl implements CartClubService {
                     AtomicDouble shopPrice = new AtomicDouble(0);
                     // 该供应商下参与店铺促销的商品总价
                     AtomicDouble shopPromotionFee = new AtomicDouble(0);
-                    // 该供应商满减金额(svip优惠,供应商满减,单品满减)
+                    // 该供应商满减金额(供应商满减,单品满减)
                     AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                    // 该供应商svip优惠金额
+                    AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                     // 供应商促销优惠活动
                     PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                     // 供应商下商品列表
@@ -716,9 +727,8 @@ public class CartClubServiceImpl implements CartClubService {
                                 // 超级会员设置商品优惠价
                                 productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
                                 if (svipUserFlag) {
-                                    // 超级会员设置供应商价格-商品优惠金额,店铺优惠总额 + 商品优惠金额
-                                    shopPrice.set(MathUtil.sub(shopPrice.get(), cartItemVo.getSvipTotalReducedPrice()).doubleValue());
-                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
+                                    // 超级会员设置超级会员优惠总额 + 商品优惠金额
+                                    shopSvipReducedPrice.set(MathUtil.add(shopSvipReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
                                 }
                             } else {
                                 // 获取商品促销信息
@@ -822,10 +832,14 @@ public class CartClubServiceImpl implements CartClubService {
                             shop.setCartList(productList);
                             // 供应商总价
                             shop.setTotalPrice(shopPrice.get());
+                            // 当有超级会员优惠时,取超级会员优惠
+                            Double shopReduction = MathUtil.compare(shopSvipReducedPrice, 0) > 0 ? shopSvipReducedPrice.get() : shopReducedPrice.get();
                             // 供应商总优惠
                             shop.setReducedPrice(shopReducedPrice.get());
+                            // 供应商总超级会员优惠
+                            shop.setSvipReducedPrice(shopSvipReducedPrice.get());
                             // 供应商划线价
-                            shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                            shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReduction).doubleValue());
 
                             // 添加供应商Id集合
                             shopIds.add(shop.getShopId());
@@ -833,6 +847,8 @@ public class CartClubServiceImpl implements CartClubService {
                             totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
                             // 优惠总额
                             reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
+                            // 超级会员优惠总额
+                            svipReducedPrice.set(MathUtil.add(svipReducedPrice, shop.getSvipReducedPrice()).doubleValue());
                             // 总划线价
                             totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
                             // 商品种类
@@ -898,6 +914,7 @@ public class CartClubServiceImpl implements CartClubService {
         resultData.put("totalCount", totalCount);
         resultData.put("totalPrice", totalPrice);
         resultData.put("reducedPrice", reducedPrice);
+        resultData.put("svipReducedPrice", svipReducedPrice);
         resultData.put("totalOriginalPrice", totalOriginalPrice);
         resultData.put("promotions", totalPromotions);
         resultData.put("invoice", invoice);

+ 76 - 45
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -82,6 +82,9 @@ public class CartSellerServiceImpl implements CartSellerService {
         List<Integer> promotionsIds = new ArrayList<>();
         // 获取机构用户Id
         Integer clubUserId = baseMapper.getUserIdByClubId(clubId);
+        // 超级会员标识
+        Integer svipUserId = baseMapper.getSvipUserIdByClubId(clubId);
+        boolean svipUserFlag = null != svipUserId;
         // 开始分页请求供应商数据
         PageHelper.startPage(pageNum, pageSize);
         // 协销购物车供应商列表
@@ -96,8 +99,12 @@ public class CartSellerServiceImpl implements CartSellerService {
                 AtomicInteger shopKindCount = new AtomicInteger(0);
                 // 该供应商总价
                 AtomicDouble shopPrice = new AtomicDouble(0);
-                // 该供应商满减金额(svip优惠,供应商满减,单品满减)
+                // 该供应商下参与店铺促销的商品总价
+                AtomicDouble shopPromotionFee = new AtomicDouble(0);
+                // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                // 该供应商svip优惠金额
+                AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                 // 供应商下商品列表
@@ -121,50 +128,60 @@ public class CartSellerServiceImpl implements CartSellerService {
                         cartItemVo.setStatus(0);
                         // 设置商品图片及税费
                         boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
-                        // 获取商品促销信息
-                        PromotionsVo promotions = null;
-                        // 没有店铺促销时,商品促销才有效
-                        if (null == shopPromotion) {
+                        if (1 == cartItemVo.getSvipProductFlag()) {
+                            // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
+                            // 超级会员设置商品优惠价
+                            productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
+                            if (svipUserFlag) {
+                                // 超级会员设置超级会员优惠总额 + 商品优惠金额
+                                shopReducedPrice.set(MathUtil.add(shopReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
+                            }
+                        } else {
                             // 获取商品促销信息
-                            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(), clubUserId);
-                                if (null != repurchase && repurchase > 0) {
-                                    if (taxFlag) {
-                                        BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(repurchase, cartItemVo.getTaxRate()), 100, 2);
-                                        cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
-                                    } else {
-                                        cartItemVo.setPrice(repurchase);
+                                if (cartItemVo.getLadderFlag() == 1) {
+                                    // 设置阶梯价
+                                    productService.setCartLadderPrices(cartItemVo, taxFlag);
+                                } else {
+                                    // 复购价
+                                    Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), clubUserId);
+                                    if (null != repurchase && repurchase > 0) {
+                                        if (taxFlag) {
+                                            BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(repurchase, cartItemVo.getTaxRate()), 100, 2);
+                                            cartItemVo.setPrice(MathUtil.add(repurchase, cartItemTax).doubleValue());
+                                        } else {
+                                            cartItemVo.setPrice(repurchase);
+                                        }
                                     }
                                 }
                             }
@@ -175,6 +192,11 @@ public class CartSellerServiceImpl implements CartSellerService {
                         }
                         // 该供应商下价格累加
                         shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        // 该供应商下可参与店铺促销的商品价格累加
+                        if (!(1 == cartItemVo.getSvipProductFlag() && svipUserFlag)) {
+                            // 超级会员购买svip商品不享受店铺促销优惠
+                            shopPromotionFee.set(MathUtil.add(shopPromotionFee, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        }
                         // 该供应商下商品种类 +1
                         shopKindCount.incrementAndGet();
                     }
@@ -215,10 +237,14 @@ public class CartSellerServiceImpl implements CartSellerService {
                 shop.setCartList(productList);
                 // 供应商总价
                 shop.setTotalPrice(shopPrice.get());
+                // 当有超级会员优惠时,取超级会员优惠
+                Double shopReduction = MathUtil.compare(shopSvipReducedPrice, 0) > 0 ? shopSvipReducedPrice.get() : shopReducedPrice.get();
                 // 供应商总优惠
                 shop.setReducedPrice(shopReducedPrice.get());
+                // 供应商总超级会员优惠
+                shop.setSvipReducedPrice(shopSvipReducedPrice.get());
                 // 供应商划线价
-                shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReduction).doubleValue());
                 // 供应商下商品种类
                 shop.setCount(shopKindCount.get());
             });
@@ -417,8 +443,10 @@ public class CartSellerServiceImpl implements CartSellerService {
                 AtomicDouble shopPrice = new AtomicDouble(0);
                 // 该供应商下参与店铺促销的商品总价
                 AtomicDouble shopPromotionFee = new AtomicDouble(0);
-                // 该供应商满减金额(svip优惠,供应商满减,单品满减)
+                // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                // 该供应商svip优惠金额
+                AtomicDouble shopSvipReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
                 PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                 // 供应商下商品列表
@@ -437,8 +465,7 @@ public class CartSellerServiceImpl implements CartSellerService {
                             // 超级会员设置商品优惠价
                             productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
                             if (svipUserFlag) {
-                                // 超级会员设置供应商价格-商品优惠金额,店铺优惠总额 + 商品优惠金额
-                                shopPrice.set(MathUtil.sub(shopPrice.get(), cartItemVo.getSvipTotalReducedPrice()).doubleValue());
+                                // 超级会员设置超级会员优惠总额 + 商品优惠金额
                                 shopReducedPrice.set(MathUtil.add(shopReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
                             }
                         } else{
@@ -543,10 +570,14 @@ public class CartSellerServiceImpl implements CartSellerService {
                         shop.setCartList(productList);
                         // 供应商总价
                         shop.setTotalPrice(shopPrice.get());
+                        // 当有超级会员优惠时,取超级会员优惠
+                        Double shopReduction = MathUtil.compare(shopSvipReducedPrice, 0) > 0 ? shopSvipReducedPrice.get() : shopReducedPrice.get();
                         // 供应商总优惠
                         shop.setReducedPrice(shopReducedPrice.get());
+                        // 供应商总超级会员优惠
+                        shop.setSvipReducedPrice(shopSvipReducedPrice.get());
                         // 供应商划线价
-                        shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+                        shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReduction).doubleValue());
 
                         // 添加供应商Id集合
                         shopIds.add(shop.getShopId());

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

@@ -520,7 +520,7 @@ public class SubmitServiceImpl implements SubmitService {
                             // 保存订单商品svip数据
                             product.setSvipProductFlag(1);
                             product.setSvipPriceType(svipProductPo.getSvipPriceType());
-                            product.setSvipDiscount(1 == svipProductPo.getSvipPriceType() ? svipProductPo.getSvipDiscount() : null);
+                            product.setSvipDiscount(1 == svipProductPo.getSvipPriceType() ? svipProductPo.getSvipDiscount() : 0.00d);
                         }
                     } else if (promotions != null) {
                         // 是否包含活动商品(受订单未支付自动关闭时间影响)  0 否 1 是

+ 2 - 2
src/main/resources/backup.sql

@@ -2,9 +2,9 @@
 ALTER TABLE `caimei`.`cm_order`
     ADD COLUMN `svipFullReduction` DECIMAL(15,2) NULL COMMENT '订单超级会员优惠' DEFAULT 0.00 AFTER `couponAmount`;
 ALTER TABLE `caimei`.`cm_shop_order`
-    ADD COLUMN `svipShopReduction` VARCHAR(45) NULL COMMENT '店铺超级会员优惠' AFTER `differencePrice`;
+    ADD COLUMN `svipShopReduction` DECIMAL(15,2) NULL COMMENT '店铺超级会员优惠' DEFAULT 0.00 AFTER `differencePrice`;
 ALTER TABLE `caimei`.`cm_order_product`
     ADD COLUMN `svipProductFlag` INT NULL DEFAULT 0 COMMENT '超级会员优惠商品标识:0不是,1是' AFTER `heUserId`,
-    ADD COLUMN `svipPriceFlag` INT NULL DEFAULT NULL COMMENT '超级会员优惠价类型:1折扣价,2直接优惠价' AFTER `svipProductFlag`,
+    ADD COLUMN `svipPriceType` INT NULL DEFAULT NULL COMMENT '超级会员优惠价类型:1折扣价,2直接优惠价' AFTER `svipProductFlag`,
     ADD COLUMN `svipDiscount` DECIMAL(20,2) NULL DEFAULT '0.00' COMMENT '超级会员折扣' AFTER `svipPriceFlag`;
 -- =================================== 2021年9月 超级会员S_VIP end =====================================

+ 1 - 1
src/main/resources/mapper/OrderCommonMapper.xml

@@ -104,7 +104,7 @@
         cop.isActProduct AS actProduct,
         cop.productType,
         cop.svipProductFlag,
-        cop.svipPriceFlag,
+        cop.svipPriceType,
         cop.svipDiscount,
         p.productCategory as productCategory
         FROM cm_order_product cop

+ 2 - 2
src/main/resources/mapper/SubmitMapper.xml

@@ -33,14 +33,14 @@
                                     totalAmount, totalFee, shouldPayFee, productUnit, num, presentNum, discountFee, includedTax,
                                     invoiceType, taxRate, addedValueTax, totalAddedValueTax, singleShouldPayTotalTax, shouldPayTotalTax,
                                     shopProductAmount, singleShopFee, shopFee, singleOtherFee, otherFee, singleCmFee, cmFee,
-                                    payStatus, buyAgainFlag, notOutStore, isActProduct, productType, svipProductFlag,svipPriceFlag,
+                                    payStatus, buyAgainFlag, notOutStore, isActProduct, productType, svipProductFlag,svipPriceType,
                                       svipDiscount)
         VALUES (#{orderId},#{orderNo},#{shopOrderId},#{shopOrderNo},#{orderPromotionsId},#{productId},#{shopId},#{name},
                 #{image},#{price},#{price},#{shopName},#{costPrice},#{normalPrice},#{ladderPriceFlag},#{discountPrice},#{discount},
                 #{totalAmount},#{totalFee},#{shouldPayFee},#{productUnit},#{num},#{presentNum},#{discountFee},#{includedTax},
                 #{invoiceType},#{taxRate},#{addedValueTax},#{totalAddedValueTax},#{singleShouldPayTotalTax},#{shouldPayTotalTax},
                 #{shopProductAmount},#{singleShopFee},#{shopFee},#{singleOtherFee},#{otherFee},#{singleCmFee},#{cmFee},
-                #{payStatus},#{buyAgainFlag},#{notOutStore},#{actProduct},#{productType},#{svipProductFlag},#{svipPriceFlag},#{svipDiscount})
+                #{payStatus},#{buyAgainFlag},#{notOutStore},#{actProduct},#{productType},#{svipProductFlag},#{svipPriceType},#{svipDiscount})
     </insert>
     <insert id="insertOrderPromotions" keyColumn="id" keyProperty="id" parameterType="com.caimei365.order.model.vo.PromotionsVo" useGeneratedKeys="true">
         INSERT INTO cm_promotions_order (orderId, promotionsId, name, description, type, mode, touchPrice, reducedPrice, status, beginTime, endTime)