diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponTakeTypeEnum.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponTakeTypeEnum.java index 1513e62ea..eff4137ac 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/enums/coupon/CouponTakeTypeEnum.java +++ b/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; import lombok.Getter; import java.util.Arrays; +import java.util.Objects; /** * 优惠劵领取方式 @@ -20,12 +21,12 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { REGISTER(3, "新人券"), // 注册时自动领取 ; - public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTakeTypeEnum::getValue).toArray(); + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(CouponTakeTypeEnum::getType).toArray(); /** * 值 */ - private final Integer value; + private final Integer type; /** * 名字 */ @@ -35,4 +36,9 @@ public enum CouponTakeTypeEnum implements IntArrayValuable { public int[] array() { return ARRAYS; } + + public static boolean isUser(Integer type) { + return Objects.equals(USER.getType(), type); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java index 586618e92..a03a68adb 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/coupon/AppCouponTemplateController.java +++ b/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 { // 1.1 处理查询条件:商品范围编号 Long productScopeValue = getProductScopeValue(productScope, spuId); // 1.2 处理查询条件:领取方式 = 直接领取 - List canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue()); + List canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType()); // 2. 查询 List list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope, @@ -105,7 +105,7 @@ public class AppCouponTemplateController { // 1.1 处理查询条件:商品范围编号 Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId()); // 1.2 处理查询条件:领取方式 = 直接领取 - List canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue()); + List canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType()); // 2. 分页查询 PageResult pageResult = couponTemplateService.getCouponTemplatePage( diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java index e6cd4ba0e..3945aa06b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java +++ b/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 { if (couponTemplate == null) { throw exception(COUPON_TEMPLATE_NOT_EXISTS); } - // 校验剩余数量 - if (couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) { + // 校验剩余数量(仅在 CouponTakeTypeEnum.USER 用户领取时) + if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeCount()) + && couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) { throw exception(COUPON_TEMPLATE_NOT_ENOUGH); } // 校验"固定日期"的有效期类型是否过期 @@ -295,7 +296,7 @@ public class CouponServiceImpl implements CouponService { } } // 校验领取方式 - if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getValue())) { + if (ObjectUtil.notEqual(couponTemplate.getTakeType(), takeType.getType())) { throw exception(COUPON_TEMPLATE_CANNOT_TAKE); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java index 923ee5904..019c45dae 100755 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponTemplateServiceImpl.java +++ b/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 { public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) { // 校验存在 CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId()); - // 校验发放数量不能过小 - if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { + // 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时) + if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType()) + && updateReqVO.getTotalCount() > 0 // 大于 0 的原因,是因为 -1 不限制 + && updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) { throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount()); } // 校验商品范围 @@ -118,7 +120,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService { @Override public List getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) { - return couponTemplateMapper.selectListByTakeType(takeType.getValue()); + return couponTemplateMapper.selectListByTakeType(takeType.getType()); } @Override