Browse Source

协销帮机构下单结算

chao 3 năm trước cách đây
mục cha
commit
548a9fea77

+ 0 - 7
src/main/java/com/caimei365/order/controller/AddressApi.java

@@ -2,7 +2,6 @@ package com.caimei365.order.controller;
 
 import com.caimei365.order.model.ResponseJson;
 import com.caimei365.order.model.dto.AddressDto;
-import com.caimei365.order.model.dto.CartDto;
 import com.caimei365.order.model.vo.AddressSelectVo;
 import com.caimei365.order.model.vo.AddressVo;
 import com.caimei365.order.service.AddressService;
@@ -123,10 +122,4 @@ public class AddressApi {
         return addressService.deleteUserAddress(addressDto);
     }
 
-
-
-
-
-
-
 }

+ 82 - 6
src/main/java/com/caimei365/order/controller/CartSellerApi.java

@@ -1,6 +1,7 @@
 package com.caimei365.order.controller;
 
 import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.dto.AgainBuyDto;
 import com.caimei365.order.model.dto.SellerCartDto;
 import com.caimei365.order.service.CartSellerService;
 import io.swagger.annotations.Api;
@@ -78,8 +79,8 @@ public class CartSellerApi {
      *                      clubId       机构ID
      *                      type         商品类型:1单一商品,2组合商品
      *                      productId    单一商品id
-     *                      productNum   单一商品数量
-     *                      productInfo  组合商品信息:Json字符串格式[{"id":4351,"num":1},{}]
+     *                      productCount 单一商品数量
+     *                      productInfo  组合商品信息:Json字符串格式[{"id":4351,"count":1},{}]
      * }
      */
     @ApiOperation("协销添加购物车(旧:/seller/addCart)(/seller/batchAddCart)")
