Browse Source

呵呵商城拼团/分享减免part1

Aslee 3 years ago
parent
commit
b411d72815
23 changed files with 598 additions and 35 deletions
  1. 15 1
      src/main/java/com/caimei/controller/OrderApi.java
  2. 25 6
      src/main/java/com/caimei/controller/OrderSubmitApi.java
  3. 7 0
      src/main/java/com/caimei/mapper/OrderMapper.java
  4. 30 0
      src/main/java/com/caimei/mapper/OrderSubmitMapper.java
  5. 10 0
      src/main/java/com/caimei/mapper/ProductMapper.java
  6. 34 0
      src/main/java/com/caimei/model/po/CmHeheCollageMemberPo.java
  7. 47 0
      src/main/java/com/caimei/model/po/CmHeheCollagePo.java
  8. 45 0
      src/main/java/com/caimei/model/po/CmHeheCollageProductPo.java
  9. 5 0
      src/main/java/com/caimei/model/po/CmOrderPo.java
  10. 6 0
      src/main/java/com/caimei/model/vo/CartProductVo.java
  11. 61 0
      src/main/java/com/caimei/model/vo/CollageDetailsVo.java
  12. 15 0
      src/main/java/com/caimei/model/vo/OrderVo.java
  13. 11 0
      src/main/java/com/caimei/model/vo/ProductVo.java
  14. 38 0
      src/main/java/com/caimei/model/vo/ReductionVo.java
  15. 8 0
      src/main/java/com/caimei/service/OrderService.java
  16. 10 3
      src/main/java/com/caimei/service/OrderSubmitService.java
  17. 6 0
      src/main/java/com/caimei/service/impl/OrderServiceImpl.java
  18. 115 2
      src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java
  19. 7 0
      src/main/java/com/caimei/service/impl/ProductServiceImpl.java
  20. 28 19
      src/main/java/com/caimei/service/impl/ShoppingCartServiceImpl.java
  21. 23 4
      src/main/resources/mapper/OrderMapper.xml
  22. 47 0
      src/main/resources/mapper/OrderSubmitMapper.xml
  23. 5 0
      src/main/resources/mapper/ProductMapper.xml

+ 15 - 1
src/main/java/com/caimei/controller/OrderApi.java

@@ -1,6 +1,7 @@
 package com.caimei.controller;
 
 import com.caimei.model.ResponseJson;
+import com.caimei.model.vo.CollageDetailsVo;
 import com.caimei.model.vo.LogisticsBatchVo;
 import com.caimei.model.vo.OrderProductVo;
 import com.caimei.model.vo.OrderVo;
