Bläddra i källkod

svip商品购买

Aslee 3 år sedan
förälder
incheckning
0fd290b69e

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

@@ -44,7 +44,9 @@ public class ProductService {
         boolean taxFlag = (Integer.valueOf(0).equals(cartItemVo.getIncludedTax()) && (Integer.valueOf(1).equals(cartItemVo.getInvoiceType()) || Integer.valueOf(2).equals(cartItemVo.getInvoiceType())));
         if (taxFlag) {
             BigDecimal cartItemTax = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getTaxRate()), 100, 2);
-            cartItemVo.setPrice(MathUtil.add(cartItemVo.getPrice(), cartItemTax).doubleValue());
+            double price = MathUtil.add(cartItemVo.getPrice(), cartItemTax).doubleValue();
+            cartItemVo.setPrice(price);
+            cartItemVo.setOriginalPrice(price);
         }
         return taxFlag;
     }
@@ -348,4 +350,36 @@ public class ProductService {
         baseMapper.updateUserBeans(beansHistory.getUserId(), userBeans);
         log.info(note + ">>>>>更新用户采美豆(update[user(userBeans:"+ userBeans +")]),userId:" + beansHistory.getUserId());
     }
+
+    /**
+     * 设置超级会员优惠商品价格
+     * @param cartItemVo    当前购物车商品
+     * @param taxFlag       计算税费标志
+     * @param svipUserFlag
+     */
+    public void setSvipProductPrice(CartItemVo cartItemVo, boolean taxFlag, boolean svipUserFlag) {
+        Integer svipPriceType = cartItemVo.getSvipPriceType();
+        BigDecimal discountPrice = BigDecimal.ZERO;
+        if (1 == svipPriceType) {
+            // 折扣价
+            cartItemVo.setSvipPriceTag(MathUtil.div(cartItemVo.getSvipDiscount(), 10, 1) + "折");
+            // 设置折扣价(原价格已计算税费,无需重复计算)
+            discountPrice = MathUtil.div(MathUtil.mul(cartItemVo.getPrice(), cartItemVo.getSvipDiscount()), 100, 2);
+        } else if (2 == svipPriceType) {
+            // 直接优惠价
+            discountPrice = cartItemVo.getSvipDiscountPrice();
+            if (taxFlag) {
+                //添加税费
+                BigDecimal thisTaxFee = MathUtil.div(MathUtil.mul(discountPrice, cartItemVo.getTaxRate()), 100, 2);
+                discountPrice = MathUtil.add(discountPrice, thisTaxFee).setScale(2, BigDecimal.ROUND_HALF_UP);
+            }
+            cartItemVo.setSvipPriceTag("¥" + discountPrice);
+        }
+        if (svipUserFlag) {
+            // 超级会员设置优惠价
+            cartItemVo.setPrice(discountPrice.doubleValue());
+            // 设置优惠金额=(商品原价-折扣价)*商品数量
+            cartItemVo.setSvipTotalReducedPrice(MathUtil.mul(MathUtil.sub(cartItemVo.getOriginalPrice(), discountPrice), cartItemVo.getNumber()));
+        }
+    }
 }

+ 13 - 0
src/main/java/com/caimei365/order/mapper/BaseMapper.java

@@ -168,4 +168,17 @@ public interface BaseMapper {
      * 获取条款列表
      */
     List<ClauseVo> getClauseList();
+    /**
+     * 查询超级会员用户id
+     * @param userId    用户id
+     * @return
+     */
+    Integer getSvipUserIdByUserId(Integer userId);
+
+    /**
+     * 查询超级会员用户id
+     * @param clubId    机构id
+     * @return
+     */
+    Integer getSvipUserIdByClubId(Integer clubId);
 }

+ 6 - 1
src/main/java/com/caimei365/order/mapper/SubmitMapper.java

@@ -3,7 +3,6 @@ package com.caimei365.order.mapper;
 import com.caimei365.order.model.bo.OrderParamBo;
 import com.caimei365.order.model.po.*;
 import com.caimei365.order.model.vo.AddressVo;
-import com.caimei365.order.model.vo.CouponVo;
 import com.caimei365.order.model.vo.LadderPriceVo;
 import com.caimei365.order.model.vo.PromotionsVo;
 import org.apache.ibatis.annotations.Mapper;
@@ -97,4 +96,10 @@ public interface SubmitMapper {
      * 保存订单优惠记录
      */
     void insertCouponOrderRecord(CouponOrderRecordPo orderRecord);
+    /**
+     * 获取超级会员优惠商品详情
+     * @param productId 商品id
+     * @return
+     */
+    SvipProductPo getSvipProductDetails(Integer productId);
 }

+ 4 - 0
src/main/java/com/caimei365/order/model/bo/OrderParamBo.java

