Commit 9805f9f512705fd514b2971a1ae96b0985be639c
1 parent
5f7505d4
【功能修复】商城:指定发卷、新人卷,支持无限发放的兜底
Showing
4 changed files
with
19 additions
and
10 deletions
yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponTakeTypeEnum.java
| @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; | @@ -5,6 +5,7 @@ import lombok.AllArgsConstructor; | ||
| 5 | import lombok.Getter; | 5 | import lombok.Getter; |
| 6 | 6 | ||
| 7 | import java.util.Arrays; | 7 | import java.util.Arrays; |
| 8 | +import java.util.Objects; | ||
| 8 | 9 | ||
| 9 | /** | 10 | /** |
| 10 | * 优惠劵领取方式 | 11 | * 优惠劵领取方式 |
| @@ -20,12 +21,12 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { | @@ -20,12 +21,12 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { | ||
| 20 | REGISTER(3, "新人券"), // 注册时自动领取 | 21 | REGISTER(3, "新人券"), // 注册时自动领取 |
| 21 | ; | 22 | ; |
| 22 | 23 | ||
| 23 | - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTakeTypeEnum::getValue).toArray(); | 24 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTakeTypeEnum::getType).toArray(); |
| 24 | 25 | ||
| 25 | /** | 26 | /** |
| 26 | * 值 | 27 | * 值 |
| 27 | */ | 28 | */ |
| 28 | - private final Integer value; | 29 | + private final Integer type; |
| 29 | /** | 30 | /** |
| 30 | * 名字 | 31 | * 名字 |
| 31 | */ | 32 | */ |
| @@ -35,4 +36,9 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { | @@ -35,4 +36,9 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { | ||
| 35 | public int[] array() { | 36 | public int[] array() { |
| 36 | return ARRAYS; | 37 | return ARRAYS; |
| 37 | } | 38 | } |
| 39 | + | ||
| 40 | + public static boolean isUser(Integer type) { | ||
| 41 | + return Objects.equals(USER.getType(), type); | ||
| 42 | + } | ||
| 43 | + | ||
| 38 | } | 44 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java
| @@ -73,7 +73,7 @@ public class AppCouponTemplateController { | @@ -73,7 +73,7 @@ public class AppCouponTemplateController { | ||
| 73 | // 1.1 处理查询条件:商品范围编号 | 73 | // 1.1 处理查询条件:商品范围编号 |
| 74 | Long productScopeValue = getProductScopeValue(productScope, spuId); | 74 | Long productScopeValue = getProductScopeValue(productScope, spuId); |
| 75 | // 1.2 处理查询条件:领取方式 = 直接领取 | 75 | // 1.2 处理查询条件:领取方式 = 直接领取 |
| 76 | - List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue()); | 76 | + List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType()); |
| 77 | 77 | ||
| 78 | // 2. 查询 | 78 | // 2. 查询 |
| 79 | List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope, | 79 | List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope, |
| @@ -105,7 +105,7 @@ public class AppCouponTemplateController { | @@ -105,7 +105,7 @@ public class AppCouponTemplateController { | ||
| 105 | // 1.1 处理查询条件:商品范围编号 | 105 | // 1.1 处理查询条件:商品范围编号 |
| 106 | Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId()); | 106 | Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId()); |
| 107 | // 1.2 处理查询条件:领取方式 = 直接领取 | 107 | // 1.2 处理查询条件:领取方式 = 直接领取 |
| 108 | - List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue()); | 108 | + List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType()); |
| 109 | 109 | ||
| 110 | // 2. 分页查询 | 110 | // 2. 分页查询 |
| 111 | PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage( | 111 | PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage( |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| @@ -284,8 +284,9 @@ public class CouponServiceImpl implements CouponService { | @@ -284,8 +284,9 @@ public class CouponServiceImpl implements CouponService { | ||
| 284 | if (couponTemplate == null) { | 284 | if (couponTemplate == null) { |
| 285 | throw exception(COUPON_TEMPLATE_NOT_EXISTS); | 285 | throw exception(COUPON_TEMPLATE_NOT_EXISTS); |
| 286 | } | 286 | } |
| 287 | - // 校验剩余数量 | ||
| 288 | - if (couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) { | 287 | + // 校验剩余数量(仅在 CouponTakeTypeEnum.USER 用户领取时) |
| 288 | + if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeCount()) | ||
| 289 | + && couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) { | ||
| 289 | throw exception(COUPON_TEMPLATE_NOT_ENOUGH); | 290 | throw exception(COUPON_TEMPLATE_NOT_ENOUGH); |
| 290 | } | 291 | } |
| 291 | // 校验"固定日期"的有效期类型是否过期 | 292 | // 校验"固定日期"的有效期类型是否过期 |
| @@ -295,7 +296,7 @@ public class CouponServiceImpl implements CouponService { | @@ -295,7 +296,7 @@ public class CouponServiceImpl implements CouponService { | ||
| 295 | } | 296 | } |
| 296 | } | 297 | } |
| 297 | // 校验领取方式 | 298 | // 校验领取方式 |
| 298 | - if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getValue())) { | 299 | + if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getType())) { |
| 299 | throw exception(COUPON_TEMPLATE_CANNOT_TAKE); | 300 | throw exception(COUPON_TEMPLATE_CANNOT_TAKE); |
| 300 | } | 301 | } |
| 301 | } | 302 | } |
yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| @@ -57,8 +57,10 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -57,8 +57,10 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 57 | public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) { | 57 | public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) { |
| 58 | // 校验存在 | 58 | // 校验存在 |
| 59 | CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); | 59 | CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); |
| 60 | - // 校验发放数量不能过小 | ||
| 61 | - if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { | 60 | + // 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时) |
| 61 | + if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) | ||
| 62 | + && updateReqVO.getTotalCount() > 0 // 大于 0 的原因,是因为 -1 不限制 | ||
| 63 | + && updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { | ||
| 62 | throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); | 64 | throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); |
| 63 | } | 65 | } |
| 64 | // 校验商品范围 | 66 | // 校验商品范围 |
| @@ -118,7 +120,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | @@ -118,7 +120,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { | ||
| 118 | 120 | ||
| 119 | @Override | 121 | @Override |
| 120 | public List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) { | 122 | public List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) { |
| 121 | - return couponTemplateMapper.selectListByTakeType(takeType.getValue()); | 123 | + return couponTemplateMapper.selectListByTakeType(takeType.getType()); |
| 122 | } | 124 | } |
| 123 | 125 | ||
| 124 | @Override | 126 | @Override |