Commit 3accf80700fda60960042a929be081656d74bf88
1 parent
9fe59e85
fix:【mall】优惠劵:相关的判断不对,关联 https://t.zsxq.com/fYaKv
Showing
3 changed files
with
33 additions
and
6 deletions
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
| ... | ... | @@ -285,8 +285,8 @@ public class CouponServiceImpl implements CouponService { |
| 285 | 285 | // 校验剩余发放数量是否充足(仅在 CouponTakeTypeEnum.USER 用户领取时) |
| 286 | 286 | // 关联案例:https://t.zsxq.com/mElGQ、https://t.zsxq.com/6pLzr |
| 287 | 287 | if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) |
| 288 | - && ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 校验不限制领取数 | |
| 289 | - && couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 >= 总发放数量 | |
| 288 | + && !couponTemplateService.isTotalCountUnlimited(couponTemplate.getTotalCount()) // 校验不限制总发放数量 | |
| 289 | + && couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 > 总发放数量 | |
| 290 | 290 | throw exception(COUPON_TEMPLATE_NOT_ENOUGH); |
| 291 | 291 | } |
| 292 | 292 | // 校验"固定日期"的有效期类型是否过期 |
| ... | ... | @@ -304,7 +304,7 @@ public class CouponServiceImpl implements CouponService { |
| 304 | 304 | * @param couponTemplate 优惠劵模版 |
| 305 | 305 | */ |
| 306 | 306 | private void removeTakeLimitUser(Set<Long> userIds, CouponTemplateDO couponTemplate) { |
| 307 | - if (couponTemplate.getTakeLimitCount() <= 0) { | |
| 307 | + if (couponTemplateService.isTakeLimitCountUnlimited(couponTemplate.getTakeLimitCount())) { | |
| 308 | 308 | return; |
| 309 | 309 | } |
| 310 | 310 | // 查询已领过券的用户 |
| ... | ... | @@ -360,7 +360,8 @@ public class CouponServiceImpl implements CouponService { |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | // 2.1 过滤领取数量无限制的 |
| 363 | - Set<Long> templateIds = convertSet(templates, CouponTemplateDO::getId, template -> template.getTakeLimitCount() != -1); | |
| 363 | + Set<Long> templateIds = convertSet(templates, CouponTemplateDO::getId, | |
| 364 | + template -> !couponTemplateService.isTakeLimitCountUnlimited(template.getTakeLimitCount())); | |
| 364 | 365 | // 2.2 检查用户领取的数量是否超过限制 |
| 365 | 366 | if (CollUtil.isNotEmpty(templateIds)) { |
| 366 | 367 | Map<Long, Integer> couponTakeCountMap = this.getTakeCountMapByTemplateIds(templateIds, userId); | ... | ... |
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java
| ... | ... | @@ -19,6 +19,23 @@ import java.util.List; |
| 19 | 19 | public interface CouponTemplateService { |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | + * 判断是否不限制每人领取数量 | |
| 23 | + * | |
| 24 | + * @param takeLimitCount 每人限领个数 | |
| 25 | + * @return 是否不限制 | |
| 26 | + */ | |
| 27 | + boolean isTakeLimitCountUnlimited(Integer takeLimitCount); | |
| 28 | + | |
| 29 | + /** | |
| 30 | + * 判断是否不限制总发放数量 | |
| 31 | + * | |
| 32 | + * @param totalCount 发放数量 | |
| 33 | + * @return 是否不限制 | |
| 34 | + */ | |
| 35 | + @SuppressWarnings("BooleanMethodIsAlwaysInverted") | |
| 36 | + boolean isTotalCountUnlimited(Integer totalCount); | |
| 37 | + | |
| 38 | + /** | |
| 22 | 39 | * 创建优惠劵模板 |
| 23 | 40 | * |
| 24 | 41 | * @param createReqVO 创建信息 | ... | ... |
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java
| 1 | 1 | package cn.iocoder.yudao.module.promotion.service.coupon; |
| 2 | 2 | |
| 3 | -import cn.hutool.core.util.ObjUtil; | |
| 4 | 3 | import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; |
| 5 | 4 | import cn.iocoder.yudao.framework.common.pojo.PageResult; |
| 6 | 5 | import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; |
| ... | ... | @@ -42,6 +41,16 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { |
| 42 | 41 | private ProductSpuApi productSpuApi; |
| 43 | 42 | |
| 44 | 43 | @Override |
| 44 | + public boolean isTakeLimitCountUnlimited(Integer takeLimitCount) { | |
| 45 | + return CouponTemplateDO.TAKE_LIMIT_COUNT_MAX.equals(takeLimitCount); | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Override | |
| 49 | + public boolean isTotalCountUnlimited(Integer totalCount) { | |
| 50 | + return CouponTemplateDO.TOTAL_COUNT_MAX.equals(totalCount); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Override | |
| 45 | 54 | public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { |
| 46 | 55 | // 校验商品范围 |
| 47 | 56 | validateProductScope(createReqVO.getProductScope(), createReqVO.getProductScopeValues()); |
| ... | ... | @@ -59,7 +68,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { |
| 59 | 68 | CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); |
| 60 | 69 | // 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时) |
| 61 | 70 | if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) |
| 62 | - && ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 非不限制 | |
| 71 | + && !isTotalCountUnlimited(updateReqVO.getTotalCount()) // 非不限制总发放数量 | |
| 63 | 72 | && updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { |
| 64 | 73 | throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); |
| 65 | 74 | } | ... | ... |