@@ -109,4 +109,8 @@ public class OrderParamBo implements Serializable {
      * 优惠券Id
      */
     private Integer clubCouponId;
+    /**
+     * 超级会员用户标记
+     */
+    private Boolean svipUserFlag;
 }

+ 33 - 0
src/main/java/com/caimei365/order/model/po/SvipProductPo.java

@@ -0,0 +1,33 @@
+package com.caimei365.order.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * 超级会员优惠商品
+ *
+ * @author : Aslee
+ * @date : 2021/9/28
+ */
+@Data
+public class SvipProductPo implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 超级会员优惠商品标识:0不是,1是
+     */
+    private Integer svipProductFlag;
+    /**
+     * 超级会员优惠价类型:1折扣价,2直接优惠价
+     */
+    private Integer svipPriceType;
+    /**
+     * 超级会员折扣
+     */
+    private BigDecimal svipDiscount;
+    /**
+     * 超级会员优惠价
+     */
+    private BigDecimal svipDiscountPrice;
+}

+ 25 - 0
src/main/java/com/caimei365/order/model/vo/CartItemVo.java

@@ -3,6 +3,7 @@ package com.caimei365.order.model.vo;
 import lombok.Data;
 
 import java.io.Serializable;
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -122,4 +123,28 @@ public class CartItemVo implements Serializable {
      * 商品属性:1产品,2仪器
      */
     private Integer commodityType;
+    /**
+     * 超级会员优惠商品标识:0不是,1是
+     */
+    private Integer svipProductFlag;
+    /**
+     * 超级会员优惠价类型:1折扣价,2直接优惠价
+     */
+    private Integer svipPriceType;
+    /**
+     * 超级会员折扣
+     */
+    private BigDecimal svipDiscount;
+    /**
+     * 超级会员优惠价
+     */
+    private BigDecimal svipDiscountPrice;
+    /**
+     * 超级会员价格标签
+     */
+    private String svipPriceTag;
+    /**
+     * 购物车该商品总优惠金额
+     */
+    private BigDecimal svipTotalReducedPrice;
 }

