mirror of
https://github.com/YunaiV/ruoyi-vue-pro.git
synced 2026-04-19 13:58:38 +00:00
fix:【mall】优惠劵:相关的判断不对,关联 https://t.zsxq.com/fYaKv
This commit is contained in:
@@ -285,8 +285,8 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
// 校验剩余发放数量是否充足(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
// 校验剩余发放数量是否充足(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
||||||
// 关联案例:https://t.zsxq.com/mElGQ、https://t.zsxq.com/6pLzr
|
// 关联案例:https://t.zsxq.com/mElGQ、https://t.zsxq.com/6pLzr
|
||||||
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
||||||
&& ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 校验不限制领取数
|
&& !couponTemplateService.isTotalCountUnlimited(couponTemplate.getTotalCount()) // 校验不限制总发放数量
|
||||||
&& couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 >= 总发放数量
|
&& couponTemplate.getTakeCount() > couponTemplate.getTotalCount()) { // 已领取数量 > 总发放数量
|
||||||
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
|
throw exception(COUPON_TEMPLATE_NOT_ENOUGH);
|
||||||
}
|
}
|
||||||
// 校验"固定日期"的有效期类型是否过期
|
// 校验"固定日期"的有效期类型是否过期
|
||||||
@@ -304,7 +304,7 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
* @param couponTemplate 优惠劵模版
|
* @param couponTemplate 优惠劵模版
|
||||||
*/
|
*/
|
||||||
private void removeTakeLimitUser(Set<Long> userIds, CouponTemplateDO couponTemplate) {
|
private void removeTakeLimitUser(Set<Long> userIds, CouponTemplateDO couponTemplate) {
|
||||||
if (couponTemplate.getTakeLimitCount() <= 0) {
|
if (couponTemplateService.isTakeLimitCountUnlimited(couponTemplate.getTakeLimitCount())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// 查询已领过券的用户
|
// 查询已领过券的用户
|
||||||
@@ -360,7 +360,8 @@ public class CouponServiceImpl implements CouponService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2.1 过滤领取数量无限制的
|
// 2.1 过滤领取数量无限制的
|
||||||
Set<Long> templateIds = convertSet(templates, CouponTemplateDO::getId, template -> template.getTakeLimitCount() != -1);
|
Set<Long> templateIds = convertSet(templates, CouponTemplateDO::getId,
|
||||||
|
template -> !couponTemplateService.isTakeLimitCountUnlimited(template.getTakeLimitCount()));
|
||||||
// 2.2 检查用户领取的数量是否超过限制
|
// 2.2 检查用户领取的数量是否超过限制
|
||||||
if (CollUtil.isNotEmpty(templateIds)) {
|
if (CollUtil.isNotEmpty(templateIds)) {
|
||||||
Map<Long, Integer> couponTakeCountMap = this.getTakeCountMapByTemplateIds(templateIds, userId);
|
Map<Long, Integer> couponTakeCountMap = this.getTakeCountMapByTemplateIds(templateIds, userId);
|
||||||
|
|||||||
@@ -18,6 +18,23 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public interface CouponTemplateService {
|
public interface CouponTemplateService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否不限制每人领取数量
|
||||||
|
*
|
||||||
|
* @param takeLimitCount 每人限领个数
|
||||||
|
* @return 是否不限制
|
||||||
|
*/
|
||||||
|
boolean isTakeLimitCountUnlimited(Integer takeLimitCount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 判断是否不限制总发放数量
|
||||||
|
*
|
||||||
|
* @param totalCount 发放数量
|
||||||
|
* @return 是否不限制
|
||||||
|
*/
|
||||||
|
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
||||||
|
boolean isTotalCountUnlimited(Integer totalCount);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 创建优惠劵模板
|
* 创建优惠劵模板
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package cn.iocoder.yudao.module.promotion.service.coupon;
|
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.enums.CommonStatusEnum;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi;
|
import cn.iocoder.yudao.module.product.api.category.ProductCategoryApi;
|
||||||
@@ -41,6 +40,16 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
|||||||
@Resource
|
@Resource
|
||||||
private ProductSpuApi productSpuApi;
|
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
|
@Override
|
||||||
public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) {
|
public Long createCouponTemplate(CouponTemplateCreateReqVO createReqVO) {
|
||||||
// 校验商品范围
|
// 校验商品范围
|
||||||
@@ -59,7 +68,7 @@ public class CouponTemplateServiceImpl implements CouponTemplateService {
|
|||||||
CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId());
|
CouponTemplateDO couponTemplate = validateCouponTemplateExists(updateReqVO.getId());
|
||||||
// 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
// 校验发放数量不能过小(仅在 CouponTakeTypeEnum.USER 用户领取时)
|
||||||
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
if (CouponTakeTypeEnum.isUser(couponTemplate.getTakeType())
|
||||||
&& ObjUtil.notEqual(couponTemplate.getTakeLimitCount(), CouponTemplateDO.TAKE_LIMIT_COUNT_MAX) // 非不限制
|
&& !isTotalCountUnlimited(updateReqVO.getTotalCount()) // 非不限制总发放数量
|
||||||
&& updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) {
|
&& updateReqVO.getTotalCount() < couponTemplate.getTakeCount()) {
|
||||||
throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount());
|
throw exception(COUPON_TEMPLATE_TOTAL_COUNT_TOO_SMALL, couponTemplate.getTakeCount());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user