From 9805f9f512705fd514b2971a1ae96b0985be639c Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 11 Sep 2024 20:55:28 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9A=E6=8C=87=E5=AE=9A=E5=8F=91?= =?UTF-8?q?=E5=8D=B7=E3=80=81=E6=96=B0=E4=BA=BA=E5=8D=B7=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E6=97=A0=E9=99=90=E5=8F=91=E6=94=BE=E7=9A=84=E5=85=9C?= =?UTF-8?q?=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../promotion/enums/coupon/CouponTakeTypeEnum.java | 10 ++++++++-- .../app/coupon/AppCouponTemplateController.java | 4 ++-- .../promotion/service/coupon/CouponServiceImpl.java | 7 ++++--- .../service/coupon/CouponTemplateServiceImpl.java | 8 +++++--- 4 files changed, 19 insertions(+), 10 deletions(-) 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