Ver Fonte

Merge branch 'reduce_money_coupon'

zoujiajian há 3 anos atrás
pai
commit
336837d61b

+ 3 - 1
netflix-dao/src/main/java/com/cyksj/mapper/manage/coupon/CouponUserMapper.java

@@ -8,6 +8,8 @@ import com.cyksj.model.views.CouponActiveView;
 import com.cyksj.model.views.CouponUserView;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.List;
+
 /*
  *项目名: netflix
  *文件名: CouponUserMapper
@@ -17,7 +19,7 @@ import org.apache.ibatis.annotations.Param;
 public interface CouponUserMapper extends BaseMapper<CouponUser> {
 	Page<CouponUserView> getAvailableCouponList(@Param("skuId") Long skuId, @Param("couponId") Long couponId, @Param("goodsId") Long goodsId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew, @Param("page") IPage<CouponUserView> page);
 
-	Integer countAvailableCouponList(@Param("goodsId") Long goodsId, @Param("skuId") Long skuId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew);
+	List<CouponUserView> countAvailableCouponList(@Param("goodsId") Long goodsId, @Param("skuId") Long skuId, @Param("userId") Long userId, @Param("isRenew") Boolean isRenew);
 
 	Page<CouponActiveView> couponCenterList(@Param("userId") Long userId, IPage<CouponUserView> page);
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/dto/CouponPopularizeDto.java

@@ -25,6 +25,11 @@ public class CouponPopularizeDto {
 
 	private Coupon.Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	private BigDecimal reduceCondition;
+
 	private Boolean isRenew;
 
 	private Coupon.Scope scope;

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/entity/Coupon.java

@@ -36,6 +36,11 @@ public class Coupon extends BaseEntity {
 	@NotNull(message = "优惠券类型不能为空")
 	private Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	private BigDecimal reduceCondition;
+
 	/**
 	 * 抵扣金额
 	 */

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponActiveView.java