@@ -98,7 +99,7 @@ public class CartSellerApi {
             if (null == sellerCartDto.getProductId()) {
                 return ResponseJson.error("单一商品Id不能为空!", null);
             }
-            if (null == sellerCartDto.getProductNum()) {
+            if (null == sellerCartDto.getProductCount()) {
                 return ResponseJson.error("单一商品数量不能为空!", null);
             }
         } else if (2 == sellerCartDto.getType()) {
@@ -117,7 +118,7 @@ public class CartSellerApi {
      * @param sellerCartDto {
      *                      id                购物车Id
      *                      serviceProviderId 协销Id
-     *                      productNum        商品数量
+     *                      productCount        商品数量
      *                      }
      */
     @ApiOperation("协销更新购物车(旧:/seller/addProductNum)")
@@ -129,7 +130,7 @@ public class CartSellerApi {
         if (null == sellerCartDto.getId()) {
             return ResponseJson.error("购物车Id不能为空!", null);
         }
-        if (null == sellerCartDto.getProductNum()) {
+        if (null == sellerCartDto.getProductCount()) {
             return ResponseJson.error("商品数量不能为空!", null);
         }
         return cartSellerService.updateSellerCart(sellerCartDto);
@@ -143,7 +144,7 @@ public class CartSellerApi {
      *                      cartIds           购物车IDs
      * }
      */
-    @ApiOperation("删除购物车(旧:/seller/deleteSellerCart)")
+    @ApiOperation("协销删除购物车(旧:/seller/deleteSellerCart)")
     @PostMapping("/cart/delete")
     public ResponseJson<Integer> deleteSellerCart(SellerCartDto sellerCartDto){
         if (null == sellerCartDto.getServiceProviderId()) {
@@ -155,5 +156,80 @@ public class CartSellerApi {
         return cartSellerService.deleteSellerCart(sellerCartDto);
     }
 
+    /**
+     * 协销购物车结算
+     */
+    @ApiOperation("协销购物车结算(旧:/seller/settlement)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = false, name = "serviceProviderId", value = "协销Id"),
+            @ApiImplicitParam(required = false, name = "clubId", value = "机构Id"),
+            @ApiImplicitParam(required = false, name = "productIds", value = "商品ids,逗号隔开")
+    })
+    @GetMapping("/cart/settlement")
+    public ResponseJson<Map<String, Object>> settlementSellerCart(Integer serviceProviderId, Integer clubId, String productIds) {
+        if (null == serviceProviderId) {
+            return ResponseJson.error("协销Id不能为空!", null);
+        }
+        if (null == clubId) {
+            return ResponseJson.error("机构Id不能为空!", null);
+        }
+        if (StringUtils.isEmpty(productIds)) {
+            return ResponseJson.error("商品Id集合不能为空!", null);
+        }
+        return cartSellerService.settlementSellerCart(serviceProviderId, clubId, productIds);
+    }
+
+    /**
+     * 协销二手商品立即购买
+     */
+    @ApiOperation("立即购买(旧:/seller/settlementBySencondProduct)")
+    @ApiImplicitParams({
+            @ApiImplicitParam(required = false, name = "serviceProviderId", value = "协销Id"),
+            @ApiImplicitParam(required = false, name = "clubId", value = "机构Id"),
+            @ApiImplicitParam(required = false, name = "productId", value = "商品Id"),
+            @ApiImplicitParam(required = false, name = "productCount", value = "商品数量")
+    })
+    @GetMapping("/second/settlement")
+    public ResponseJson<Map<String, Object>> buyNowProduct(Integer serviceProviderId, Integer clubId, Integer productId, Integer productCount){
+        if (null == serviceProviderId) {
+            return ResponseJson.error("协销Id不能为空!", null);
+        }
+        if (null == clubId) {
+            return ResponseJson.error("购物车Id不能为空!", null);
+        }
+        if (null == productId) {
+            return ResponseJson.error("商品Id不能为空!", null);
+        }
+        if (null == productCount) {
+            return ResponseJson.error("商品数量不能为空!", null);
+        }
+        return cartSellerService.settlementSecond(serviceProviderId, clubId, productId, productCount);
+    }
+
+    /**
+     * 协销再来一单
+     *
+     * @param againBuyDto {
+     *                    serviceProviderId      协销Id
+     *                    clubId                 机构ID
+     *                    orderId                订单Id
+     *                    confirmFlag            确认标识 0未确认 1已确认-将失效商品以外的正常商品加入购物车
+     *                    }
+     */
+    @ApiOperation("协销添加购物车(旧:/seller/addCart)(/seller/batchAddCart)")
+    @PostMapping("/cart/add/again")
+    public ResponseJson<Map<String, Object>> addCartBuyAgain(AgainBuyDto againBuyDto){
+        if (null == againBuyDto.getServiceProviderId()) {
+            return ResponseJson.error("协销Id不能为空!", null);
+        }
+        if (null == againBuyDto.getClubId()) {
+            return ResponseJson.error("机构Id不能为空!", null);
+        }
+        if (null == againBuyDto.getOrderId()) {
+            return ResponseJson.error("订单Id不能为空!", null);
+        }
+        return cartSellerService.addCartBuyAgain(againBuyDto);
+    }
+
 
 }

+ 36 - 0
src/main/java/com/caimei365/order/mapper/CartSellerMapper.java

@@ -5,6 +5,7 @@ import com.caimei365.order.model.po.SellerCartPo;
 import com.caimei365.order.model.vo.CartItemVo;
 import com.caimei365.order.model.vo.CartShopVo;
 import org.apache.ibatis.annotations.Mapper;
+import org.apache.ibatis.annotations.Param;
 
 import java.util.List;
 
@@ -62,4 +63,39 @@ public interface CartSellerMapper {
      * @param cartIds 购物车Id集合
      */
     void deleteSellerCartByIds(Integer serviceProviderId, List<Integer> cartIds);
+    /**
+     * 根据商品Id获取供应商
+     * @param productId      商品Id
+     */
+    CartShopVo getShopByProductId(Integer productId);
+    /**
+     * 根据商品Ids获取购物车供应商列表
+     * @param serviceProviderId  协销Id
+     * @param clubId             机构Id
+     * @param productIds      商品Ids
+     */
+    List<CartShopVo> getCartShopsByProductIds(@Param("serviceProviderId") Integer serviceProviderId, @Param("clubId") Integer clubId, @Param("productIds") List<String> productIds);
+    /**
+     * 根据商品Ids获取购物车已上架商品列表
+     * @param serviceProviderId  协销Id
+     * @param clubId             机构Id
+     * @param shopId             供应商Id
+     * @param productIds        商品Ids
+     */
+    List<CartItemVo> getCartProductsByProductIds(@Param("serviceProviderId") Integer serviceProviderId, @Param("clubId") Integer clubId, @Param("shopId") Integer shopId, @Param("productIds") List<String> productIds);
+    /**
+     * 根据商品Id获取二手商品
+     * @param productId      商品Id
+     */
+    CartItemVo getSecondByProductId(Integer productId);
+    /**
+     * 获取订单里用户Id
+     * @param orderId 订单Id
+     */
+    Integer getOrderUserIdByOrderId(Integer orderId);
+    /**
+     * 获取订单商品的商品数量列表
+     * @param orderId 订单Id
+     */
+    List<CartItemVo> getOrderProductNum(Integer orderId);
 }

+ 37 - 0
src/main/java/com/caimei365/order/model/dto/AgainBuyDto.java

@@ -0,0 +1,37 @@
+package com.caimei365.order.model.dto;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Description
+ *
+ * @author : Charles
+ * @date : 2021/7/5
+ */
+@Data
+public class AgainBuyDto implements Serializable {
+    private static final long serialVersionUID = 1L;
+    /**
+     * 协销id
+     */
+    @ApiModelProperty("协销id")
+    private Integer serviceProviderId;
+    /**
+     * 机构id
+     */
+    @ApiModelProperty("机构id")
+    private Integer clubId;
+    /**
+     * 订单id
+     */
+    @ApiModelProperty("订单Id")
+    private Integer orderId;
+    /**
+     * 确认标志:0未确认 1已确认-将失效商品以外的正常商品加入购物车
+     */
+    @ApiModelProperty("确认标志:0未确认 1已确认-将失效商品以外的正常商品加入购物车")
+    private Integer confirmFlag;
+}

+ 1 - 1
src/main/java/com/caimei365/order/model/dto/SellerCartDto.java

@@ -43,7 +43,7 @@ public class SellerCartDto implements Serializable {
      * 商品数量
      */
     @ApiModelProperty("单一商品数量")
-    private Integer productNum;
+    private Integer productCount;
     /**
      * 组合商品信息:Json字符串格式[{id:4351,num:1},{}]
      */

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

@@ -1,8 +1,8 @@
 package com.caimei365.order.service;
 
 import com.caimei365.order.model.ResponseJson;
+import com.caimei365.order.model.dto.AgainBuyDto;
 import com.caimei365.order.model.dto.SellerCartDto;
-import io.swagger.annotations.ApiImplicitParam;
 
 import java.util.Map;
 
@@ -65,4 +65,33 @@ public interface CartSellerService {
      * }
      */
     ResponseJson<Integer> deleteSellerCart(SellerCartDto sellerCartDto);
+
+    /**
+     * 协销购物车结算
+     * @param serviceProviderId 协销Id
+     * @param clubId            机构Id
+     * @param productIds        商品Ids
+     */
+    ResponseJson<Map<String, Object>> settlementSellerCart(Integer serviceProviderId, Integer clubId, String productIds);
+
+    /**
+     * 协销二手商品立即购买
+     * @param serviceProviderId 协销Id
+     * @param clubId       机构Id
+     * @param productId    商品Id
+     * @param productCount 商品数量
+     */
+    ResponseJson<Map<String, Object>> settlementSecond(Integer serviceProviderId, Integer clubId, Integer productId, Integer productCount);
+
+    /**
+     * 协销再来一单
+     *
+     * @param againBuyDto {
+     *                    serviceProviderId      协销Id
+     *                    clubId                 机构ID
+     *                    orderId                订单Id
+     *                    confirmFlag            确认标识 0未确认 1已确认-将失效商品以外的正常商品加入购物车
+     *                    }
+     */
+    ResponseJson<Map<String, Object>> addCartBuyAgain(AgainBuyDto againBuyDto);
 }

+ 44 - 51
src/main/java/com/caimei365/order/service/impl/CartClubServiceImpl.java

@@ -516,11 +516,7 @@ public class CartClubServiceImpl implements CartClubService {
         } else {
             productIdList.add(productIds);
         }
-        // 最终商品Id列表,排除失效商品
-        List<String> resultProductIds = new ArrayList<>();
 
-        // 是否库存充足
-        AtomicBoolean isStocked = new AtomicBoolean(true);
         // 供应商列表
         List<CartShopVo> shopList = cartClubMapper.getCartShopsByProductIds(userId, productIdList);
         if (null != shopList && shopList.size()>0) {
@@ -538,11 +534,12 @@ public class CartClubServiceImpl implements CartClubService {
                 // 供应商下商品列表
                 List<CartItemVo> productList = cartClubMapper.getCartProductsByShopIdAndProductIds(userId, shop.getShopId(), finalIdList);
                 if (null != productList && productList.size()>0) {
+                    // 去除价格不可见商品
                     productList.removeIf(cartItemVo -> !(cartItemVo.getPriceFlag() == 0 || (cartItemVo.getPriceFlag() == 2 && userIdentity == 2)));
+                    // 去除库存不足商品
+                    productList.removeIf(cartItemVo -> !(cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber()));
                     // 迭代器设置商品信息
                     for (CartItemVo cartItemVo : productList) {
-                        // 加入最终商品Id列表
-                        resultProductIds.add(cartItemVo.getProductId().toString());
                         // 设置商品图片及税费
                         boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
                         // 是否充值商品
@@ -550,59 +547,55 @@ public class CartClubServiceImpl implements CartClubService {
                         if (recharge) {
                             includeRecharge.set(true);
                         }
-                        // 是否库存充足
-                        isStocked.set((cartItemVo.getStock() != null && cartItemVo.getStock() > 0 && cartItemVo.getStock() >= cartItemVo.getMin() && cartItemVo.getStock() >= cartItemVo.getNumber()));
-                        if (isStocked.get()) {
+                        // 获取商品促销信息
+                        PromotionsVo promotions = null;
+                        // 没有店铺促销时,商品促销才有效
+                        if (null == shopPromotion) {
                             // 获取商品促销信息
-                            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());
-                                        }
+                            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);
+                        }
+                        if (null != promotions || null != shopPromotion) {
+                            // 商品处于活动状态
+                            cartItemVo.setActStatus(1);
+                            // 关闭阶梯价格,活动优先
+                            cartItemVo.setLadderFlag(0);
+                        } else {
+                            if (cartItemVo.getLadderFlag() == 1) {
+                                // 设置阶梯价
+                                productService.setCartLadderPrices(cartItemVo, taxFlag);
                             } else {
-                                if (cartItemVo.getLadderFlag() == 1) {
-                                    // 设置阶梯价
-                                    productService.setCartLadderPrices(cartItemVo, taxFlag);
-                                } else {
-                                    // 复购价
-                                    Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
-                                    if (null != repurchase && repurchase > 0) {
-                                        cartItemVo.setPrice(repurchase);
-                                    }
+                                // 复购价
+                                Double repurchase = baseMapper.getRepurchasePrice(cartItemVo.getProductId(), userId);
+                                if (null != repurchase && repurchase > 0) {
+                                    cartItemVo.setPrice(repurchase);
                                 }
                             }
-                            // 该供应商下价格累加
-                            shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
-                            // 该供应商下商品种类 +1
-                            shopKindCount.incrementAndGet();
-                            // 总数量 + 当前商品购买数量
-                            totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
                         }
+                        // 该供应商下价格累加
+                        shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        // 该供应商下商品种类 +1
+                        shopKindCount.incrementAndGet();
+                        // 总数量 + 当前商品购买数量
+                        totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
                     }
                     if (shopKindCount.get() > 0) {
                         // 店铺促销

+ 337 - 13
src/main/java/com/caimei365/order/service/impl/CartSellerServiceImpl.java

@@ -6,12 +6,10 @@ 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.dto.AgainBuyDto;
 import com.caimei365.order.model.dto.SellerCartDto;
 import com.caimei365.order.model.po.SellerCartPo;
-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.model.vo.*;
 import com.caimei365.order.service.CartSellerService;
 import com.caimei365.order.utils.MathUtil;
 import com.github.pagehelper.PageHelper;
@@ -25,7 +23,10 @@ import org.springframework.stereotype.Service;
 import javax.annotation.Resource;
 import java.math.BigDecimal;
 import java.util.*;
+import java.util.concurrent.atomic.AtomicBoolean;
 import java.util.concurrent.atomic.AtomicInteger;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 /**
  * Description
@@ -243,8 +244,8 @@ public class CartSellerServiceImpl implements CartSellerService {
      *                      clubId       机构ID
      *                      type         商品类型:1单一商品,2组合商品
      *                      productId    单一商品id
-     *                      productNum   单一商品数量
-     *                      productInfo  组合商品信息:Json字符串格式[{"id":4351,"num":1},{}]
+     *                      productCount 单一商品数量
+     *                      productInfo  组合商品信息:Json字符串格式[{"id":4351,"count":1},{}]
      *                      }
      */
     @Override
@@ -258,14 +259,14 @@ public class CartSellerServiceImpl implements CartSellerService {
                 for (Iterator iterator = productArr.iterator(); iterator.hasNext();) {
                     JSONObject product = (JSONObject) iterator.next();
                     Integer productId = product.getInteger("id");
-                    Integer productNum = product.getInteger("num");
+                    Integer productCount = product.getInteger("count");
                     sellerCartDto.setProductId(productId);
-                    sellerCartDto.setProductNum(productNum);
+                    sellerCartDto.setProductCount(productCount);
                     addSellerCart(sellerCartDto);
                 }
             } catch (Exception e) {
                 log.error("组合商品信息格式错误", e);
-                return ResponseJson.error("组合商品信息格式错误!Json字符串格式[{\"id\":4351,\"num\":1},{}]", null);
+                return ResponseJson.error("组合商品信息格式错误!Json字符串格式[{\"id\":4351,\"count\":1},{}]", null);
             }
         }
         // 返回购物车种类数量
@@ -280,7 +281,7 @@ public class CartSellerServiceImpl implements CartSellerService {
         SellerCartPo cart = cartSellerMapper.getSellerCart(sellerCartDto);
         if (cart != null) {
             // 购物车已存在该商品,更新数量
-            cart.setNum(cart.getNum() + sellerCartDto.getProductNum());
+            cart.setNum(cart.getNum() + sellerCartDto.getProductCount());
             cart.setAddTime(new Date());
             cartSellerMapper.updateSellerCart(cart);
         } else {
@@ -289,7 +290,7 @@ public class CartSellerServiceImpl implements CartSellerService {
             cart.setServiceProviderId(sellerCartDto.getServiceProviderId());
             cart.setClubId(sellerCartDto.getClubId());
             cart.setProductId(sellerCartDto.getProductId());
-            cart.setNum(sellerCartDto.getProductNum());
+            cart.setNum(sellerCartDto.getProductCount());
             cart.setAddTime(new Date());
             cartSellerMapper.insertSellerCart(cart);
         }
@@ -301,7 +302,7 @@ public class CartSellerServiceImpl implements CartSellerService {
      * @param sellerCartDto {
      *                      serviceProviderId 协销Id
      *                      id           购物车Id
-     *                      productNum   商品数量
+     *                      productCount 商品数量
      *                      }
      */
     @Override
@@ -310,7 +311,7 @@ public class CartSellerServiceImpl implements CartSellerService {
         if (!sellerCartDto.getServiceProviderId().equals(cart.getServiceProviderId())) {
             return ResponseJson.error("协销Id不正确!",null);
         }
-        cart.setNum(cart.getNum() + sellerCartDto.getProductNum());
+        cart.setNum(cart.getNum() + sellerCartDto.getProductCount());
         cart.setAddTime(new Date());
         cartSellerMapper.updateSellerCart(cart);
         return ResponseJson.success(0);
@@ -339,5 +340,328 @@ public class CartSellerServiceImpl implements CartSellerService {
         return ResponseJson.success(0);
     }
 
+    /**
+     * 协销购物车结算
+     *
+     * @param serviceProviderId 协销Id
+     * @param clubId            机构Id
+     * @param productIds        商品Ids
+     */
+    @Override
+    public ResponseJson<Map<String, Object>> settlementSellerCart(Integer serviceProviderId, Integer clubId, String productIds) {
+        log.info("¥¥¥¥¥¥¥¥¥¥ > 商品结算(协销帮机构下单)");
+        // 商品种类
+        AtomicInteger kindCount = new AtomicInteger(0);
+        // 商品总数量
+        AtomicInteger totalCount = new AtomicInteger(0);
+        // 统计商品总金额
+        AtomicDouble totalPrice = new AtomicDouble(0);
+        // 统计总促销满减
+        AtomicDouble reducedPrice = new AtomicDouble(0);
+        // 统计总划线价
+        AtomicDouble totalOriginalPrice = new AtomicDouble(0);
+        // 是否包含充值商品,默认false
+        AtomicBoolean includeRecharge = new AtomicBoolean(false);
+
+        // 促销活动(总)
+        List<PromotionsVo> totalPromotions = new ArrayList<>();
+        // 促销活动Id集合,用于合并促销活动
+        List<Integer> promotionsIds = new ArrayList<>();
+        // 供应商Id集合,用户判断赠品供应商是否在当前供应商中
+        List<Integer> shopIds = new ArrayList<>();
+
+        // 前端接收商品Id信息
+        List<String> productIdList = new ArrayList<>();
+        if (productIds.contains(",")) {
+            productIdList = Stream.of(productIds.split(",")).collect(Collectors.toList());
+        } else {
+            productIdList.add(productIds);
+        }
+        // 获取机构用户Id
+        Integer clubUserId = baseMapper.getUserIdByClubId(clubId);
+        // 供应商列表
+        List<CartShopVo> shopList = cartSellerMapper.getCartShopsByProductIds(serviceProviderId, clubId, productIdList);
+        if (null != shopList && shopList.size()>0) {
+            // 遍历供应商列表
+            List<String> finalIdList = productIdList;
+            shopList.forEach(shop -> {
+                // 该供应商下商品种类
+                AtomicInteger shopKindCount = new AtomicInteger(0);
+                // 该供应商总价
+                AtomicDouble shopPrice = new AtomicDouble(0);
+                // 该供应商满减金额(供应商满减,单品满减)
+                AtomicDouble shopReducedPrice = new AtomicDouble(0);
+                // 供应商促销优惠活动
+                PromotionsVo shopPromotion = baseMapper.getPromotionByShopId(shop.getShopId());
+                // 供应商下商品列表
+                List<CartItemVo> productList = cartSellerMapper.getCartProductsByProductIds(serviceProviderId, clubId, shop.getShopId(), finalIdList);
+                if (null != productList && productList.size()>0) {
+                    for (CartItemVo cartItemVo : productList) {
+                        // 设置商品图片及税费
+                        boolean taxFlag = productService.setCartItemImgAndTax(cartItemVo);
+                        // 是否充值商品
+                        boolean recharge = productService.isRechargeProduct(cartItemVo.getProductId());
+                        if (recharge) {
+                            includeRecharge.set(true);
+                        }
+                        // 获取商品促销信息
+                        PromotionsVo promotions = null;
+                        // 没有店铺促销时,商品促销才有效
+                        if (null == shopPromotion) {
+                            // 获取商品促销信息
+                            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);
+                                }
+                            }
+                        }
+                        // 该供应商下价格累加
+                        shopPrice.set(MathUtil.add(shopPrice, MathUtil.mul(cartItemVo.getNumber(), cartItemVo.getPrice())).doubleValue());
+                        // 该供应商下商品种类 +1
+                        shopKindCount.incrementAndGet();
+                        // 总数量 + 当前商品购买数量
+                        totalCount.updateAndGet(v -> v + cartItemVo.getNumber());
+                    }
+                    if (shopKindCount.get() > 0) {
+                        // 店铺促销
+                        if (null != shopPromotion) {
+                            shop.setPromotions(shopPromotion);
+                            if (!promotionsIds.contains(shopPromotion.getId())) {
+                                promotionsIds.add(shopPromotion.getId());
+                                // 店铺满赠
+                                if (shopPromotion.getMode() == 3) {
+                                    // 获取赠品
+                                    List<CartItemVo> giftList = baseMapper.getPromotionGifts(shopPromotion.getId());
+                                    shopPromotion.setGiftList(giftList);
+                                }
+                                // 设置该优惠下的商品列表
+                                List<PromotionPriceVo> promotionPriceList = new ArrayList<>();
+                                productList.forEach(item -> {
+                                    PromotionPriceVo promotionPrice = new PromotionPriceVo();
+                                    promotionPrice.setProductId(item.getProductId());
+                                    promotionPrice.setNumber(item.getNumber());
+                                    promotionPrice.setPrice(item.getPrice());
+                                    promotionPriceList.add(promotionPrice);
+                                });
+                                shopPromotion.setProductList(promotionPriceList);
+                                // 添加到总促销
+                                totalPromotions.add(shopPromotion);
+                                // 店铺满减-计算供应商总价/满减金额
+                                if (shopPromotion.getMode() == 2 && MathUtil.compare(shopPrice, shopPromotion.getTouchPrice()) > -1) {
+                                    // 该供应商总价 - 满减金额
+                                    shopPrice.set(MathUtil.sub(shopPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                    // 该供应商优惠总额 + 满减金额
+                                    shopReducedPrice.set(MathUtil.add(shopReducedPrice.get(), shopPromotion.getReducedPrice()).doubleValue());
+                                }
+                            }
+                        }
+                        // 供应商商品
+                        shop.setCartList(productList);
+                        // 供应商总价
+                        shop.setTotalPrice(shopPrice.get());
+                        // 供应商总优惠
+                        shop.setReducedPrice(shopReducedPrice.get());
+                        // 供应商划线价
+                        shop.setOriginalPrice(MathUtil.add(shopPrice.get(), shopReducedPrice.get()).doubleValue());
+
+                        // 添加供应商Id集合
+                        shopIds.add(shop.getShopId());
+                        // 计算总价
+                        totalPrice.set(MathUtil.add(totalPrice, shop.getTotalPrice()).doubleValue());
+                        // 优惠总额
+                        reducedPrice.set(MathUtil.add(reducedPrice, shop.getReducedPrice()).doubleValue());
+                        // 总划线价
+                        totalOriginalPrice.set(MathUtil.add(totalOriginalPrice, shop.getOriginalPrice()).doubleValue());
+                        // 商品种类
+                        kindCount.updateAndGet(v -> v + shopKindCount.get());
+                    }
+                }
+                // 供应商下商品种类
+                shop.setCount(shopKindCount.get());
+            });
+            // 删除空数据
+            shopList.removeIf(shop -> (null == shop || shop.getCount() == 0));
+
+        }
+        // 总促销计算
+        totalPromotions.forEach(promotions -> {
+            // 该促销内商品总价
+            double touchPrice = promotions.getProductList().stream().mapToDouble(product -> product.getNumber() * product.getPrice()).sum();
+            // 凑单满减
+            if (promotions.getType() == 2 && promotions.getMode() == 2) {
+                if (MathUtil.compare(touchPrice, promotions.getTouchPrice()) > -1) {
+                    // 总价 - 满减金额
+                    totalPrice.set(MathUtil.sub(totalPrice, promotions.getReducedPrice()).doubleValue());
+                    // 优惠总额 + 满减金额
+                    reducedPrice.set(MathUtil.add(reducedPrice, promotions.getReducedPrice()).doubleValue());
+                }
+            } else if (promotions.getMode() == 3) {
+                // 全部满赠
+                promotions.getGiftList().forEach(gift -> {
+                    if (shopIds.contains(gift.getShopId())) {
+                        // 赠品在当前订单内的供应商下
+                        shopList.forEach(shop -> {
+                            if (shop.getShopId().equals(gift.getShopId())) {
+                                shop.getCartList().add(gift);
+                            }
+                        });
+                    } else {
+                        // 获取赠品供应商
+                        CartShopVo giftShop = baseMapper.getPromotionGiftsShop(gift.getProductId());
+                        shopIds.add(giftShop.getShopId());
+                        giftShop.setCartList(new ArrayList<>());
+                        giftShop.getCartList().add(gift);
+                        shopList.add(giftShop);
+                    }
+                });
+            }
+        });
+        // 发票信息
+        InvoiceVo invoice = baseMapper.getUserInvoice(clubUserId);
+        // 可用余额
+        Double availableMoney = baseMapper.getUserAbleUserMoney(clubUserId);
+        // 可用采美豆
+        Integer userBeans = baseMapper.getUserBeans(clubUserId);
+        // 包装返回数据
+        Map<String, Object> resultData = new HashMap<>();
+        resultData.put("list", shopList);
+        resultData.put("kindCount", kindCount);
+        resultData.put("totalCount", totalCount);
+        resultData.put("totalPrice", totalPrice);
+        resultData.put("reducedPrice", reducedPrice);
+        resultData.put("totalOriginalPrice", totalOriginalPrice);
+        resultData.put("promotions", totalPromotions);
+        resultData.put("invoice", invoice);
+        resultData.put("userMoney", availableMoney);
+        resultData.put("userBeans", userBeans);
+        resultData.put("includeRecharge", includeRecharge);
+        return ResponseJson.success(resultData);
+    }
+
+    /**
+     * 协销二手商品立即购买
+     *
+     * @param serviceProviderId 协销Id
+     * @param clubId            机构Id
+     * @param productId         商品Id
+     * @param productCount      商品数量
+     */
+    @Override
+    public ResponseJson<Map<String, Object>> settlementSecond(Integer serviceProviderId, Integer clubId, Integer productId, Integer productCount) {
+        // 统计商品总金额
+        Double totalPrice = 0d;
+        // 供应商信息
+        CartShopVo shop = cartSellerMapper.getShopByProductId(productId);
+        if (null != shop) {
+            CartItemVo second = cartSellerMapper.getSecondByProductId(productId);
+            second.setActStatus(0);
+            second.setNumber(productCount);
+            // 计算总价
+            totalPrice = MathUtil.mul(second.getNumber(), second.getPrice()).doubleValue();
+            shop.setTotalPrice(totalPrice);
+            List<CartItemVo> cartList = new ArrayList<>(1);
+            cartList.add(second);
+            shop.setCartList(cartList);
+        }
+        // 获取机构用户Id
+        Integer clubUserId = baseMapper.getUserIdByClubId(clubId);
+        // 发票信息
+        InvoiceVo invoice = baseMapper.getUserInvoice(clubUserId);
+        // 可用余额
+        Double availableMoney = baseMapper.getUserAbleUserMoney(clubUserId);
+        // 可用采美豆
+        Integer userBeans = baseMapper.getUserBeans(clubUserId);
+        // 包装返回数据
+        Map<String, Object> resultData = new HashMap<>();
+        resultData.put("shop", shop);
+        resultData.put("kindCount", 1);
+        resultData.put("totalCount", productCount);
+        resultData.put("totalPrice", totalPrice);
+        resultData.put("invoice", invoice);
+        resultData.put("userMoney", availableMoney);
+        resultData.put("userBeans", userBeans);
+        return ResponseJson.success(resultData);
+    }
+
+    /**
+     * 协销再来一单
+     *
+     * @param againBuyDto {
+     *                    serviceProviderId      协销Id
+     *                    clubId                 机构ID
+     *                    orderId                订单Id
+     *                    confirmFlag            确认标识 0未确认 1已确认-将失效商品以外的正常商品加入购物车
+     *                    }
+     */
+    @Override
+    public ResponseJson<Map<String, Object>> addCartBuyAgain(AgainBuyDto againBuyDto) {
+        // 返回数据
+        Map<String, Object> resultData = new HashMap<>();
+        // 获取订单里用户Id
+        Integer orderUserId = cartSellerMapper.getOrderUserIdByOrderId(againBuyDto.getOrderId());
+        if (null == orderUserId || orderUserId == 0) {
+            return ResponseJson.error("订单异常或不存在!", null);
+        }
+        List<CartItemVo> productList = cartSellerMapper.getOrderProductNum(againBuyDto.getOrderId());
+        // 总商品种类数量
+        Integer total = productList.size();
+        // 移除失效商品
+        productList.removeIf(cartItemVo -> (null == cartItemVo || null == cartItemVo.getValidFlag() || (cartItemVo.getValidFlag() != 2 && cartItemVo.getValidFlag() != 3 && cartItemVo.getValidFlag() != 9)));
+        // 失效商品数量
+        Integer invalid = total - productList.size();
+        if (productList.size() == 0) {
+            return ResponseJson.error(-2, "订单内的商品已全部失效,不能下单!", null);
+        }
+        if (invalid > 0 && (null == againBuyDto.getConfirmFlag() || 1 != againBuyDto.getConfirmFlag())){
+            resultData.put("productList", productList);
+            return ResponseJson.error(-3, "部分商品已失效,不能进行购买。是否先将以下商品加入购物车?", resultData);
+        }
+        // 订单商品加入协销购物车
+        SellerCartDto cart = new SellerCartDto();
+        cart.setServiceProviderId(againBuyDto.getServiceProviderId());
+        cart.setClubId(againBuyDto.getClubId());
+        productList.forEach(cartItemVo -> {
+            cart.setProductId(cartItemVo.getProductId());
+            cart.setProductCount(cartItemVo.getNumber());
+            addSellerCart(cart);
+        });
+        // 包装返回数据
+        resultData.put("userId", orderUserId);
+        resultData.put("clubId", againBuyDto.getClubId());
+        resultData.put("productList", productList);
+        return ResponseJson.success(resultData);
+    }
 
 }

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

@@ -19,7 +19,7 @@
         r.currentPrice
         from repeat_purchase_price r
         left join product p on p.productID = r.productId
-        where r.productId = #{productId} and userId = #{userId}
+        where r.productId = #{productId} and r.userId = #{userId}
         and ((p.costCheckFlag=1 and r.currentPrice <![CDATA[ >= ]]> p.costPrice) or p.costCheckFlag=2)
         and p.price1 <![CDATA[ >= ]]> r.currentPrice
         and r.delFlag = 0

+ 5 - 5
src/main/resources/mapper/CartClubMapper.xml

@@ -21,7 +21,7 @@
         FROM cm_cart c
         LEFT JOIN shop s ON c.shopID = s.shopID
         WHERE c.userID = #{userId}
-        AND productID in
+        AND c.productID in
         <foreach collection="productIds" open="(" separator="," close=")" item="productId">
             #{productId}
         </foreach>
@@ -41,7 +41,7 @@
             p.unit AS unit,
             p.stock AS stock,
             p.step AS step,
-            p.minBuyNumber AS MIN,
+            p.minBuyNumber AS min,
             p.price1TextFlag AS priceFlag,
             p.ladderPriceFlag AS ladderFlag,
             p.includedTax AS includedTax,
@@ -66,7 +66,7 @@
         p.unit AS unit,
         p.stock AS stock,
         p.step AS step,
-        p.minBuyNumber AS MIN,
+        p.minBuyNumber AS min,
         p.price1TextFlag AS priceFlag,
         p.ladderPriceFlag AS ladderFlag,
         p.includedTax AS includedTax,
@@ -76,7 +76,7 @@
         FROM cm_cart c
         LEFT JOIN product p ON c.productID = p.productID
         WHERE c.userID = #{userId} and p.shopID = #{shopId}
-        AND p.validFlag='2' AND productID in
+        AND p.validFlag='2' AND p.productID in
         <foreach collection="productIds" open="(" separator="," close=")" item="productId">
             #{productId}
         </foreach>
@@ -95,7 +95,7 @@
             p.unit AS unit,
             p.stock AS stock,
             p.step AS step,
-            p.minBuyNumber AS MIN,
+            p.minBuyNumber AS min,
             p.price1TextFlag AS priceFlag,
             p.ladderPriceFlag AS ladderFlag,
             p.includedTax AS includedTax,

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

@@ -25,7 +25,7 @@
             p.unit AS unit,
             p.stock AS stock,
             p.step AS step,
-            p.minBuyNumber AS MIN,
+            p.minBuyNumber AS min,
             p.price1TextFlag AS priceFlag,
             p.ladderPriceFlag AS ladderFlag,
             p.includedTax AS includedTax,
@@ -70,5 +70,97 @@
             #{id}
         </foreach>
     </delete>
+    <select id="getShopByProductId" resultType="com.caimei365.order.model.vo.CartShopVo">
+        SELECT
+            p.shopID AS shopId,
+            s.name AS shopName,
+            s.logo AS shopLogo
+        FROM product p
+        LEFT JOIN shop s ON s.shopID = p.shopID
+        WHERE p.productID = #{productId}
+        LIMIT 1
+    </select>
+    <select id="getCartShopsByProductIds" 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}
+        AND c.productID in
+        <foreach collection="productIds" open="(" separator="," close=")" item="productId">
+            #{productId}
+        </foreach>
+        GROUP BY c.shopId
+        ORDER BY c.id DESC
+    </select>
+    <select id="getCartProductsByProductIds" 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}
+        AND p.productID in
+        <foreach collection="productIds" open="(" separator="," close=")" item="productId">
+            #{productId}
+        </foreach>
+        ORDER BY c.id DESC
+    </select>
+    <select id="getSecondByProductId" resultType="com.caimei365.order.model.vo.CartItemVo">
+        SELECT
+            p.productId,
+            p.shopId,
+            p.`name` AS `name`,
+            p.mainImage AS image,
+            p.price1 AS price,
+            cshd.originalPrice AS originalPrice,
+            p.unit AS unit,
+            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 product p
+        LEFT JOIN cm_second_hand_detail cshd ON p.productID = cshd.productID
+        WHERE p.productCategory = 2
+        AND p.productID = #{productId}
+        LIMIT 1
+    </select>
+    <select id="getOrderUserIdByOrderId" resultType="java.lang.Integer">
+        SELECT userID FROM cm_order
+        WHERE orderID = #{orderId} AND delFlag = '0'
+    </select>
+    <select id="getOrderProductNum" resultType="com.caimei365.order.model.vo.CartItemVo">
+        SELECT
+            op.ProductID AS productId,
+            op.num AS number,
+            p.minBuyNumber AS min,
+            p.`name` AS `name`,
+            p.mainImage AS image,
+            p.validFlag AS validFlag
+        FROM cm_order_product
+        LEFT JOIN product p ON op.productID = p.productID
+        WHERE orderID = #{orderID}
+        GROUP BY op.ProductID
+    </select>
 
 </mapper>