diff --git a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java b/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java index 93e00cc1cf..c3aa766cd2 100644 --- a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java +++ b/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 { // 校验剩余发放数量是否充足(仅在 CouponTakeTypeEnum.USER 用户领取时) // 关联案例:https://t.zsxq.com/mElGQ、https://t.zsxq.com/6pLzr if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) - && ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 校验不限制领取数 - && couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 >= 总发放数量 + && !couponTemplateService.isTotalCountUnlimited(couponTemplate.getTotalCount()) // 校验不限制总发放数量 + && couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 > 总发放数量 throw exception(COUPON_TEMPLATE_NOT_ENOUGH); } // 校验"固定日期"的有效期类型是否过期 @@ -304,7 +304,7 @@ public class CouponServiceImpl implements CouponService { * @param couponTemplate 优惠劵模版 */ private void removeTakeLimitUser(Set userIds, CouponTemplateDO couponTemplate) { - if (couponTemplate.getTakeLimitCount() <= 0) { + if (couponTemplateService.isTakeLimitCountUnlimited(couponTemplate.getTakeLimitCount())) { return; } // 查询已领过券的用户 @@ -360,7 +360,8 @@ public class CouponServiceImpl implements CouponService { } // 2.1 过滤领取数量无限制的 - Set templateIds = convertSet(templates, CouponTemplateDO::getId, template -> template.getTakeLimitCount() != -1); + Set templateIds = convertSet(templates, CouponTemplateDO::getId, + template -> !couponTemplateService.isTakeLimitCountUnlimited(template.getTakeLimitCount())); // 2.2 检查用户领取的数量是否超过限制 if (CollUtil.isNotEmpty(templateIds)) { Map couponTakeCountMap = this.getTakeCountMapByTemplateIds(templateIds, userId); diff --git a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java b/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java index 085979ef02..cce2cf59ef 100755 --- a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java +++ b/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateService.java @@ -18,6 +18,23 @@ import java.util.List; */ public interface CouponTemplateService { + /** + * 判断是否不限制每人领取数量 + * + * @param takeLimitCount 每人限领个数 + * @return 是否不限制 + */ + boolean isTakeLimitCountUnlimited(Integer takeLimitCount); + + /** + * 判断是否不限制总发放数量 + * + * @param totalCount 发放数量 + * @return 是否不限制 + */ + @SuppressWarnings("BooleanMethodIsAlwaysInverted") + boolean isTotalCountUnlimited(Integer totalCount); + /** * 创建优惠劵模板 * diff --git a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java b/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java index bdd8b32825..8c25cb8646 100755 --- a/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java @@ -1,6 +1,5 @@ package cn.iocoder.yudao.module.promotion.service.coupon; -import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi; @@ -41,6 +40,16 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { @Resource private ProductSpuApi productSpuApi; + @Override + public boolean isTakeLimitCountUnlimited(Integer takeLimitCount) { + return CouponTemplateDO.TAKE_LIMIT_COUNT_MAX.equals(takeLimitCount); + } + + @Override + public boolean isTotalCountUnlimited(Integer totalCount) { + return CouponTemplateDO.TOTAL_COUNT_MAX.equals(totalCount); + } + @Override public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) { // 校验商品范围 @@ -59,7 +68,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); // 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时) if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) - && ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 非不限制 + && !isTotalCountUnlimited(updateReqVO.getTotalCount()) // 非不限制总发放数量 && updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); }