@@ -49,6 +49,12 @@ public class CouponActiveView {
 	@DbField("c.type")
 	private Coupon.Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	@DbField("c.reduce_condition")
+	private BigDecimal reduceCondition;
+
 	/**
 	 * 抵扣金额
 	 */

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponRecommendView.java

@@ -46,6 +46,12 @@ public class CouponRecommendView {
 	@DbField("c.type")
 	private Coupon.Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	@DbField("c.reduce_condition")
+	private BigDecimal reduceCondition;
+
 	/**
 	 * 抵扣金额
 	 */

+ 6 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponUserView.java

@@ -74,6 +74,12 @@ public class CouponUserView {
 	@DbField("c.type")
 	private Coupon.Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	@DbField("c.reduce_condition")
+	private BigDecimal reduceCondition;
+
 	@DbField("c.scope")
 	private Coupon.Scope scope;
 

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/views/CouponView.java

@@ -37,6 +37,11 @@ public class CouponView {
 	 */
 	private Coupon.Type type;
 
+	/**
+	 * 可用满减卷金额条件
+	 */
+	private BigDecimal reduceCondition;
+
 	/**
 	 * 抵扣金额
 	 */

+ 1 - 0
netflix-dao/src/main/resources/mapper/CouponMapper.xml

@@ -13,6 +13,7 @@
                cdp.coupon_id as popularizeCouponId,
                cp.goods_type,
                cp.reduce_money,
+               cp.reduce_condition,
                cp.discount,
                cp.valid_days,
                cp.valid_start_time,

+ 8 - 3
netflix-dao/src/main/resources/mapper/CouponUserMapper.xml

@@ -11,6 +11,7 @@
         cp.type,
         cp.goods_sku_ids,
         cp.discount,
+        cp.reduce_condition,
         cp.reduce_money,
         cp.is_valid_time,
         cu.valid_start_time,
@@ -49,9 +50,11 @@
         </if>)s where flag = 1 and couponUserStatus != 'used'
     </select>
 
-    <select id="countAvailableCouponList" resultType="java.lang.Integer">
-        select count(distinct id)
-        from (select cu.id,ca.expiry_status as flag
+    <select id="countAvailableCouponList" resultType="com.cyksj.model.views.CouponUserView">
+        select distinct id,reduce_condition,`type`
+        from (select cu.id,ca.expiry_status as flag,
+                     cp.reduce_condition,
+                     cp.type
         from `coupon_user` cu
         left join `coupon` cp on cp.id = cu.coupon_id
         left join `coupon_sku` ck on ck.coupon_id = cp.id
@@ -80,6 +83,7 @@
                      c.name,
                      c.goods_type,
                      c.type,
+                     c.reduce_condition,
                      c.reduce_money,
                      c.discount,
                      c.scope,
@@ -129,6 +133,7 @@
                c.name,
                c.goods_type,
                c.type,
+               c.reduce_condition,
                c.reduce_money,
                c.discount,
                c.goods_sku_ids,

+ 15 - 0
netflix-service/src/main/java/com/cyksj/service/coupon/impl/CouponFontServiceImpl.java

@@ -23,7 +23,9 @@ import org.springframework.dao.DuplicateKeyException;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
+import java.math.BigDecimal;
 import java.util.ArrayList;
+import java.util.Comparator;
 import java.util.List;
 import java.util.Optional;
 
@@ -144,6 +146,7 @@ public class CouponFontServiceImpl implements CouponFontService {
 		Long goodsId = null;
 		//实物还是虚物
 		GoodsDonSkuView goodsDonSkuView = beanSearcher.searchFirst(GoodsDonSkuView.class, MapUtils.builder().field(GoodsDonSkuView::getSkuId, skuId).op(Operator.Equal).build());
+		BigDecimal skuMoney = goodsDonSkuView.getMoney();
 		if (goodsDonSkuView.getType() == 2) {
 			goodsId = goodsDonSkuView.getGoodsId();
 		}
@@ -158,12 +161,21 @@ public class CouponFontServiceImpl implements CouponFontService {
 				} catch (Exception e) {
 
 				}
+
 				if (!data.getIsAvailable()) {
 					data.setReason(String.format("仅限%s", data.getGoodsSkuStr()));
 					if (isRenew != null && isRenew && data.getIsRenew()) {
 						data.setReason(String.format("%s续费时可使用", data.getReason()));
 					}
 				}
+
+				if (goodsDonSkuView.getType() == 2 && data.getType() == Coupon.Type.reduce) {
+					if (data.getIsAvailable() && skuMoney.compareTo(data.getReduceCondition()) < 0) {
+						data.setIsAvailable(false);
+						data.setReason(String.format("满%s可用", data.getReduceCondition().divide(BigDecimal.valueOf(100))));
+					}
+				}
+
 				if (isRenew != null && isRenew && !data.getIsRenew()) {
 					data.setReason(String.format("续费时,不可使用"));
 				}
@@ -172,6 +184,9 @@ public class CouponFontServiceImpl implements CouponFontService {
 				this.setCouponUserStatus(data, now);
 			});
 		});
+		if (goodsDonSkuView.getType() == 2) {
+			availableCouponList.getRecords().sort(Comparator.comparing(CouponUserView::getIsAvailable).reversed());
+		}
 		return availableCouponList;
 	}
 

+ 6 - 0
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -270,6 +270,12 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				orderDon.setMoney(discountMoney);
 				couponMoney = payRequest.getDonMoney().subtract(discountMoney);
 			} else if (coupon.getType() == Coupon.Type.reduce) {
+				if (goodsDon.getType() == Constant.realGoodsType.get(0)) {
+					BigDecimal reduceCondition = coupon.getReduceCondition();
+					if (reduceCondition.compareTo(BigDecimal.ZERO) > 0 && reduceCondition.compareTo(payRequest.getDonMoney()) > 0) {
+						throw BusinessRuntimeException.getInstance(String.format("满%s可用", reduceCondition.divide(BigDecimal.valueOf(100))));
+					}
+				}
 				BigDecimal subtractMoney = payRequest.getDonMoney().subtract(coupon.getReduceMoney());
 				orderDon.setMoney(subtractMoney);
 				couponMoney = payRequest.getDonMoney().subtract(subtractMoney);

+ 21 - 2
netflix-web/src/main/java/com/cyksj/web/controller/coupon/CouponFrontController.java

@@ -27,7 +27,9 @@ import com.ejlchina.searcher.util.MapUtils;
 import lombok.RequiredArgsConstructor;
 import org.springframework.web.bind.annotation.*;
 
+import java.math.BigDecimal;
 import java.util.List;
+import java.util.stream.Collectors;
 
 /*
  *项目名: netflix
@@ -105,11 +107,22 @@ public class CouponFrontController {
 		if (goodsDonSkuView == null) {
 			throw BusinessRuntimeException.getInstance("规格不存在");
 		}
+		BigDecimal skuMoney = goodsDonSkuView.getMoney();
 		if (goodsDonSkuView.getType() == 2) {
 			goodsId = goodsDonSkuView.getGoodsId();
 		}
-		Integer count = couponUserMapper.countAvailableCouponList(goodsId, skuId, userId, isRenew);
-		return GatewayResponse.SUCCESS.newBuilder().toResult(count);
+		List<CouponUserView> couponUserViews = couponUserMapper.countAvailableCouponList(goodsId, skuId, userId, isRenew);
+		Integer total = couponUserViews.size();
+		if (goodsDonSkuView.getType() == 2) {
+			List<CouponUserView> collect = couponUserViews.stream().filter(coupon -> {
+				if (coupon.getType() == Coupon.Type.reduce && skuMoney.compareTo(coupon.getReduceCondition()) < 0) {
+					return false;
+				}
+				return true;
+			}).collect(Collectors.toList());
+			total = collect.size();
+		}
+		return GatewayResponse.SUCCESS.newBuilder().toResult(total);
 	}
 
 	@GetMapping("/available/list")
@@ -219,6 +232,7 @@ public class CouponFrontController {
 		if (goodsDonSkuView == null) {
 			throw BusinessRuntimeException.getInstance("该规格不存在");
 		}
+		BigDecimal skuMoney = goodsDonSkuView.getMoney();
 		if (goodsDonSkuView.getType() == 2) {
 			throw BusinessRuntimeException.getInstance("实物不支持使用优惠码");
 		}
@@ -245,6 +259,11 @@ public class CouponFrontController {
 		if (couponSku == null) {
 			throw BusinessRuntimeException.getInstance("该优惠码不适用于该规格");
 		}
+		if (goodsDonSkuView.getType() == 2) {
+			if (dto.getType() == Coupon.Type.reduce && skuMoney.compareTo(dto.getReduceCondition()) < 0) {
+				throw BusinessRuntimeException.getInstance(String.format("满%s可用", dto.getReduceCondition().divide(BigDecimal.valueOf(100))));
+			}
+		}
 		return GatewayResponse.SUCCESS.newBuilder().toResult(dto);
 	}
 }