@@ -38,7 +39,7 @@ public class OrderApi {
      */
     @ApiOperation("我的订单")
     @ApiImplicitParams({
-            @ApiImplicitParam(name = "orderState", required = true, value = "1:待付款,2:待发货,3:已发货,4:退货款"),
+            @ApiImplicitParam(name = "orderState", required = true, value = "1:待付款,2:待发货,3:已发货,4:退货款,5:待分享"),
             @ApiImplicitParam(name = "userId", required = false, value = "用户id"),
             @ApiImplicitParam(name = "pageNum", required = false, value = "第几页"),
             @ApiImplicitParam(name = "pageSize", required = false, value = "一页多少条")
@@ -194,4 +195,17 @@ public class OrderApi {
         }
         return orderService.buyAgain(orderId);
     }
+
+    /**
+     * 拼团详情数据
+     */
+    @ApiOperation("拼团详情数据")
+    @ApiImplicitParam(name = "orderId", required = false, value = "订单id")
+    @GetMapping("/collage/details")
+    public ResponseJson<CollageDetailsVo> collageDetails(Integer collageId) {
+        if (collageId == null) {
+            return ResponseJson.error("参数异常,拼团id不能为空", null);
+        }
+        return orderService.collageDetails(collageId);
+    }
 }

+ 25 - 6
src/main/java/com/caimei/controller/OrderSubmitApi.java

@@ -53,8 +53,15 @@ public class OrderSubmitApi {
      *               *   "userId": 10708,        //机构用户ID
      *               *   "cartType":3,               //购买类型:(1购物车提交[对应表cm_cart],2直接购买提交)
      *               *   "addressId": 2732,          //地址ID
+     *               *   "discountInfo": {
+     *               *       "couponId": 12             //优惠券ID
+     *               *       "couponShareId": 12        //优惠券分享ID
+     *               *       "collageFlag": 1           //拼团标识:0不参与拼团,1参与拼团
+     *               *       "collageId": 8             //拼团id:参与拼团,若拼团id为空则发起拼团,不为空则与他人拼团
+     *               *       "reductionUserId": 8       //分享抵扣用户id
+     *               *   }
      *               *   "couponId": 12             //优惠券ID
-     *               *   "couponId": 12             //优惠券分享ID
+     *               *   "couponShareId": 12        //优惠券分享ID
      *               *   "orderInfo": [
      *               *                   { "shopId":1001,    // 供应商ID
      *               *                     "note":备注,
@@ -83,10 +90,9 @@ public class OrderSubmitApi {
         Integer userId = null;
         Integer cartType = null;
         Integer addressId = null;
-        Integer couponId = null;
-        Integer couponShareId = null;
         List<Map<String, Object>> orderInfo = null;
         Map<String, Object> payInfo = null;
+        Map<String, Object> discountInfo = null;
         Map<String, Object> orderInvoice = null;
         // 校验传入参数的正确性
         try {
@@ -106,8 +112,7 @@ public class OrderSubmitApi {
             if (null == addressId) {
                 return ResponseJson.error("地址数据异常", null);
             }
-            couponId = paramsMap.getInteger("couponId");
-            couponShareId = paramsMap.getInteger("couponShareId");
+            discountInfo = paramsMap.getJSONObject("discountInfo");
             orderInfo = (List<Map<String, Object>>) paramsMap.get("orderInfo");
             if (null == orderInfo) {
                 return ResponseJson.error("订单商品数据异常", null);
@@ -122,6 +127,20 @@ public class OrderSubmitApi {
         }
 
         log.info("****** 提交订单参数:【机构自己下单】:" + params);
-        return orderSubmitService.orderSubmit(userId, cartType, addressId, couponId, couponShareId, orderInfo, payInfo);
+        return orderSubmitService.orderSubmit(userId, cartType, addressId, discountInfo, orderInfo, payInfo);
+    }
+
+    /**
+     * 分享减免
+     */
+    @ApiOperation("分享减免")
+    @ApiImplicitParams({
+            @ApiImplicitParam(name = "userId", value = "机构用户id", required = true),
+            @ApiImplicitParam(name = "reductionId", value = "分享减免活动id", required = true),
+            @ApiImplicitParam(name = "shareType", value = "分享渠道:1微信好友,2微信朋友圈", required = true),
+    })
+    @PostMapping("/reduction/share")
+    public ResponseJson<Integer> shareReduction(Integer userId, Integer reductionId, Integer shareType) {
+        return orderSubmitService.shareReduction(userId, reductionId, shareType);
     }
 }

+ 7 - 0
src/main/java/com/caimei/mapper/OrderMapper.java

@@ -292,4 +292,11 @@ public interface OrderMapper {
      * @param receiveCouponId
      */
     void revertCoupon(Integer receiveCouponId);
+
+    /**
+     * 拼团详情
+     * @param collageId   拼团id
+     * @return
+     */
+    CollageDetailsVo getCollageDetails(Integer collageId);
 }

+ 30 - 0
src/main/java/com/caimei/mapper/OrderSubmitMapper.java

@@ -3,6 +3,7 @@ package com.caimei.mapper;
 import com.caimei.model.po.*;
 import com.caimei.model.vo.AddressVo;
 import com.caimei.model.vo.CartProductVo;
+import com.caimei.model.vo.ReductionVo;
 import com.caimei.model.vo.ShopVo;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
@@ -152,4 +153,33 @@ public interface OrderSubmitMapper {
      * @param orderRecord
      */
     void insertCouponOrderRecord(CouponOrderRecordPo orderRecord);
+
+    /**
+     * 查找拼团商品
+     * @param productID
+     * @return
+     */
+    CmHeheCollageProductPo findCollageProduct(Integer productID);
+
+    /**
+     * 新增拼团记录
+     * @param collage
+     */
+    void insertCollage(CmHeheCollagePo collage);
+
+    CmHeheCollagePo findCollage(Integer collageId);
+
+    Integer findCollageMemberNum(Integer collageId);
+
+    void insertCollageMember(CmHeheCollageMemberPo collageMember);
+
+    ReductionVo findCurrentReduction();
+
+    Integer findShareNum(@Param("userId") Integer userId, @Param("reductionId") Integer reductionId);
+
+    Integer insertReductionUser(@Param("userId") Integer userId, @Param("reductionId") Integer reductionId, @Param("shareType") Integer shareType);
+
+    ReductionVo findReduction(Integer reductionUserId);
+
+    void updateReductionUserId(@Param("reductionUserId") Integer reductionUserId,@Param("orderId") Long orderId);
 }

+ 10 - 0
src/main/java/com/caimei/mapper/ProductMapper.java

@@ -1,11 +1,14 @@
 package com.caimei.mapper;
 
+import com.caimei.model.po.CmHeheCollagePo;
+import com.caimei.model.po.CmHeheCollageProductPo;
 import com.caimei.model.po.ProductDetailInfoPo;
 import com.caimei.model.po.UserSearchHistoryPo;
 import com.caimei.model.vo.*;
 import org.apache.ibatis.annotations.Mapper;
 import org.apache.ibatis.annotations.Param;
 
+import java.math.BigDecimal;
 import java.util.List;
 
 /**
@@ -207,4 +210,11 @@ public interface ProductMapper {
      * @return
      */
     Integer findProductDiscount(@Param("productId") Integer productId, @Param("userId") Integer userId);
+
+    /**
+     * 查找拼团商品
+     * @param productID
+     * @return
+     */
+    CmHeheCollageProductPo findCollageProduct(Integer productID);
 }

+ 34 - 0
src/main/java/com/caimei/model/po/CmHeheCollageMemberPo.java

@@ -0,0 +1,34 @@
+package com.caimei.model.po;
+
+import com.fasterxml.jackson.annotation.JsonFormat;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/12/16
+ */
+@Data
+public class CmHeheCollageMemberPo implements Serializable {
+    /**
+     * 拼团id
+     */
+    private Integer collageId;
+    /**
+     * 用户id
+     */
+    private Integer userId;
+    /**
+     * 订单id
+     */
+    private Long orderId;
+    /**
+     * 拼主标识:0不是,1是
+     */
+    private Integer launchFlag;
+}

+ 47 - 0
src/main/java/com/caimei/model/po/CmHeheCollagePo.java

@@ -0,0 +1,47 @@
+package com.caimei.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/12/16
+ */
+@Data
+public class CmHeheCollagePo implements Serializable {
+    private Integer id;
+    /**
+     * 拼团商品id
+     */
+    private Integer productId;
+
+    /**
+     * 拼团商品id
+     */
+    private BigDecimal price;
+
+    /**
+     * 拼团人数
+     */
+    private Integer memberNum;
+
+    /**
+     * 拼团状态:1拼团中,已拼成
+     */
+    private Integer status;
+
+    /**
+     * 开始时间
+     */
+    private Date startTime;
+
+    /**
+     * 结束时间
+     */
+    private Date endTime;
+}

+ 45 - 0
src/main/java/com/caimei/model/po/CmHeheCollageProductPo.java

@@ -0,0 +1,45 @@
+package com.caimei.model.po;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/12/16
+ */
+@Data
+public class CmHeheCollageProductPo implements Serializable {
+    /**
+     * 呵呵商城商品id
+     */
+    private Integer productId;
+
+    /**
+     * 拼团价格
+     */
+    private BigDecimal price;
+
+    /**
+     * 单人限购量
+     */
+    private Integer limitedNum;
+
+    /**
+     * 不限购买量标识:1不限制,0限制
+     */
+    private Integer unlimitedFlag;
+
+    /**
+     * 拼团人数
+     */
+    private Integer memberNum;
+
+    /**
+     * 商品状态:0已下架,1已上架
+     */
+    private Integer status;
+}

+ 5 - 0
src/main/java/com/caimei/model/po/CmOrderPo.java

@@ -295,5 +295,10 @@ public class CmOrderPo implements Serializable {
      */
     private BigDecimal couponAmount;
 
+    /**
+     * 分享减免金额
+     */
+    private BigDecimal reductionAmount;
+
     private static final long serialVersionUID = 1L;
 }

+ 6 - 0
src/main/java/com/caimei/model/vo/CartProductVo.java

@@ -1,5 +1,6 @@
 package com.caimei.model.vo;
 
+import com.caimei.model.po.CmHeheCollageProductPo;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -93,5 +94,10 @@ public class CartProductVo implements Serializable {
      * 活动阶梯数据
      */
     private List<ActivityLadderVo> ladderList;
+
+    /**
+     * 拼团状态:0没有拼团价,1拼团价价
+     */
+    private Integer collageStatus = 0;
 }
 

+ 61 - 0
src/main/java/com/caimei/model/vo/CollageDetailsVo.java

@@ -0,0 +1,61 @@
+package com.caimei.model.vo;
+
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+import java.util.Date;
+
+/**
+ * Description
+ *
+ * @author : Aslee
+ * @date : 2021/12/21
+ */
+@Data
+public class CollageDetailsVo implements Serializable {
+    /**
+     * 拼团id
+     */
+    private Integer collageId;
+
+    /**
+     * 商品图片
+     */
+    private String productImage;
+
+    /**
+     * 商品名称
+     */
+    private String productName;
+
+    /**
+     * 拼团价
+     */
+    private BigDecimal price;
+
+    /**
+     * 市场价/原价
+     */
+    private BigDecimal normalPrice;
+
+    /**
+     * 总拼团人数
+     */
+    private Integer memberNum;
+
+    /**
+     * 已拼团人数
+     */
+    private Integer existNum;
+
+    /**
+     * 拼团还需人数
+     */
+    private Integer needNum;
+
+    /**
+     * 拼团结束时间
+     */
+    private Date endTime;
+}

+ 15 - 0
src/main/java/com/caimei/model/vo/OrderVo.java

@@ -239,5 +239,20 @@ public class OrderVo implements Serializable {
      */
     private List<ShopOrderVo> shopOrderList;
 
+    /**
+     * 是否为拼团订单
+     */
+    private boolean collageFlag = false;
+
+    /**
+     * 拼团id
+     */
+    private Integer collageId;
+
+    /**
+     * 拼团状态:1拼团中,2已拼成
+     */
+    private Integer collageStatus;
+
     private static final long serialVersionUID = 1L;
 }

+ 11 - 0
src/main/java/com/caimei/model/vo/ProductVo.java

@@ -1,5 +1,6 @@
 package com.caimei.model.vo;
 
+import com.caimei.model.po.CmHeheCollageProductPo;
 import lombok.Data;
 
 import java.io.Serializable;
@@ -48,6 +49,16 @@ public class ProductVo implements Serializable {
      */
     private Integer activeStatus = 0;
 
+    /**
+     * 拼团状态:0没有拼团价,1拼团价价
+     */
+    private Integer collageStatus = 0;
+
+    /**
+     * 拼团商品
+     */
+    private CmHeheCollageProductPo collageProduct;
+
     /**
      * 是否含税 0不含税,1含税
      */

+ 38 - 0
src/main/java/com/caimei/model/vo/ReductionVo.java

@@ -0,0 +1,38 @@
+package com.caimei.model.vo;
+
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+
+import java.io.Serializable;
+import java.math.BigDecimal;
+
+/**
+ * ReductionVo
+ *
+ * @author : Aslee
+ * @date : 2021/12/20
+ */
+@Data
+public class ReductionVo implements Serializable {
+    /**
+     * 分享减免id
+     */
+    private Integer reductionId;
+
+    /**
+     * 减免金额
+     */
+    private BigDecimal reducedAmount;
+
+    /**
+     * 减免条件
+     */
+    private BigDecimal touchPrice;
+
+    /**
+     * 分享次数
+     */
+    private Integer shareNum;
+
+    private static final long serialVersionUID = 1L;
+}

+ 8 - 0
src/main/java/com/caimei/service/OrderService.java

@@ -1,6 +1,7 @@
 package com.caimei.service;
 
 import com.caimei.model.ResponseJson;
+import com.caimei.model.vo.CollageDetailsVo;
 import com.caimei.model.vo.LogisticsBatchVo;
 import com.caimei.model.vo.OrderProductVo;
 import com.caimei.model.vo.OrderVo;
@@ -122,4 +123,11 @@ public interface OrderService {
      * @return
      */
     ResponseJson<List<OrderProductVo>> buyAgain(Integer orderId);
+
+    /**
+     * 拼团详情
+     * @param collageId
+     * @return
+     */
+    ResponseJson<CollageDetailsVo> collageDetails(Integer collageId);
 }

+ 10 - 3
src/main/java/com/caimei/service/OrderSubmitService.java

@@ -31,11 +31,18 @@ public interface OrderSubmitService {
      * @param userId
      * @param cartType
      * @param addressId
-     * @param couponId
-     * @param couponShareId
      * @param orderInfo
      * @param payInfo
      * @return
      */
-    ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Integer couponId, Integer couponShareId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo);
+    ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Map<String, Object> discountInfo, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo);
+
+    /**
+     * 分享减免
+     * @param userId
+     * @param reductionId
+     * @param shareType
+     * @return
+     */
+    ResponseJson<Integer> shareReduction(Integer userId, Integer reductionId, Integer shareType);
 }

+ 6 - 0
src/main/java/com/caimei/service/impl/OrderServiceImpl.java

@@ -377,6 +377,12 @@ public class OrderServiceImpl implements OrderService {
         return ResponseJson.success(null);
     }
 
+    @Override
+    public ResponseJson<CollageDetailsVo> collageDetails(Integer collageId) {
+        CollageDetailsVo collageDetails = orderMapper.getCollageDetails(collageId);
+        return ResponseJson.success(collageDetails);
+    }
+
     /**
      * 支付金额,待付金额
      */

+ 115 - 2
src/main/java/com/caimei/service/impl/OrderSubmitServiceImpl.java

@@ -13,7 +13,6 @@ import com.caimei.util.OrderNoUtils;
 import com.caimei.util.ProductUtils;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
@@ -124,6 +123,15 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                 return o1.getCouponAmount().compareTo(o2.getCouponAmount());
             }
         });
+        // 可参与的分享减免活动
+        ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
+        if (null != currentReduction) {
+            // 查询分享次数
+            Integer shareNum = orderSubmitMapper.findShareNum(userId, currentReduction.getReductionId());
+            if (shareNum < currentReduction.getShareNum()) {
+                confirmData.put("reduction", currentReduction);
+            }
+        }
         confirmData.put("receiveCouponList", receiveCouponList);
         confirmData.put("totalPrice", totalPrice);
         confirmData.put("shopList", shopList);
@@ -132,7 +140,7 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
 
     @Override
     @Transactional(rollbackFor = Exception.class)
-    public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Integer couponId, Integer couponShareId, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
+    public ResponseJson<Map<String, String>> orderSubmit(Integer userId, Integer cartType, Integer addressId, Map<String, Object> discountInfo, List<Map<String, Object>> orderInfo, Map<String, Object> payInfo) {
         /*
          * 逻辑处理 start
          */
@@ -197,6 +205,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
          * 订单商品
          */
         List<CmOrderProductPo> orderProductList = new ArrayList<>();
+        Integer collageFlag = (Integer) discountInfo.get("collageFlag");
+        Integer collageId = (Integer) discountInfo.get("collageId");
         for (Map<String, Object> shopOrderInfo : orderInfo) {
             Integer shopId = (Integer) shopOrderInfo.get("shopId");
             if (null == shopId) {
@@ -249,6 +259,13 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
                             }
                         }
                     }
+                    if (collageFlag != null && 1 == collageFlag) {
+                        // 拼团价
+                        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(productId);
+                        if (collageProduct != null) {
+                            productPrice = collageProduct.getPrice();
+                        }
+                    }
                     Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
                     if (null != discount && discount > 0) {
                         productPrice = MathUtil.div(MathUtil.mul(productPrice, discount), 100);
@@ -300,6 +317,8 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         CouponVo coupon = null;
         // 已领取优惠券id
         Integer receiveCouponId = null;
+        Integer couponId = (Integer) discountInfo.get("couponId");
+        Integer couponShareId = (Integer) discountInfo.get("couponShareId");
         if (null != couponId && couponId > 0) {
             receiveCouponId = couponMapper.findReceiveCouponId(userId, couponId, couponShareId);
             List<CouponVo> receiveCouponList = couponMapper.findReceiveCouponList(userId, null, receiveCouponId, 1);
@@ -313,6 +332,21 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             couponAmount = coupon.getCouponAmount();
         }
         order.setCouponAmount(couponAmount);
+        // 处理分享减免
+        BigDecimal reductionAmount = BigDecimal.ZERO;
+        Integer reductionUserId = (Integer) discountInfo.get("reductionUserId");
+        if (null != reductionUserId) {
+            // 分享减免活动
+            ReductionVo reductionVo = orderSubmitMapper.findReduction(reductionUserId);
+            if (null != reductionVo) {
+                reductionAmount = reductionVo.getReducedAmount();
+            } else {
+                // 设置手动回滚事务
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return ResponseJson.error("分享减免异常", null);
+            }
+        }
+        order.setReductionAmount(reductionAmount);
 
         // 设置是否是二手订单
         order.setSecondHandOrderFlag("0");
@@ -332,7 +366,10 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         payTotalFee = productTotalFee;
         orderTotalFee = productTotalFee;
         order.setOrderTotalFee(orderTotalFee);
+        // 优惠券抵扣
         payTotalFee = MathUtil.sub(payTotalFee, couponAmount);
+        // 分享减免
+        payTotalFee = MathUtil.sub(payTotalFee, reductionAmount);
         // 订单状态
         order.setStatus("11");
         if (MathUtil.compare(payTotalFee, 0) < 0 && MathUtil.compare(productTotalFee, 0) >= 0 && MathUtil.compare(couponAmount, 0) > 0) {
@@ -484,6 +521,61 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
             orderSubmitMapper.insertCouponOrderRecord(orderRecord);
         }
 
+        /**
+         * 保存拼团成员记录
+         */
+        if (collageFlag != null && collageFlag == 1) {
+            if (orderProductList.size() > 1) {
+                //设置手动回滚事务
+                TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                return ResponseJson.error("拼团订单商品数量异常", null);
+            }
+            // 构建拼团成员
+            CmHeheCollageMemberPo collageMember = new CmHeheCollageMemberPo();
+            collageMember.setUserId(userId);
+            collageMember.setOrderId(order.getOrderID());
+            if (collageId == null) {
+                // 拼团发起者,构建拼团记录
+                CmHeheCollagePo collage = new CmHeheCollagePo();
+                CmOrderProductPo orderProductPo = orderProductList.get(0);
+                CmHeheCollageProductPo collageProduct = orderSubmitMapper.findCollageProduct(orderProductPo.getProductID());
+                collage.setProductId(collageProduct.getProductId());
+                collage.setMemberNum(collageProduct.getMemberNum());
+                collage.setPrice(collageProduct.getPrice());
+                collage.setStatus(1);
+                Date startTime = new Date();
+                collage.setStartTime(startTime);
+                Calendar calendar = Calendar.getInstance();
+                calendar.setTime(startTime);
+                calendar.add(Calendar.DAY_OF_MONTH, 1);
+                collage.setEndTime(calendar.getTime());
+                orderSubmitMapper.insertCollage(collage);
+                collageId = collage.getId();
+                collageMember.setLaunchFlag(1);
+            } else {
+                // 已拼人数
+                Integer memberNum = orderSubmitMapper.findCollageMemberNum(collageId);
+                CmHeheCollagePo collage = orderSubmitMapper.findCollage(collageId);
+                if (collage != null && 2 != collage.getStatus() && memberNum < collage.getMemberNum()) {
+                    // 参加拼团
+                    collageMember.setLaunchFlag(0);
+                } else {
+                    //设置手动回滚事务
+                    TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
+                    return ResponseJson.error("参与拼团异常", null);
+                }
+            }
+            collageMember.setCollageId(collageId);
+            orderSubmitMapper.insertCollageMember(collageMember);
+        }
+
+        /**
+         * 保存分享减免订单抵扣记录
+         */
+        if (null != reductionUserId) {
+            orderSubmitMapper.updateReductionUserId(reductionUserId, order.getOrderID());
+        }
+
         log.info("******************** 提交订单逻辑处理 end *******************");
         /*
          * 构造返回参数
@@ -499,6 +591,27 @@ public class OrderSubmitServiceImpl implements OrderSubmitService {
         return ResponseJson.success(info);
     }
 
+    @Override
+    public ResponseJson<Integer> shareReduction(Integer userId, Integer reductionId, Integer shareType) {
+        if (null == userId || null == reductionId || null == shareType) {
+            return ResponseJson.error("参数异常", null);
+        }
+        // 可参与的分享减免活动
+        ReductionVo currentReduction = orderSubmitMapper.findCurrentReduction();
+        if (null != currentReduction) {
+            // 查询分享次数
+            Integer shareNum = orderSubmitMapper.findShareNum(userId, currentReduction.getReductionId());
+            if (shareNum <= currentReduction.getShareNum()) {
+                Integer reductionUserId = orderSubmitMapper.insertReductionUser(userId, reductionId, shareType);
+                return ResponseJson.success("分享成功", reductionUserId);
+            } else {
+                return ResponseJson.error("分享次数超限", null);
+            }
+        } else {
+            return ResponseJson.error("分享减免活动不存在", null);
+        }
+    }
+
     /**
      * 整理订单商品数据
      *

+ 7 - 0
src/main/java/com/caimei/service/impl/ProductServiceImpl.java

@@ -2,6 +2,8 @@ package com.caimei.service.impl;
 
 import com.caimei.mapper.ProductMapper;
 import com.caimei.model.ResponseJson;
+import com.caimei.model.po.CmHeheCollagePo;
+import com.caimei.model.po.CmHeheCollageProductPo;
 import com.caimei.model.po.ProductDetailInfoPo;
 import com.caimei.model.po.UserSearchHistoryPo;
 import com.caimei.model.vo.*;
@@ -65,6 +67,8 @@ public class ProductServiceImpl implements ProductService {
     public void setProductDetails(ProductVo product, Integer userId) {
         product.setMainImage(ProductUtils.getImageURL("product", product.getMainImage(), 0, domain));
         Integer activityId = productMapper.findActivityByProductId(product.getProductId());
+        // 拼团价
+        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(product.getProductId());
         if (activityId != null && activityId > 0) {
             product.setActiveStatus(1);
             //活动阶梯
@@ -74,6 +78,9 @@ public class ProductServiceImpl implements ProductService {
                 // 没有起订量概念,默认显示购买1个商品的价格,若第一阶梯为一个商品,则取第一阶梯时间
                 product.setPrice(1 == ladder.getBuyNum() ? ladder.getBuyPrice() : product.getPrice());
             }
+        } else if (collageProduct != null) {
+            product.setCollageStatus(1);
+            product.setCollageProduct(collageProduct);
         }
         Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
         if (null != discount && discount > 0) {

+ 28 - 19
src/main/java/com/caimei/service/impl/ShoppingCartServiceImpl.java

@@ -6,6 +6,7 @@ import com.caimei.mapper.ShoppingCartMapper;
 import com.caimei.model.ResponseJson;
 import com.caimei.model.dto.CartDto;
 import com.caimei.model.po.CmCartPo;
+import com.caimei.model.po.CmHeheCollageProductPo;
 import com.caimei.model.vo.*;
 import com.caimei.service.ShoppingCartService;
 import com.caimei.util.MathUtil;
@@ -90,38 +91,46 @@ public class ShoppingCartServiceImpl implements ShoppingCartService {
     public void setPrice(CartProductVo product, Integer userId) {
         //税费
         boolean addTaxFlag = ("0".equals(product.getIncludedTax()) && ("1".equals(product.getInvoiceType()) || "2".equals(product.getInvoiceType())));
+        // 活动id
         Integer activityId = productMapper.findActivityByProductId(product.getProductId());
-        // 查询商品折扣
-        Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
-        if (null != discount && discount > 0) {
-            product.setPrice(MathUtil.div(MathUtil.mul(product.getPrice(), discount), 100));
-        }
+        // 拼团商品
+        CmHeheCollageProductPo collageProduct = productMapper.findCollageProduct(product.getProductId());
         if (activityId != null && activityId > 0) {
             product.setActiveStatus(1);
             //活动阶梯
             List<ActivityLadderVo> ladderList = productMapper.findActivityLadder(activityId, product.getProductId());
             if (ladderList != null && ladderList.size() > 0) {
                 for (ActivityLadderVo ladder : ladderList) {
-                    if (null != discount && discount > 0) {
-                        ladder.setBuyPrice((MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), discount), 100)));
-                    }
-                    if (addTaxFlag) {
-                        BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-                        ladder.setBuyPrice(MathUtil.add(addedValueTax, ladder.getBuyPrice()));
-                    }
                     if (product.getProductCount() >= ladder.getBuyNum()) {
                         product.setPrice(ladder.getBuyPrice());
                     }
                 }
-            } else if (addTaxFlag) {
-                BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-                product.setPrice(MathUtil.add(addedValueTax, product.getPrice()));
             }
             product.setLadderList(ladderList);
-        } else {
-            if (addTaxFlag) {
-                BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
-                product.setPrice(MathUtil.add(addedValueTax, product.getPrice()));
+        } else if (null != collageProduct) {
+            product.setCollageStatus(1);
+            product.setPrice(collageProduct.getPrice());
+        }
+        List<ActivityLadderVo> ladderList = product.getLadderList();
+        // 查询商品折扣,设置折扣价
+        Integer discount = productMapper.findProductDiscount(product.getProductId(), userId);
+        if (null != discount && discount > 0) {
+            product.setPrice(MathUtil.div(MathUtil.mul(product.getPrice(), discount), 100));
+            if (null != ladderList) {
+                ladderList.forEach(ladder->{
+                    ladder.setBuyPrice((MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), discount), 100)));
+                });
+            }
+        }
+        // 为商品价格和阶梯列表添加税费
+        if (addTaxFlag) {
+            BigDecimal addedValueTax = MathUtil.div(MathUtil.mul(product.getPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
+            product.setPrice(MathUtil.add(addedValueTax, product.getPrice()));
+            if (null != ladderList) {
+                ladderList.forEach(ladder->{
+                    BigDecimal ladderTax = MathUtil.div(MathUtil.mul(ladder.getBuyPrice(), product.getClubTaxPoint()), BigDecimal.valueOf(100), 2);
+                    ladder.setBuyPrice(MathUtil.add(ladderTax, ladder.getBuyPrice()));
+                });
             }
         }
     }

+ 23 - 4
src/main/resources/mapper/OrderMapper.xml

@@ -35,28 +35,36 @@
           co.freight,
           co.couponAmount,
           co.paySuccessCounter,
-          co.closeReason
+          co.closeReason,
+          if(chc.id is not null,true,false) as collageFlag,
+          chc.id as collageId,
+          chc.status as collageStatus
     </sql>
     <select id="findOrderList" resultType="com.caimei.model.vo.OrderVo">
         select
           <include refid="cm_Order_List"></include>
         from cm_order co
+        left join cm_hehe_collage_member chcm on co.orderID = chcm.orderId
+        left join cm_hehe_collage chc on chcm.collageId = chc.id
         where co.delFlag = '0'
         AND co.orderType = 2
         <if test="userId != null ">
             AND co.userID = #{userId}
         </if>
         <if test="orderState == 1 ">
-            AND co.status IN(11,12,13,21,22,23)
+            AND co.status IN(11,12,13,21,22,23) AND chcm.id is null
         </if>
         <if test="orderState == 2 ">
             AND co.status IN(11,12,21,22,31,32)
         </if>
         <if test="orderState == 3 ">
-            AND co.status IN(12,13,22,23,32,33)
+            AND co.status IN(12,13,22,23,32,33) AND chcm.id is null
         </if>
         <if test="orderState == 4 ">
-            AND co.refundType IN(1,2)
+            AND co.refundType IN(1,2) AND chcm.id is null
+        </if>
+        <if test="orderState == 5">
+            AND chcm.id is not null and chc.status = 1
         </if>
         ORDER BY co.orderTime DESC
     </select>
@@ -537,4 +545,15 @@
     <select id="findOrderCoupon" resultType="java.lang.Integer">
         select receiveCouponId from cm_hehe_coupon_order_record where orderId = #{orderId}
     </select>
+    <select id="getCollageDetails" resultType="com.caimei.model.vo.CollageDetailsVo">
+        select chc.id as collageId, p.mainImage as productImage,p.name as productName,chc.price,chp.price as normalPrice,
+               chc.memberNum,count(chcm.id) as existNum,(chc.memberNum-count(chcm.id)) as needNum,
+               chc.endTime
+        from cm_hehe_collage chc
+            left join cm_hehe_collage_member chcm on chc.id = chcm.collageId
+            left join cm_hehe_collage_product chcp on chc.productId = chcp.productId
+            left join product p on chcp.productId = p.productID
+            left join cm_hehe_product chp on p.productID = chp.productId
+        where chc.id = #{collageId}
+    </select>
 </mapper>

+ 47 - 0
src/main/resources/mapper/OrderSubmitMapper.xml

@@ -234,6 +234,9 @@
             <if test="couponAmount != null">
                 couponAmount,
             </if>
+            <if test="reductionAmount != null">
+                reductionAmount,
+            </if>
             <if test="delFlag != null">
                 delFlag,
             </if>
@@ -401,6 +404,9 @@
             <if test="couponAmount != null">
                 #{couponAmount,jdbcType=DECIMAL},
             </if>
+            <if test="reductionAmount != null">
+                #{reductionAmount,jdbcType=DECIMAL},
+            </if>
             <if test="delFlag != null">
                 #{delFlag,jdbcType=CHAR},
             </if>
@@ -1409,6 +1415,9 @@
             orderId = #{orderId}
         where id = #{receiveCouponId}
     </update>
+    <update id="updateReductionUserId">
+        update cm_hehe_reduction_user set orderId = #{orderId} where id = #{reductionUserId}
+    </update>
 
     <select id="findByAddressId" resultType="com.caimei.model.vo.AddressVo">
         SELECT a.addressID AS addressId,
@@ -1521,6 +1530,17 @@
         INSERT INTO cm_hehe_coupon_order_record (orderId, receiveCouponId, couponType, couponAmount, touchPrice, createDate)
         VALUES (#{orderId}, #{receiveCouponId}, #{couponType}, #{couponAmount}, #{touchPrice}, #{createDate})
     </insert>
+    <insert id="insertCollage" useGeneratedKeys="true" keyProperty="id" keyColumn="id" parameterType="com.caimei.model.po.CmHeheCollagePo">
+        insert into cm_hehe_collage (productId, price, memberNum, status, startTime, completeTime, endTime)
+        values (#{productId}, #{price}, #{memberNum}, #{status}, #{startTime}, #{completeTime}, #{endTime})
+    </insert>
+    <insert id="insertCollageMember">
+        insert into cm_hehe_collage_member (collageId, userId, orderId, launchFlag) values (#{collageId}, #{userId}, #{orderId}, #{launchFlag})
+    </insert>
+    <insert id="insertReductionUser" useGeneratedKeys="true" keyColumn="id">
+        insert into cm_hehe_reduction_user (userId, reductionId, shareType, shareTime)
+        values (#{userId}, #{reductionId}, #{shareType}, NOW())
+    </insert>
 
     <select id="findShopByProductId" resultType="com.caimei.model.vo.ShopVo">
         SELECT
@@ -1579,4 +1599,31 @@
             #{cartId}
         </foreach>
     </select>
+    <select id="findCollageProduct" resultType="com.caimei.model.po.CmHeheCollageProductPo">
+        select chcp.productid, chcp.price, chcp.limitednum, chcp.unlimitedflag, chcp.membernum, chcp.status
+        from cm_hehe_collage_product chcp
+        where chcp.productId = #{productID} and chcp.status = 1
+    </select>
+    <select id="findCollage" resultType="com.caimei.model.po.CmHeheCollagePo">
+        select id, productId, price, memberNum, status, startTime, completeTime, endTime
+        from cm_hehe_collage where id = #{collageId} and status = 1
+    </select>
+    <select id="findCollageMemberNum" resultType="java.lang.Integer">
+        select count(*) from cm_hehe_collage_member where collageId = #{collageId}
+    </select>
+    <select id="findCurrentReduction" resultType="com.caimei.model.vo.ReductionVo">
+        select id as reductionId, reducedAmount, touchPrice, shareNum
+        from cm_hehe_reduction where NOW() <![CDATA[  >=  ]]> startTime and NOW() <![CDATA[  <=  ]]> endTime
+    </select>
+    <select id="findShareNum" resultType="java.lang.Integer">
+        select count(*)
+        from cm_hehe_reduction_user
+        where userId = #{userId}
+          and reductionId = #{reductionId}
+    </select>
+    <select id="findReduction" resultType="com.caimei.model.vo.ReductionVo">
+        select chr.id as reductionId, reducedAmount, touchPrice from cm_hehe_reduction chr
+            left join cm_hehe_reduction_user chru on chr.id = chru.reductionId
+        where chru.id = #{reductionUserId} and chru.orderId is null
+    </select>
 </mapper>

+ 5 - 0
src/main/resources/mapper/ProductMapper.xml

@@ -311,5 +311,10 @@
         order by chd.discount desc
         limit 1
     </select>
+    <select id="findCollageProduct" resultType="com.caimei.model.po.CmHeheCollageProductPo">
+        select chcp.productid, chcp.price, chcp.limitednum, chcp.unlimitedflag, chcp.membernum, chcp.status
+        from cm_hehe_collage_product chcp
+        where chcp.productId = #{productID} and chcp.status = 1
+    </select>
 
 </mapper>