【功能修复】商城:指定发卷、新人卷,支持无限发放的兜底

This commit is contained in:
YunaiV 2024-09-11 20:55:28 +08:00
parent 5f7505d4ac
commit 9805f9f512
4 changed files with 19 additions and 10 deletions

View File

@ -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);
}
}

View File

@ -73,7 +73,7 @@ public class AppCouponTemplateController {
// 1.1 处理查询条件商品范围编号
Long productScopeValue = getProductScopeValue(productScope, spuId);
// 1.2 处理查询条件领取方式 = 直接领取
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue());
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType());
// 2. 查询
List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope,
@ -105,7 +105,7 @@ public class AppCouponTemplateController {
// 1.1 处理查询条件商品范围编号
Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId());
// 1.2 处理查询条件领取方式 = 直接领取
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue());
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType());
// 2. 分页查询
PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(

View File

@ -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);
}
}

View File

@ -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<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) {
return couponTemplateMapper.selectListByTakeType(takeType.getValue());
return couponTemplateMapper.selectListByTakeType(takeType.getType());
}
@Override