mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-12-01 19:51:53 +08:00
【功能修复】商城:指定发卷、新人卷,支持无限发放的兜底
This commit is contained in:
parent
5f7505d4ac
commit
9805f9f512
@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 优惠劵领取方式
|
* 优惠劵领取方式
|
||||||
@ -20,12 +21,12 @@ public enum CouponTakeTypeEnum implements IntArrayValuable {
|
|||||||
REGISTER(3, "新人券"), // 注册时自动领取
|
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() {
|
public int[] array() {
|
||||||
return ARRAYS;
|
return ARRAYS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isUser(Integer type) {
|
||||||
|
return Objects.equals(USER.getType(), type);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ public class AppCouponTemplateController {
|
|||||||
// 1.1 处理查询条件:商品范围编号
|
// 1.1 处理查询条件:商品范围编号
|
||||||
Long productScopeValue = getProductScopeValue(productScope, spuId);
|
Long productScopeValue = getProductScopeValue(productScope, spuId);
|
||||||
// 1.2 处理查询条件:领取方式 = 直接领取
|
// 1.2 处理查询条件:领取方式 = 直接领取
|
||||||
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue());
|
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType());
|
||||||
|
|
||||||
// 2. 查询
|
// 2. 查询
|
||||||
List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope,
|
List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(canTakeTypes, productScope,
|
||||||
@ -105,7 +105,7 @@ public class AppCouponTemplateController {
|
|||||||
// 1.1 处理查询条件:商品范围编号
|
// 1.1 处理查询条件:商品范围编号
|
||||||
Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId());
|
Long productScopeValue = getProductScopeValue(pageReqVO.getProductScope(), pageReqVO.getSpuId());
|
||||||
// 1.2 处理查询条件:领取方式 = 直接领取
|
// 1.2 处理查询条件:领取方式 = 直接领取
|
||||||
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getValue());
|
List<Integer> canTakeTypes = singletonList(CouponTakeTypeEnum.USER.getType());
|
||||||
|
|
||||||
// 2. 分页查询
|
// 2. 分页查询
|
||||||
PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(
|
PageResult<CouponTemplateDO> pageResult = couponTemplateService.getCouponTemplatePage(
|
||||||
|
@ -284,8 +284,9 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
if (couponTemplate == null) {
|
if (couponTemplate == null) {
|
||||||
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
throw exception(COUPON_TEMPLATE_NOT_EXISTS);
|
||||||
}
|
}
|
||||||
// 校验剩余数量
|
// 校验剩余数量(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
||||||
if (couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
|
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeCount())
|
||||||
|
&& couponTemplate.getTakeCount() + userIds.size() > couponTemplate.getTotalCount()) {
|
||||||
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
|
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);
|
throw exception(COUPON_TEMPLATE_CANNOT_TAKE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -57,8 +57,10 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
|||||||
public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) {
|
public void updateCouponTemplate(CouponTemplateUpdateReqVO updateReqVO) {
|
||||||
// 校验存在
|
// 校验存在
|
||||||
CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId());
|
CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId());
|
||||||
// 校验发放数量不能过小
|
// 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
||||||
if (updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) {
|
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
||||||
|
&& updateReqVO.getTotalCount() > 0 // 大于 0 的原因,是因为 -1 不限制
|
||||||
|
&& updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) {
|
||||||
throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount());
|
throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount());
|
||||||
}
|
}
|
||||||
// 校验商品范围
|
// 校验商品范围
|
||||||
@ -118,7 +120,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) {
|
public List<CouponTemplateDO> getCouponTemplateListByTakeType(CouponTakeTypeEnum takeType) {
|
||||||
return couponTemplateMapper.selectListByTakeType(takeType.getValue());
|
return couponTemplateMapper.selectListByTakeType(takeType.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user