Explorar el Código

会员订单提交

Aslee hace 3 años
padre
commit
d22ca5359e

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

@@ -92,7 +92,7 @@ public class OrderCommonService {
                     }
                 }
                 // 超级会员优惠商品设置优惠标签
-                if (1 == orderProduct.getSvipProductFlag()) {
+                if (null != orderProduct.getSvipPriceFlag() && 1 == orderProduct.getSvipPriceFlag()) {
                     if (1 == orderProduct.getSvipPriceType()) {
                         orderProduct.setSvipPriceTag(MathUtil.div(orderProduct.getSvipDiscount(), 10, 1) + "折");
                     } else if (2 == orderProduct.getSvipPriceType()){

+ 2 - 2
src/main/java/com/caimei365/order/model/po/OrderProductPo.java

@@ -209,9 +209,9 @@ public class OrderProductPo implements Serializable {
      */
     private Integer orderPromotionsId;
     /**
-     * 超级会员优惠商品标识:0不是,1是
+     * 超级会员优惠价格标识:0不是,1是
      */
-    private Integer svipProductFlag;
+    private Integer svipPriceFlag;
     /**
      * 超级会员优惠价类型:1折扣价,2直接优惠价
      */

+ 2 - 2
src/main/java/com/caimei365/order/model/vo/OrderProductVo.java

@@ -229,9 +229,9 @@ public class OrderProductVo implements Serializable {
      */
     private Integer includedTaxFlag;
     /**
-     * 超级会员优惠商品标识:0不是,1是
+     * 超级会员优惠价格标识:0不是,1是
      */
-    private Integer svipProductFlag;
+    private Integer svipPriceFlag;
     /**
      * 超级会员优惠价类型:1折扣价,2直接优惠价
      */

+ 82 - 64
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -951,6 +951,9 @@ public class CartClubServiceImpl implements CartClubService {
         }
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(cartDto.getUserId());
+        // 超级会员标识
+        Integer svipUserId = baseMapper.getSvipUserIdByUserId(cartDto.getUserId());
+        boolean svipUserFlag = null != svipUserId;
         // 价格不可见商品
         if (!(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2))) {
             return ResponseJson.error("商品价格不可见!", null);
@@ -973,76 +976,88 @@ public class CartClubServiceImpl implements CartClubService {
         AtomicDouble totalPrice = new AtomicDouble(0);
         // 统计总促销满减
         AtomicDouble reducedPrice = new AtomicDouble(0);
+        // svip优惠金额
+        AtomicDouble svipReducedPrice = new AtomicDouble(0);
 
         // 供应商促销优惠活动
         PromotionsVo promotions = baseMapper.getPromotionByShopId(shop.getShopId());
-        // 没有店铺促销时,商品促销才有效
-        if (null == promotions) {
-            // 获取商品促销信息
-            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 (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 (shopIds.contains(gift.getShopId())) {
-                            // 赠品在当前订单内的供应商下
-                            shopList.forEach(s -> {
-                                if (s.getShopId().equals(gift.getShopId())) {
-                                    s.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);
-                        }
-                    });
-                    promotions.setGiftList(giftList);
-                }
+        if (1 == cartItemVo.getSvipProductFlag()) {
+            // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
+            // 超级会员设置商品优惠价
+            productService.setSvipProductPrice(cartItemVo, taxFlag, svipUserFlag);
+            if (svipUserFlag) {
+                // 超级会员设置超级会员优惠总额 + 商品优惠金额
+                svipReducedPrice.set(MathUtil.add(svipReducedPrice, cartItemVo.getSvipTotalReducedPrice()).doubleValue());
             }
-            // 添加到总促销
-            totalPromotions.add(promotions);
-            // 商品处于活动状态
-            cartItemVo.setActStatus(1);
-            // 关闭阶梯价格,活动优先
-            cartItemVo.setLadderFlag(0);
-            cartItemVo.setPromotions(promotions);
         } else {
-            cartItemVo.setActStatus(0);
-            if (cartItemVo.getLadderFlag() == 1) {
-                // 设置阶梯价
-                productService.setCartLadderPrices(cartItemVo, taxFlag);
+            // 没有店铺促销时,商品促销才有效
+            if (null == promotions) {
+                // 获取商品促销信息
+                promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
             } else {
-                // 复购价
-                Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), cartDto.getUserId());
-                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);
+                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 (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 (shopIds.contains(gift.getShopId())) {
+                                // 赠品在当前订单内的供应商下
+                                shopList.forEach(s -> {
+                                    if (s.getShopId().equals(gift.getShopId())) {
+                                        s.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);
+                            }
+                        });
+                        promotions.setGiftList(giftList);
+                    }
+                }
+                // 添加到总促销
+                totalPromotions.add(promotions);
+                // 商品处于活动状态
+                cartItemVo.setActStatus(1);
+                // 关闭阶梯价格,活动优先
+                cartItemVo.setLadderFlag(0);
+                cartItemVo.setPromotions(promotions);
+            } else {
+                cartItemVo.setActStatus(0);
+                if (cartItemVo.getLadderFlag() == 1) {
+                    // 设置阶梯价
+                    productService.setCartLadderPrices(cartItemVo, taxFlag);
+                } else {
+                    // 复购价
+                    Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), cartDto.getUserId());
+                    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);
+                        }
                     }
                 }
             }