+ 131 - 83
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -83,6 +83,9 @@ public class CartClubServiceImpl implements CartClubService {
         List<CartItemVo> cartAllProducts = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
+        // 超级会员标识
+        Integer svipUserId = baseMapper.getSvipUserIdByUserId(userId);
+        boolean svipUserFlag = null != svipUserId;
         if (null != shopInfoList && shopInfoList.size()>0) {
             // 删除空数据
             shopInfoList.removeIf(Objects::isNull);
@@ -94,6 +97,8 @@ public class CartClubServiceImpl implements CartClubService {
                 AtomicInteger shopKindCount = new AtomicInteger(0);
                 // 该供应商总价
                 AtomicDouble shopPrice = new AtomicDouble(0);
+                // 该供应商下可参与店铺促销的商品总价
+                AtomicDouble shopPromotionPrice = new AtomicDouble(0);
                 // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
@@ -114,55 +119,71 @@ public class CartClubServiceImpl implements CartClubService {
                         // 默认所有商品未选中状态(前端要求)
                         cartItemVo.setIsChecked(false);
                         // 价格是否可见
-                        boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2));
+                        boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2) || svipUserFlag);
                         // 是否库存充足
                         boolean isStocked = (cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber());
                         if (priceVisible && isStocked) {
-                            // 获取商品促销信息
-                            PromotionsVo promotions = null;
-                            // 没有店铺促销时,商品促销才有效
-                            if (null == shopPromotion) {
+                            if (1 == cartItemVo.getSvipProductFlag()) {
+                                // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
+                                // 超级会员设置商品优惠价
+                                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 {
                                 // 获取商品促销信息
-                                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());
+                            // 该供应商下可参与店铺促销的商品价格累加
+                            if (!(1 == cartItemVo.getSvipProductFlag() && svipUserFlag)) {
+                                // 超级会员购买svip商品不享受店铺促销优惠
+                                shopPromotionPrice.set(MathUtil.add(shopPromotionPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                            }
                             // 该供应商下商品种类 +1
                             shopKindCount.incrementAndGet();
                             // 购物车总数量 + 当前商品购买数量
@@ -223,17 +244,20 @@ public class CartClubServiceImpl implements CartClubService {
                             // 设置该优惠下的商品列表
                             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);
+                                if (!(1 == item.getSvipProductFlag() && svipUserFlag)){
+                                    // 超级会员购买svip商品不享受店铺促销优惠
+                                    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) {
+                            if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionPrice, shopPromotion.getTouchPrice()) > -1) {
                                 // 该供应商总价 - 满减金额
                                 shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
                                 // 该供应商优惠总额 + 满减金额
@@ -632,6 +656,9 @@ 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<>();
@@ -652,6 +679,8 @@ public class CartClubServiceImpl implements CartClubService {
                     AtomicInteger shopKindCount = new AtomicInteger(0);
                     // 该供应商总价
                     AtomicDouble shopPrice = new AtomicDouble(0);
+                    // 该供应商下参与店铺促销的商品总价
+                    AtomicDouble shopPromotionPrice = new AtomicDouble(0);
                     // 该供应商满减金额(供应商满减,单品满减)
                     AtomicDouble shopReducedPrice = new AtomicDouble(0);
                     // 供应商促销优惠活动
@@ -672,51 +701,67 @@ public class CartClubServiceImpl implements CartClubService {
                             if (recharge) {
                                 includeRecharge.set(true);
                             }
-                            // 获取商品促销信息
-                            PromotionsVo promotions = null;
-                            // 没有店铺促销时,商品促销才有效
-                            if (null == shopPromotion) {
+                            if (1 == cartItemVo.getSvipProductFlag()) {
+                                // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
+                                // 超级会员设置商品优惠价
+                                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 {
                                 // 获取商品促销信息
-                                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());
+                            // 该供应商下可参与店铺促销的商品价格累加
+                            if (!(1 == cartItemVo.getSvipProductFlag() && svipUserFlag)) {
+                                // 超级会员购买svip商品不享受店铺促销优惠
+                                shopPromotionPrice.set(MathUtil.add(shopPromotionPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                            }
                             // 该供应商下商品种类 +1
                             shopKindCount.incrementAndGet();
                             // 总数量 + 当前商品购买数量
@@ -737,17 +782,20 @@ public class CartClubServiceImpl implements CartClubService {
                                     // 设置该优惠下的商品列表
                                     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);
+                                        if (!(1 == item.getSvipProductFlag() && svipUserFlag)){
+                                            // 超级会员购买svip商品不享受店铺促销优惠
+                                            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) {
+                                    if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionPrice, shopPromotion.getTouchPrice()) > -1) {
                                         // 该供应商总价 - 满减金额
                                         shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
                                         // 该供应商优惠总额 + 满减金额

+ 65 - 41
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -397,6 +397,9 @@ 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) {
@@ -407,6 +410,8 @@ 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);
                 // 供应商促销优惠活动
@@ -422,51 +427,67 @@ public class CartSellerServiceImpl implements CartSellerService {
                         if (recharge) {
                             includeRecharge.set(true);
                         }
-                        // 获取商品促销信息
-                        PromotionsVo promotions = null;
-                        // 没有店铺促销时,商品促销才有效
-                        if (null == shopPromotion) {
+                        if (1 == cartItemVo.getSvipProductFlag()) {
+                            // 超级会员优惠商品,不参与促销活动(普通机构购买该商品可参与店铺促销)/阶梯价/复购价
+                            // 超级会员设置商品优惠价
+                            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{
                             // 获取商品促销信息
-                            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) {
-                                    cartItemVo.setPrice(repurchase);
+                                if (cartItemVo.getLadderFlag() == 1) {
+                                    // 设置阶梯价
+                                    productService.setCartLadderPrices(cartItemVo, taxFlag);
+                                } else {
+                                    // 复购价
+                                    Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), clubUserId);
+                                    if (null != repurchase && repurchase > 0) {
+                                        cartItemVo.setPrice(repurchase);
+                                    }
                                 }
                             }
                         }
                         // 该供应商下价格累加
                         shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        // 该供应商下可参与店铺促销的商品价格累加
+                        if (!(1 == cartItemVo.getSvipProductFlag() && svipUserFlag)) {
+                            // 超级会员购买svip商品不享受店铺促销优惠
+                            shopPromotionPrice.set(MathUtil.add(shopPromotionPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        }
                         // 该供应商下商品种类 +1
                         shopKindCount.incrementAndGet();
                         // 总数量 + 当前商品购买数量
@@ -487,17 +508,20 @@ public class CartSellerServiceImpl implements CartSellerService {
                                 // 设置该优惠下的商品列表
                                 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);
+                                    if (!(1 == item.getSvipProductFlag() && svipUserFlag)){
+                                        // 超级会员购买svip商品不享受店铺促销优惠
+                                        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) {
+                                if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPromotionPrice, shopPromotion.getTouchPrice()) > -1) {
                                     // 该供应商总价 - 满减金额
                                     shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
                                     // 该供应商优惠总额 + 满减金额

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

@@ -263,6 +263,10 @@ public class SubmitServiceImpl implements SubmitService {
             return ResponseJson.error("购买类型不正确!", null);
         }
         orderParamBo.setBuyUserId(buyUserId);
+        // 超级会员用户标识
+        Integer svipUserId = baseMapper.getSvipUserIdByUserId(clubUserId);
+        boolean svipUserFlag = null != svipUserId;
+        orderParamBo.setSvipUserFlag(svipUserFlag);
         orderParamBo.setServiceProviderId(submitDto.getServiceProviderId());
         orderParamBo.setAddressId(submitDto.getAddressId());
         orderParamBo.setClubCouponId(submitDto.getClubCouponId());
@@ -464,6 +468,8 @@ public class SubmitServiceImpl implements SubmitService {
                 product.setNum(productNum);
                 product.setPresentNum(presentNum);
                 product.setProductType(productType);
+                // 超级会员优惠商品详情
+                SvipProductPo svipProductPo = submitMapper.getSvipProductDetails(productId);
                 // 是否是促销赠品
                 if (productType == 2) {
                     // 促销赠品数+1
@@ -478,7 +484,7 @@ public class SubmitServiceImpl implements SubmitService {
                     product.setTotalAddedValueTax(0d);
                 }
                 else {
-                    // 获取商品购买价格(活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
+                    // 获取商品购买价格(超级会员优惠商品价格>>>活动价格>>>阶梯价格>>>复购价格库>>>商品原始价)
                     Double productPrice = product.getPrice();
                     Double discountPrice = product.getPrice();
                     // 商品税费
@@ -491,7 +497,15 @@ public class SubmitServiceImpl implements SubmitService {
                         promotions = baseMapper.getPromotionByProductId(productId);
                     }
                     // 计算单价
-                    if (promotions != null) {
+                    if (1 == svipProductPo.getSvipProductFlag() && orderParamBo.getSvipUserFlag()) {
+                        if (1 == svipProductPo.getSvipPriceType()) {
+                            // 折扣价
+                            discountPrice = MathUtil.div(MathUtil.mul(productPrice, svipProductPo.getSvipDiscount()), 100, 2).doubleValue();
+                        } else if (2 == svipProductPo.getSvipPriceType()) {
+                            // 直接优惠价
+                            discountPrice = svipProductPo.getSvipDiscountPrice().doubleValue();
+                        }
+                    } else if (promotions != null) {
                         // 是否包含活动商品(受订单未支付自动关闭时间影响)  0 否 1 是
                         hasActProductFlag = true;
                         // 关闭阶梯价格,活动优先

+ 11 - 0
src/main/resources/mapper/BaseMapper.xml

@@ -228,4 +228,15 @@
         INSERT INTO cm_user_balance_record (userId, type, balanceType, addDate, amount, orderId, remark, delFlag)
         VALUES (#{userId}, #{type}, #{balanceType}, #{addDate}, #{amount}, #{orderId}, #{remark}, #{delFlag})
     </insert>
+    <select id="getSvipUserIdByUserId" resultType="java.lang.Integer">
+        select userId from cm_svip_user where userId = #{userId} and delFlag = '0' and now() <![CDATA[ < ]]> endTime
+    </select>
+    <select id="getSvipUserIdByClubId" resultType="java.lang.Integer">
+        select svu.userId
+        from cm_svip_user svu
+                 left join club c on svu.userId = c.userID
+        where c.clubID = #{clubId}
+          and delFlag = '0'
+          and now() <![CDATA[ < ]]> endTime;
+    </select>
 </mapper>

+ 12 - 2
src/main/resources/mapper/CartClubMapper.xml

@@ -49,9 +49,14 @@
             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 cm_cart c
         LEFT JOIN product p ON c.productID = p.productID
+        LEFT JOIN cm_svip_product csp ON p.productID = csp.productId
         WHERE c.userID = #{userId} and p.shopID = #{shopId}
         ORDER BY c.cm_cartID DESC
     </select>
@@ -76,9 +81,14 @@
         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 cm_cart c
         LEFT JOIN product p ON c.productID = p.productID
+        LEFT JOIN cm_svip_product csp ON p.productID = csp.productId
         WHERE c.userID = #{userId} and p.shopID = #{shopId}
         AND p.validFlag='2' AND p.productID in
         <foreach collection="productIds" open="(" separator="," close=")" item="productId">

+ 9 - 0
src/main/resources/mapper/SubmitMapper.xml

@@ -138,4 +138,13 @@
         WHERE a.addressID = #{addressId}
         LIMIT 1
     </select>
+    <select id="getSvipProductDetails" resultType="com.caimei365.order.model.po.SvipProductPo">
+        select
+               if(id is not null,1,0) as svipProductFlag,
+               priceType as svipPriceType,
+               discount as svipDiscount,
+               discountPrice as svipDiscountPrice
+        from cm_svip_product
+        where productId = #{productId}
+    </select>
 </mapper>