Browse Source

协销购物车列表

chao 3 years ago
parent
commit
ceb486d1c8

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

@@ -0,0 +1,151 @@
+package com.caimei365.order.components;
+
+import com.caimei365.order.mapper.BaseMapper;
+import com.caimei365.order.model.vo.CartItemVo;
+import com.caimei365.order.model.vo.LadderPriceVo;
+import com.caimei365.order.model.vo.PromotionPriceVo;
+import com.caimei365.order.model.vo.PromotionsVo;
+import com.caimei365.order.utils.MathUtil;
+import com.caimei365.order.utils.ProductUtil;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.stereotype.Service;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.math.BigDecimal;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.stream.IntStream;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/6/29
+ */
+@Slf4j
+@Service
+public class ProductService {
+    @Value("${caimei.wwwDomain}")
+    private String domain;
+    @Resource
+    private BaseMapper baseMapper;
+
+    /**
+     * 设置商品图片及税费
+     * @param cartItemVo 购物车商品
+     * @return taxFlag 是否需要设置税费
+     */
+    public boolean setCartItemImgAndTax(CartItemVo cartItemVo) {
+        // 图片路径
+        String image = ProductUtil.getImageUrl("product", cartItemVo.getImage(), domain);
+        cartItemVo.setImage(image);
+        // 是否添加税费,不含税商品 开票需添加税费
+        boolean taxFlag = "0".equals(cartItemVo.getIncludedTax()) && ("1".equals(cartItemVo.getInvoiceType()) || "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());
+        }
+        return taxFlag;
+    }
+
+    /**
+     * 设置购物车阶梯价
+     * @param cartItemVo
+     * @param taxFlag
+     */
+    public void setCartLadderPrices(CartItemVo cartItemVo, boolean taxFlag) {
+        // 阶梯价列表
+        List<LadderPriceVo> ladderPrices = baseMapper.getLadderPriceList(cartItemVo.getProductId());
+        if (!CollectionUtils.isEmpty(ladderPrices)) {
+            IntStream.range(0, ladderPrices.size()).forEach(i -> {
+                boolean isThisLadder;
+                // 添加税费
+                if (taxFlag) {
+                    BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(ladderPrices.get(i).getBuyPrice(), cartItemVo.getTaxRate()), 100, 2);
+                    ladderPrices.get(i).setBuyPrice(MathUtil.add(ladderPrices.get(i).getBuyPrice(), addedValueTax).doubleValue());
+                }
+                if (i == ladderPrices.size() - 1) {
+                    ladderPrices.get(i).setMaxNum(0);
+                    ladderPrices.get(i).setNumRange("≥" + ladderPrices.get(i).getBuyNum());
+                    isThisLadder = (cartItemVo.getNumber() >= ladderPrices.get(i).getBuyNum());
+                } else {
+                    ladderPrices.get(i).setMaxNum(ladderPrices.get(i + 1).getBuyNum());
+                    String buyNumRangeShow = ladderPrices.get(i).getBuyNum() + "~" + (ladderPrices.get(i + 1).getBuyNum() - 1);
+                    ladderPrices.get(i).setNumRange(buyNumRangeShow);
+                    isThisLadder = (cartItemVo.getNumber() >= ladderPrices.get(i).getBuyNum() && cartItemVo.getNumber() <= ladderPrices.get(i).getMaxNum());
+                }
+                if (isThisLadder) {
+                    cartItemVo.setPrice(ladderPrices.get(i).getBuyPrice());
+                    cartItemVo.setOriginalPrice(ladderPrices.get(i).getBuyPrice());
+                }
+            });
+            cartItemVo.setMin(ladderPrices.get(0).getBuyNum());
+            cartItemVo.setLadderPrices(ladderPrices);
+        } else {
+            cartItemVo.setLadderFlag(0);
+        }
+    }
+
+    /**
+     * 当前促销活动的价格计算列表
+     *
+     * @param promotions 促销活动
+     * @param cartItemVo 当前购物车商品
+     * @param taxFlag    计算税费标志
+     * @return 价格计算列表
+     */
+    public List<PromotionPriceVo> getPromotionProducts(PromotionsVo promotions, CartItemVo cartItemVo, boolean taxFlag) {
+        List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
+        PromotionPriceVo promotionPrice = new PromotionPriceVo();
+        promotionPrice.setProductId(cartItemVo.getProductId());
+        promotionPrice.setNumber(cartItemVo.getNumber());
+        // 设置价格
+        if (promotions.getType() == 1 && promotions.getMode() == 1) {
+            // 单品优惠价添加税费
+            if (taxFlag) {
+                BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), cartItemVo.getTaxRate()), BigDecimal.valueOf(100), 2);
+                promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), addedValueTax).doubleValue());
+            }
+            promotionPrice.setPrice(promotions.getTouchPrice());
+            promotionPrice.setOriginalPrice(cartItemVo.getOriginalPrice());
+            // 设置商品活动价
+            cartItemVo.setPrice(promotions.getTouchPrice());
+        } else {
+            promotionPrice.setPrice(cartItemVo.getPrice());
+        }
+        promotionPriceList.add(promotionPrice);
+        return promotionPriceList;
+    }
+
+    /**
+     * 把当前促销更新购物车总促销
+     * @param totalPromotions 总促销列表
+     * @param promotionsIds   总促销Id集合
+     * @param promotions      当前促销
+     * @param promotionPriceList  当前促销商品价格计算列表
+     */
+    public void updateTotalPromotions(List<PromotionsVo> totalPromotions, List<Integer> promotionsIds, PromotionsVo promotions, List<PromotionPriceVo> promotionPriceList) {
+        if (promotionsIds.contains(promotions.getId())) {
+            // 列表已有该促销活动
+            totalPromotions.forEach(item -> {
+                if (item.getId().equals(promotions.getId())) {
+                    promotionPriceList.addAll(item.getProductList());
+                    item.setProductList(promotionPriceList);
+                }
+            });
+        } else {
+            // 新的促销活动
+            promotionsIds.add(promotions.getId());
+            if (promotions.getMode() == 3) {
+                // 获取赠品
+                List<CartItemVo> giftList = baseMapper.getPromotionGifts(promotions.getId());
+                promotions.setGiftList(giftList);
+            }
+            promotions.setProductList(promotionPriceList);
+            // 添加到总促销
+            totalPromotions.add(promotions);
+        }
+    }
+}