@@ -1061,6 +1076,8 @@ public class CartClubServiceImpl implements CartClubService {
         shop.setReducedPrice(reducedPrice.get());
         // 供应商划线价
         shop.setOriginalPrice(originalPrice.get());
+        // svip优惠金额
+        shop.setSvipReducedPrice(svipReducedPrice.get());
         // 当前供应商添加到首位
         shopList.add(0, shop);
 
@@ -1085,6 +1102,7 @@ public class CartClubServiceImpl implements CartClubService {
         resultData.put("totalCount", cartDto.getProductCount());
         resultData.put("totalPrice", totalPrice.get());
         resultData.put("reducedPrice", reducedPrice.get());
+        resultData.put("svipReducedPrice", svipReducedPrice.get());
         resultData.put("totalOriginalPrice", originalPrice.get());
         resultData.put("invoice", invoice);
         resultData.put("userMoney", availableMoney);

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

@@ -474,8 +474,11 @@ public class SubmitServiceImpl implements SubmitService {
                 product.setNum(productNum);
                 product.setPresentNum(presentNum);
                 product.setProductType(productType);
+                product.setSvipPriceFlag(0);
                 // 超级会员优惠商品详情
                 SvipProductPo svipProductPo = submitMapper.getSvipProductDetails(productId);
+                // 是否以超级会员优惠价格购买
+                boolean svipPriceFlag = null != svipProductPo && 1 == svipProductPo.getSvipProductFlag() || orderParamBo.getSvipUserFlag();
                 // 是否是促销赠品
                 if (productType == 2) {
                     // 促销赠品数+1
@@ -518,7 +521,7 @@ public class SubmitServiceImpl implements SubmitService {
                             svipShopReduction.set(MathUtil.add(svipShopReduction, reductionFee).doubleValue());
                             svipFullReduction.set(MathUtil.add(svipFullReduction, reductionFee).doubleValue());
                             // 保存订单商品svip数据
-                            product.setSvipProductFlag(1);
+                            product.setSvipPriceFlag(1);
                             product.setSvipPriceType(svipProductPo.getSvipPriceType());
                             product.setSvipDiscount(1 == svipProductPo.getSvipPriceType() ? svipProductPo.getSvipDiscount() : 0.00d);
                         }
@@ -692,8 +695,7 @@ public class SubmitServiceImpl implements SubmitService {
                 // 统计 总金额 包括税费
                 shopProductFee.set(MathUtil.add(shopProductFee.get(), product.getTotalFee()).doubleValue());
                 // 统计子订单内可参与店铺促销的商品总金额
-                boolean buySvipProductFlag = null != svipProductPo && 1 == svipProductPo.getSvipProductFlag() || orderParamBo.getSvipUserFlag();
-                if (!buySvipProductFlag) {
+                if (!svipPriceFlag) {
                     // 超级会员购买优惠商品,不能参与店铺促销
                     shopPromotionFee.set(MathUtil.add(shopPromotionFee.get(), product.getTotalFee()).doubleValue());
                 }

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

@@ -4,7 +4,7 @@ ALTER TABLE `caimei`.`cm_order`
 ALTER TABLE `caimei`.`cm_shop_order`
     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 0 COMMENT '超级会员优惠价格标识:0不是,1是' AFTER `heUserId`,
     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 =====================================

+ 6 - 1
src/main/resources/mapper/CartClubMapper.xml

@@ -199,8 +199,13 @@
         p.invoiceType AS invoiceType,
         p.taxPoint AS taxRate,
         p.productCategory,
-        p.validFlag AS validFlag
+        p.validFlag AS validFlag,
+        if(csp.id is not null,1,0) as svipProductFlag,
+        csp.priceType as svipPriceType,
+        csp.discount as svipDiscount,
+        csp.discountPrice as svipDiscountPrice
         FROM product p
+        LEFT JOIN cm_svip_product csp ON p.productID = csp.productId
         WHERE p.validFlag='2' AND p.productID = #{productId}
     </select>
 </mapper>

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

@@ -103,7 +103,7 @@
         cop.notOutStore,
         cop.isActProduct AS actProduct,
         cop.productType,
-        cop.svipProductFlag,
+        cop.svipPriceFlag,
         cop.svipPriceType,
         cop.svipDiscount,
         p.productCategory as productCategory

+ 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,svipPriceType,
+                                    payStatus, buyAgainFlag, notOutStore, isActProduct, productType, svipPriceFlag,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},#{svipPriceType},#{svipDiscount})
+                #{payStatus},#{buyAgainFlag},#{notOutStore},#{actProduct},#{productType},#{svipPriceFlag},#{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)