+ 1 - 2
src/main/java/com/caimei365/order/controller/CartSellerApi.java

@@ -1,7 +1,6 @@
 package com.caimei365.order.controller;
 
 import com.caimei365.order.model.ResponseJson;
-import com.caimei365.order.service.CartClubService;
 import com.caimei365.order.service.CartSellerService;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiImplicitParam;
@@ -50,7 +49,7 @@ public class CartSellerApi {
         if (null == clubId) {
             return ResponseJson.error("机构Id不能为空!", null);
         }
-        return cartSellerService.getShoppingCarts(serviceProviderId, clubId, againBuyProductIds, pageNum, pageSize);
+        return cartSellerService.getSellerShoppingCarts(serviceProviderId, clubId, againBuyProductIds, pageNum, pageSize);
     }
 
 

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

@@ -1,6 +1,8 @@
 package com.caimei365.order.mapper;
 
+import com.caimei365.order.model.vo.CartItemVo;
 import com.caimei365.order.model.vo.LadderPriceVo;
+import com.caimei365.order.model.vo.PromotionsVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -15,6 +17,11 @@ import java.util.List;
  */
 @Mapper
 public interface BaseMapper {
+    /**
+     * 获取机构用户Id
+     * @param clubId 机构Id
+     */
+    Integer getUserIdByClubId(Integer clubId);
     /**
      * 根据用户Id查询用户身份
      */
@@ -27,5 +34,21 @@ public interface BaseMapper {
      * 根据商品ID和用户ID 查询复购价
      */
     Double getRepurchasePrice(@Param("productId") Integer productId, @Param("userId") Integer userId);
+    /**
+     * 供应商促销优惠活动
+     * @param shopId 供应商Id
+     */
+    PromotionsVo getPromotionByShopId(Integer shopId);
+    /**
+     * 商品促销优惠活动
+     * @param productId 商品Id
+     */
+    PromotionsVo getPromotionByProductId(Integer productId);
+    /**
+     * 促销优惠活动赠品列表
+     * @param promotionsId 促销Id
+     */
+    List<CartItemVo> getPromotionGifts(Integer promotionsId);
+
 
 }

+ 1 - 16
src/main/java/com/caimei365/order/mapper/CartClubMapper.java

@@ -4,7 +4,7 @@ import com.caimei365.order.model.dto.CartDto;
 import com.caimei365.order.model.po.CartPo;
 import com.caimei365.order.model.vo.CartItemVo;
 import com.caimei365.order.model.vo.CartShopVo;
-import com.caimei365.order.model.vo.CartPromotionsVo;
+import com.caimei365.order.model.vo.PromotionsVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
@@ -29,21 +29,6 @@ public interface CartClubMapper {
      * @param userId 用户Id
      */
     List<CartItemVo> getCartProductsByShopId(@Param("shopId") Integer shopId, @Param("userId") Integer userId);
-    /**
-     * 购物车供应商促销优惠活动
-     * @param shopId 供应商Id
-     */
-    CartPromotionsVo getPromotionByShopId(Integer shopId);
-    /**
-     * 购物车商品促销优惠活动
-     * @param productId 商品Id
-     */
-    CartPromotionsVo getPromotionByProductId(Integer productId);
-    /**
-     * 购物车商品促销优惠活动赠品列表
-     * @param promotionsId 促销Id
-     */
-    List<CartItemVo> getPromotionGifts(Integer promotionsId);
     /**
      * 获取购物车商品列表(不区分供应商)
      * @param userId 用户Id

+ 18 - 1
src/main/java/com/caimei365/order/mapper/CartSellerMapper.java

@@ -1,7 +1,11 @@
 package com.caimei365.order.mapper;
 
+import com.caimei365.order.model.vo.CartItemVo;
+import com.caimei365.order.model.vo.CartShopVo;
 import org.apache.ibatis.annotations.Mapper;
 
+import java.util.List;
+
 /**
  * Description
  *
@@ -9,5 +13,18 @@ import org.apache.ibatis.annotations.Mapper;
  * @date : 2021/6/29
  */
 @Mapper
-public class CartSellerMapper {
+public interface CartSellerMapper {
+    /**
+     * 协销购物车供应商列表
+     * @param serviceProviderId  协销Id
+     * @param clubId             机构Id
+     */
+    List<CartShopVo> getSellerCartShops(Integer serviceProviderId, Integer clubId);
+    /**
+     * 协销购物车供应商下商品列表
+     * @param serviceProviderId  协销Id
+     * @param clubId             机构Id
+     * @param shopId             供应商Id
+     */
+    List<CartItemVo> getSellerCartProducts(Integer serviceProviderId, Integer clubId, Integer shopId);
 }

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

@@ -97,10 +97,13 @@ public class CartItemVo implements Serializable {
     /**
      * 商品促销活动
      */
-    private CartPromotionsVo promotions;
+    private PromotionsVo promotions;
     /**
      * 阶梯价列表
      */
     List<LadderPriceVo> ladderPrices;
-
+    /**
+     * 前端商品勾选状态
+     */
+    private Boolean isChecked;
 }

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

@@ -50,7 +50,7 @@ public class CartShopVo implements Serializable {
     /**
      * 促销活动
      */
-    private CartPromotionsVo promotions;
+    private PromotionsVo promotions;
 
 
 

+ 3 - 3
src/main/java/com/caimei365/order/model/vo/CartPromotionPriceVo.java → src/main/java/com/caimei365/order/model/vo/PromotionPriceVo.java

@@ -1,10 +1,10 @@
 package com.caimei365.order.model.vo;
 
-import com.fasterxml.jackson.annotation.JsonFormat;
+
 import lombok.Data;
 
 import java.io.Serializable;
-import java.util.Date;
+
 
 /**
  * Description
@@ -13,7 +13,7 @@ import java.util.Date;
  * @date : 2021/6/25
  */
 @Data
-public class CartPromotionPriceVo implements Serializable {
+public class PromotionPriceVo implements Serializable {
     private static final long serialVersionUID = 1L;
     /**
      * 促销Id

+ 2 - 2
src/main/java/com/caimei365/order/model/vo/CartPromotionsVo.java → src/main/java/com/caimei365/order/model/vo/PromotionsVo.java

@@ -14,7 +14,7 @@ import java.util.List;
  * @date : 2021/6/25
  */
 @Data
-public class CartPromotionsVo implements Serializable {
+public class PromotionsVo implements Serializable {
     private static final long serialVersionUID = 1L;
     /**
      * 促销id
@@ -69,7 +69,7 @@ public class CartPromotionsVo implements Serializable {
     /**
      * 该优惠下(该购物车商品)价格列表
      */
-    private List<CartPromotionPriceVo> productList;
+    private List<PromotionPriceVo> productList;
     /**
      * 该优惠下赠品品
      */

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

@@ -20,5 +20,5 @@ public interface CartSellerService {
      * @param pageNum            页码
      * @param pageSize           每页数量
      */
-    ResponseJson<Map<String, Object>> getShoppingCarts(Integer serviceProviderId, Integer clubId, String againBuyProductIds, int pageNum, int pageSize);
+    ResponseJson<Map<String, Object>> getSellerShoppingCarts(Integer serviceProviderId, Integer clubId, String againBuyProductIds, int pageNum, int pageSize);
 }

+ 25 - 136
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -1,5 +1,6 @@
 package com.caimei365.order.service.impl;
 
+import com.caimei365.order.components.ProductService;
 import com.caimei365.order.mapper.BaseMapper;
 import com.caimei365.order.mapper.CartClubMapper;
 import com.caimei365.order.model.ResponseJson;
@@ -8,19 +9,16 @@ import com.caimei365.order.model.po.CartPo;
 import com.caimei365.order.model.vo.*;
 import com.caimei365.order.service.CartClubService;
 import com.caimei365.order.utils.MathUtil;
-import com.caimei365.order.utils.ProductUtil;
 import com.google.common.collect.Lists;
 import com.google.common.util.concurrent.AtomicDouble;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
-import org.springframework.util.CollectionUtils;
 
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.*;
 import java.util.concurrent.atomic.AtomicInteger;
-import java.util.stream.IntStream;
 
 
 /**
@@ -38,6 +36,8 @@ public class CartClubServiceImpl implements CartClubService {
     private BaseMapper baseMapper;
     @Resource
     private CartClubMapper cartClubMapper;
+    @Resource
+    private ProductService productService;
 
     /**
      * 购物车列表详细数据
@@ -67,7 +67,7 @@ public class CartClubServiceImpl implements CartClubService {
          * 处理数据
          */
         // 促销活动(总)
-        List<CartPromotionsVo> totalPromotions = new ArrayList<>();
+        List<PromotionsVo> totalPromotions = new ArrayList<>();
         List<Integer> promotionsIds = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
@@ -81,7 +81,7 @@ public class CartClubServiceImpl implements CartClubService {
                 // 该供应商满减金额(供应商满减,单品满减)
                 AtomicDouble shopReducedPrice = new AtomicDouble(0);
                 // 供应商促销优惠活动
-                CartPromotionsVo shopPromotion = cartClubMapper.getPromotionByShopId(shop.getShopId());
+                PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
                 // 供应商下商品列表
                 List<CartItemVo> productList = cartClubMapper.getCartProductsByShopId(shop.getShopId(), userId);
 
@@ -90,30 +90,32 @@ public class CartClubServiceImpl implements CartClubService {
                 while (productIterator.hasNext()) {
                     CartItemVo cartItemVo = productIterator.next();
                     // 设置商品图片及税费
-                    boolean taxFlag = setCartItemImgAndTax(cartItemVo);
+                    boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
                     // 已上架商品
                     if (cartItemVo.getValidFlag() == 2) {
                         // 设置商品有效
                         cartItemVo.setStatus(0);
+                        // 默认所有商品选中状态
+                        cartItemVo.setIsChecked(true);
                         // 价格是否可见
                         boolean priceVisible = (cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2));
                         // 是否库存充足
                         boolean isStocked = (cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber());
                         if (priceVisible && isStocked) {
                             // 获取商品促销信息
-                            CartPromotionsVo promotions = null;
+                            PromotionsVo promotions = null;
                             // 没有店铺促销时,商品促销才有效
                             if (null == shopPromotion) {
                                 // 获取商品促销信息
-                                promotions = cartClubMapper.getPromotionByProductId(cartItemVo.getProductId());
+                                promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
                                 /*
                                  * 设置商品促销优惠
                                  */
                                 if (null != promotions) {
                                     // 当前促销活动的价格计算列表
-                                    List<CartPromotionPriceVo> promotionPriceList = getPromotionProducts(promotions, cartItemVo, taxFlag);
+                                    List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
                                     // 更新到总促销列表
-                                    updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
+                                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
                                     //单品满减-计算供应商总价/满减金额
                                     if (promotions.getType() == 1 && promotions.getMode() == 2) {
                                         BigDecimal totalAmount = MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice());
@@ -134,7 +136,7 @@ public class CartClubServiceImpl implements CartClubService {
                             } else {
                                 if (cartItemVo.getLadderFlag() == 1) {
                                     // 设置阶梯价
-                                    setCartLadderPrices(cartItemVo, taxFlag);
+                                    productService.setCartLadderPrices(cartItemVo, taxFlag);
                                 } else {
                                     // 复购价
                                     Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
@@ -194,13 +196,13 @@ public class CartClubServiceImpl implements CartClubService {
                         // 店铺满赠
                         if (shopPromotion.getMode() == 3) {
                             // 获取赠品
-                            List<CartItemVo> giftList = cartClubMapper.getPromotionGifts(shopPromotion.getId());
+                            List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
                             shopPromotion.setGiftList(giftList);
                         }
                         // 设置该优惠下的商品列表
-                        List<CartPromotionPriceVo> promotionPriceList = new ArrayList<>();
+                        List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
                         productList.forEach(item -> {
-                            CartPromotionPriceVo promotionPrice = new CartPromotionPriceVo();
+                            PromotionPriceVo promotionPrice = new PromotionPriceVo();
                             promotionPrice.setProductId(item.getProductId());
                             promotionPrice.setNumber(item.getNumber());
                             promotionPrice.setPrice(item.getPrice());
@@ -218,6 +220,7 @@ public class CartClubServiceImpl implements CartClubService {
                         }
                     }
                 }
+                // 供应商商品
                 shop.setCartList(productList);
                 // 供应商总价
                 shop.setTotalPrice(shopPrice.get());
@@ -237,7 +240,7 @@ public class CartClubServiceImpl implements CartClubService {
                 kindCount.updateAndGet(v -> v + shopKindCount.get());
             });
             // 删除空数据
-            shopInfoList.removeIf(shop -> (null != shop && shop.getCount() == 0));
+            shopInfoList.removeIf(shop -> (null == shop || shop.getCount() == 0));
             // 总促销计算
             totalPromotions.forEach(promotions -> {
                 // 凑单满减
@@ -291,7 +294,7 @@ public class CartClubServiceImpl implements CartClubService {
          * 处理数据
          */
         // 促销活动(总)
-        List<CartPromotionsVo> totalPromotions = new ArrayList<>();
+        List<PromotionsVo> totalPromotions = new ArrayList<>();
         List<Integer> promotionsIds = new ArrayList<>();
         // 用户身份
         Integer userIdentity = baseMapper.getIdentityByUserId(userId);
@@ -302,9 +305,9 @@ public class CartClubServiceImpl implements CartClubService {
             cartList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2)));
             cartList.forEach(cartItemVo -> {
                 // 设置商品图片及税费
-                boolean taxFlag = setCartItemImgAndTax(cartItemVo);
+                boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
                 // 获取商品促销信息
-                CartPromotionsVo promotions = cartClubMapper.getPromotionByProductId(cartItemVo.getProductId());
+                PromotionsVo promotions = baseMapper.getPromotionByProductId(cartItemVo.getProductId());
                 /*
                  * 设置商品促销优惠
                  */
@@ -314,13 +317,13 @@ public class CartClubServiceImpl implements CartClubService {
                     // 商品处于活动状态
                     cartItemVo.setActStatus(1);
                     // 当前促销活动的价格计算列表
-                    List<CartPromotionPriceVo> promotionPriceList = getPromotionProducts(promotions, cartItemVo, taxFlag);
+                    List<PromotionPriceVo> promotionPriceList = productService.getPromotionProducts(promotions, cartItemVo, taxFlag);
                     // 更新到总促销列表
-                    updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
+                    productService.updateTotalPromotions(totalPromotions, promotionsIds, promotions, promotionPriceList);
                 } else {
                     if (cartItemVo.getLadderFlag() == 1) {
                         // 设置阶梯价
-                        setCartLadderPrices(cartItemVo, taxFlag);
+                        productService.setCartLadderPrices(cartItemVo, taxFlag);
                         // 头部只展示简略信息,不显示详细阶梯价格
                         cartItemVo.setLadderPrices(null);
                     } else {
@@ -450,7 +453,7 @@ public class CartClubServiceImpl implements CartClubService {
     }
 
     /**
-     * 获取购物车数量(商品种类数)
+     * 获取机构购物车数量(商品种类数)
      * @param userId 用户ID
      * @return int
      */
@@ -471,122 +474,8 @@ public class CartClubServiceImpl implements CartClubService {
         }
     }
 
-    /**
-     * 设置商品图片及税费
-     * @param cartItemVo 购物车商品
-     * @return taxFlag 是否需要设置税费
-     */
-    private boolean setCartItemImgAndTax(CartItemVo cartItemVo) {
-        // 图片路径
-        String image = ProductUtil.getImageUrl("product", cartItemVo.getImage(), domain);
-        cartItemVo.setImage(image);
-        // 是否添加税费,不含税商品 开票需添加税费
-        boolean taxFlag = "0".equals(cartItemVo.getIncludedTax()) && ("1".equals(cartItemVo.getInvoiceType()) || "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());
-        }
-        return taxFlag;
-    }
 
-    /**
-     * 设置购物车阶梯价
-     * @param cartItemVo
-     * @param taxFlag
-     */
-    private void setCartLadderPrices(CartItemVo cartItemVo, boolean taxFlag) {
-        // 阶梯价列表
-        List<LadderPriceVo> ladderPrices = baseMapper.getLadderPriceList(cartItemVo.getProductId());
-        if (!CollectionUtils.isEmpty(ladderPrices)) {
-            IntStream.range(0, ladderPrices.size()).forEach(i -> {
-                boolean isThisLadder;
-                // 添加税费
-                if (taxFlag) {
-                    BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(ladderPrices.get(i).getBuyPrice(), cartItemVo.getTaxRate()), 100, 2);
-                    ladderPrices.get(i).setBuyPrice(MathUtil.add(ladderPrices.get(i).getBuyPrice(), addedValueTax).doubleValue());
-                }
-                if (i == ladderPrices.size() - 1) {
-                    ladderPrices.get(i).setMaxNum(0);
-                    ladderPrices.get(i).setNumRange("≥" + ladderPrices.get(i).getBuyNum());
-                    isThisLadder = (cartItemVo.getNumber() >= ladderPrices.get(i).getBuyNum());
-                } else {
-                    ladderPrices.get(i).setMaxNum(ladderPrices.get(i + 1).getBuyNum());
-                    String buyNumRangeShow = ladderPrices.get(i).getBuyNum() + "~" + (ladderPrices.get(i + 1).getBuyNum() - 1);
-                    ladderPrices.get(i).setNumRange(buyNumRangeShow);
-                    isThisLadder = (cartItemVo.getNumber() >= ladderPrices.get(i).getBuyNum() && cartItemVo.getNumber() <= ladderPrices.get(i).getMaxNum());
-                }
-                if (isThisLadder) {
-                    cartItemVo.setPrice(ladderPrices.get(i).getBuyPrice());
-                    cartItemVo.setOriginalPrice(ladderPrices.get(i).getBuyPrice());
-                }
-            });
-            cartItemVo.setMin(ladderPrices.get(0).getBuyNum());
-            cartItemVo.setLadderPrices(ladderPrices);
-        } else {
-            cartItemVo.setLadderFlag(0);
-        }
-    }
 
-    /**
-     * 当前促销活动的价格计算列表
-     *
-     * @param promotions 促销活动
-     * @param cartItemVo 当前购物车商品
-     * @param taxFlag    计算税费标志
-     * @return 价格计算列表
-     */
-    private List<CartPromotionPriceVo> getPromotionProducts(CartPromotionsVo promotions, CartItemVo cartItemVo, boolean taxFlag) {
-        List<CartPromotionPriceVo> promotionPriceList = new ArrayList<>();
-        CartPromotionPriceVo promotionPrice = new CartPromotionPriceVo();
-        promotionPrice.setProductId(cartItemVo.getProductId());
-        promotionPrice.setNumber(cartItemVo.getNumber());
-        // 设置价格
-        if (promotions.getType() == 1 && promotions.getMode() == 1) {
-            // 单品优惠价添加税费
-            if (taxFlag) {
-                BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(promotions.getTouchPrice(), cartItemVo.getTaxRate()), BigDecimal.valueOf(100), 2);
-                promotions.setTouchPrice(MathUtil.add(promotions.getTouchPrice(), addedValueTax).doubleValue());
-            }
-            promotionPrice.setPrice(promotions.getTouchPrice());
-            promotionPrice.setOriginalPrice(cartItemVo.getOriginalPrice());
-            // 设置商品活动价
-            cartItemVo.setPrice(promotions.getTouchPrice());
-        } else {
-            promotionPrice.setPrice(cartItemVo.getPrice());
-        }
-        promotionPriceList.add(promotionPrice);
-        return promotionPriceList;
-    }
-
-    /**
-     * 把当前促销更新购物车总促销
-     * @param totalPromotions 总促销列表
-     * @param promotionsIds   总促销Id集合
-     * @param promotions      当前促销
-     * @param promotionPriceList  当前促销商品价格计算列表
-     */
-    private void updateTotalPromotions(List<CartPromotionsVo> totalPromotions, List<Integer> promotionsIds, CartPromotionsVo promotions, List<CartPromotionPriceVo> promotionPriceList) {
-        if (promotionsIds.contains(promotions.getId())) {
-            // 列表已有该促销活动
-            totalPromotions.forEach(item -> {
-                if (item.getId().equals(promotions.getId())) {
-                    promotionPriceList.addAll(item.getProductList());
-                    item.setProductList(promotionPriceList);
-                }
-            });
-        } else {
-            // 新的促销活动
-            promotionsIds.add(promotions.getId());
-            if (promotions.getMode() == 3) {
-                // 获取赠品
-                List<CartItemVo> giftList = cartClubMapper.getPromotionGifts(promotions.getId());
-                promotions.setGiftList(giftList);
-            }
-            promotions.setProductList(promotionPriceList);
-            // 添加到总促销
-            totalPromotions.add(promotions);
-        }
-    }
 
 
 }

+ 178 - 3
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -1,15 +1,27 @@
 package com.caimei365.order.service.impl;
 
+import com.caimei365.order.components.ProductService;
 import com.caimei365.order.mapper.BaseMapper;
 import com.caimei365.order.mapper.CartSellerMapper;
 import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.vo.CartItemVo;
+import com.caimei365.order.model.vo.PromotionPriceVo;
+import com.caimei365.order.model.vo.PromotionsVo;
+import com.caimei365.order.model.vo.CartShopVo;
 import com.caimei365.order.service.CartSellerService;
+import com.caimei365.order.utils.MathUtil;
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.AtomicDouble;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
-import java.util.Map;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicInteger;
 
 /**
  * Description
@@ -26,6 +38,8 @@ public class CartSellerServiceImpl implements CartSellerService {
     private BaseMapper baseMapper;
     @Resource
     private CartSellerMapper cartSellerMapper;
+    @Resource
+    private ProductService productService;
 
     /**
      * 协销购物车列表数据
@@ -37,7 +51,168 @@ public class CartSellerServiceImpl implements CartSellerService {
      * @param pageSize           每页数量
      */
     @Override
-    public ResponseJson<Map<String, Object>> getShoppingCarts(Integer serviceProviderId, Integer clubId, String againBuyProductIds, int pageNum, int pageSize) {
-        return null;
+    public ResponseJson<Map<String, Object>> getSellerShoppingCarts(Integer serviceProviderId, Integer clubId, String againBuyProductIds, int pageNum, int pageSize) {
+        List<Integer> againBuyIdList = Lists.newArrayList();
+        if (againBuyProductIds.contains(",")) {
+            String[] againBuyArr = againBuyProductIds.split(",");
+            for (String id : againBuyArr) {
+                againBuyIdList.add(Integer.parseInt(id));
+            }
+        } else {
+            againBuyIdList.add(Integer.parseInt(againBuyProductIds));
+        }
+        // 失效商品列表(总)
+        List<CartItemVo> invalidList = new ArrayList<>();
+        // 促销活动(总)
+        List<PromotionsVo> totalPromotions = new ArrayList<>();
+        List<Integer> promotionsIds = new ArrayList<>();
+        // 获取机构用户Id
+        Integer clubUserId = baseMapper.getUserIdByClubId(clubId);
+        // 开始分页请求供应商数据
+        PageHelper.startPage(pageNum, pageSize);
+        // 协销购物车供应商列表
+        List<CartShopVo> shopInfoList = cartSellerMapper.getSellerCartShops(serviceProviderId, clubId);
+        if (null != shopInfoList && shopInfoList.size()>0) {
+            // 遍历供应商列表
+            shopInfoList.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 = cartSellerMapper.getSellerCartProducts(serviceProviderId, clubId, shop.getShopId());
+                // 迭代器设置商品信息
+                Iterator<CartItemVo> productIterator = productList.iterator();
+                while (productIterator.hasNext()) {
+                    CartItemVo cartItemVo = productIterator.next();
+                    if (cartItemVo.getValidFlag() == 0) {
+                        // 后台逻辑删除,已停售
+                        cartItemVo.setStatus(1);
+                        invalidList.add(cartItemVo);
+                    } else if (cartItemVo.getValidFlag() == 10) {
+                        // 已冻结,已丢失
+                        cartItemVo.setStatus(2);
+                        invalidList.add(cartItemVo);
+                    } else {
+                        // 设置商品有效
+                        cartItemVo.setStatus(0);
+                        // 设置商品图片及税费
+                        boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
+                        // 获取商品促销信息
+                        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);
+                            }
+                        }
+                        if (null != promotions || null != shopPromotion) {
+                            // 商品处于活动状态
+                            cartItemVo.setActStatus(1);
+                            // 关闭阶梯价格,活动优先
+                            cartItemVo.setLadderFlag(0);
+                        } else {
+                            if (cartItemVo.getLadderFlag() == 1) {
+                                // 设置阶梯价
+                                productService.setCartLadderPrices(cartItemVo, taxFlag);
+                            } else {
+                                // 复购价
+                                Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), clubUserId);
+                                if (null != repurchase && repurchase > 0) {
+                                    cartItemVo.setPrice(repurchase);
+                                }
+                            }
+                        }
+                        // 再来一单的商品默认选中
+                        if (againBuyIdList.contains(cartItemVo.getProductId())) {
+                            cartItemVo.setIsChecked(true);
+                        }
+                        // 该供应商下价格累加
+                        shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        // 该供应商下商品种类 +1
+                        shopKindCount.incrementAndGet();
+                    }
+                }
+                // 店铺促销
+                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.setCount(shopKindCount.get());
+            });
+            // 删除空数据
+            shopInfoList.removeIf(shop -> (null == shop || shop.getCount() == 0));
+        }
+        PageInfo<CartShopVo> pageInfo = null;
+        if (null != shopInfoList && shopInfoList.size()>0){
+            pageInfo = new PageInfo(shopInfoList);
+        }
+        /*
+         * 返回结果
+         */
+        Map<String, Object> resultMap = new HashMap<>(3);
+        resultMap.put("pageDate", pageInfo);
+        resultMap.put("invalidProductList", invalidList);
+        resultMap.put("promotionsList", totalPromotions);
+        // 返回数据
+        return ResponseJson.success(resultMap);
     }
 }

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

@@ -1,6 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.order.mapper.BaseMapper">
+    <select id="getUserIdByClubId" resultType="java.lang.Integer">
+        select userID from user where clubID = #{clubId}
+    </select>
     <select id="getIdentityByUserId" resultType="java.lang.Integer">
         select userIdentity from user where userID = #{userId}
     </select>
@@ -21,6 +24,64 @@
         and p.price1 <![CDATA[ >= ]]> r.currentPrice
         and r.delFlag = 0
     </select>
+    <select id="getPromotionByShopId" resultType="com.caimei365.order.model.vo.PromotionsVo">
+        SELECT
+        pr.id,
+        pr.name,
+        pr.description,
+        pr.type,
+        pr.mode,
+        pr.touchPrice,
+        pr.reducedPrice,
+        pr.beginTime,
+        pr.endTime,
+        pr.status,
+        prp.productId,
+        prp.supplierId AS shopId
+        FROM cm_promotions pr
+        LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
+        WHERE prp.supplierId = #{shopId} and pr.delFlag=0 and pr.type=3
+        AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
+        ORDER BY pr.type DESC LIMIT 1
+    </select>
+    <select id="getPromotionByProductId" resultType="com.caimei365.order.model.vo.PromotionsVo">
+        SELECT
+        pr.id,
+        pr.name,
+        pr.description,
+        pr.type,
+        pr.mode,
+        pr.touchPrice,
+        pr.reducedPrice,
+        pr.beginTime,
+        pr.endTime,
+        pr.status,
+        prp.productId,
+        prp.supplierId AS shopId
+        FROM cm_promotions pr
+        LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
+        WHERE prp.productId = #{productId} and pr.delFlag=0 and pr.type in (1,2)
+        AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
+        ORDER BY pr.type DESC LIMIT 1
+    </select>
+    <select id="getPromotionGifts" resultType="com.caimei365.order.model.vo.CartItemVo">
+        SELECT
+        cpg.id AS id,
+        p.productID AS productId,
+        p.shopID AS shopId,
+        p.`name` AS `name`,
+        p.mainImage AS image,
+        cpg.number AS number,
+        0 AS price,
+        p.price1 AS originalPrice,
+        p.unit AS unit,
+        p.stock AS stock,
+        p.validFlag AS validFlag
+        FROM cm_promotions_gift cpg
+        LEFT JOIN FROM product p ON cpg.productId = p.productID
+        WHERE cpg.promotionsId = #{promotionsId}
+        ORDER BY cpg.id DESC
+    </select>
 
 
 </mapper>

+ 0 - 58
src/main/resources/mapper/CartClubMapper.xml

@@ -38,64 +38,6 @@
         WHERE c.userID = #{userId} and p.shopID = #{shopId}
         ORDER BY c.cm_cartID DESC
     </select>
-    <select id="getPromotionByShopId" resultType="com.caimei365.order.model.vo.CartPromotionsVo">
-        SELECT
-            pr.id,
-            pr.name,
-            pr.description,
-            pr.type,
-            pr.mode,
-            pr.touchPrice,
-            pr.reducedPrice,
-            pr.beginTime,
-            pr.endTime,
-            pr.status,
-            prp.productId,
-            prp.supplierId AS shopId
-        FROM cm_promotions pr
-        LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
-        WHERE prp.supplierId = #{shopId} and pr.delFlag=0 and pr.type=3
-        AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
-        ORDER BY pr.type DESC LIMIT 1
-    </select>
-    <select id="getPromotionByProductId" resultType="com.caimei365.order.model.vo.CartPromotionsVo">
-        SELECT
-            pr.id,
-            pr.name,
-            pr.description,
-            pr.type,
-            pr.mode,
-            pr.touchPrice,
-            pr.reducedPrice,
-            pr.beginTime,
-            pr.endTime,
-            pr.status,
-            prp.productId,
-            prp.supplierId AS shopId
-        FROM cm_promotions pr
-        LEFT JOIN cm_promotions_product prp ON pr.id = prp.promotionsId
-        WHERE prp.productId = #{productId} and pr.delFlag=0 and pr.type in (1,2)
-        AND (pr.status = 1 OR ( pr.status = 2 AND (NOW() BETWEEN pr.beginTime AND pr.endTime)))
-        ORDER BY pr.type DESC LIMIT 1
-    </select>
-    <select id="getPromotionGifts" resultType="com.caimei365.order.model.vo.CartItemVo">
-        SELECT
-            cpg.id AS id,
-            p.productID AS productId,
-            p.shopID AS shopId,
-            p.`name` AS `name`,
-            p.mainImage AS image,
-            cpg.number AS number,
-            0 AS price,
-            p.price1 AS originalPrice,
-            p.unit AS unit,
-            p.stock AS stock,
-            p.validFlag AS validFlag
-        FROM cm_promotions_gift cpg
-        LEFT JOIN FROM product p ON cpg.productId = p.productID
-        WHERE cpg.promotionsId = #{promotionsId}
-        ORDER BY cpg.id DESC
-    </select>
     <select id="getCartProductList" resultType="com.caimei365.order.model.vo.CartItemVo">
         SELECT
             c.cm_cartID AS id,

+ 36 - 1
src/main/resources/mapper/CartSellerMapper.xml

@@ -1,5 +1,40 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
 <mapper namespace="com.caimei365.order.mapper.CartSellerMapper">
-
+    <select id="getSellerCartShops" resultType="com.caimei365.order.model.vo.CartShopVo">
+        SELECT
+            c.shopId,
+            s.name AS shopName,
+            s.logo AS shopLogo
+        FROM bp_order_product_cart c
+        LEFT JOIN shop s ON c.shopId = s.shopID
+        WHERE c.serviceProviderId = #{serviceProviderId} AND c.clubId = #{clubId}
+        GROUP BY c.shopId
+        ORDER BY c.id DESC
+    </select>
+    <select id="getSellerCartProducts" resultType="com.caimei365.order.model.vo.CartItemVo">
+        SELECT
+            c.id,
+            c.num AS number,
+            c.productId,
+            c.shopId,
+            p.`name` AS `name`,
+            p.mainImage AS image,
+            p.price1 AS price,
+            p.price1 AS originalPrice,
+            p.unit AS unit,
+            p.stock AS stock,
+            p.step AS step,
+            p.minBuyNumber AS MIN,
+            p.price1TextFlag AS priceFlag,
+            p.ladderPriceFlag AS ladderFlag,
+            p.includedTax AS includedTax,
+            p.invoiceType AS invoiceType,
+            p.taxPoint AS taxRate,
+            p.validFlag AS validFlag
+        FROM bp_order_product_cart c
+        LEFT JOIN product p ON c.productId = p.productID
+        WHERE c.serviceProviderId = #{serviceProviderId} AND c.clubId = #{clubId} AND c.shopID = #{shopId}
+        ORDER BY c.id DESC
+    </select>
 </mapper>