!1034 修复优惠券回收之后,领取数量和剩余数量不更新的问题

Merge pull request !1034 from 卢越/master-jdk17
This commit is contained in:
芋道源码 2024-08-08 15:32:39 +00:00 committed by Gitee
commit 55f2612369
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 7 additions and 2 deletions

View File

@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum;
import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum;
import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.KeySequence;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data; import lombok.Data;
import lombok.EqualsAndHashCode; import lombok.EqualsAndHashCode;
@ -30,6 +31,7 @@ public class CouponDO extends BaseDO {
/** /**
* 优惠劵编号 * 优惠劵编号
*/ */
@TableId
private Long id; private Long id;
/** /**
* 优惠劵模板编号 * 优惠劵模板编号

View File

@ -25,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional;
import org.springframework.validation.annotation.Validated; import org.springframework.validation.annotation.Validated;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.*; import java.util.*;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -134,14 +135,16 @@ public class CouponServiceImpl implements CouponService {
// 校验存在 // 校验存在
validateCouponExists(id); validateCouponExists(id);
// 查询优惠券信息
CouponDO couponDO = couponMapper.selectById(id);
// 更新优惠劵 // 更新优惠劵
int deleteCount = couponMapper.delete(id, int deleteCount = couponMapper.delete(id,
asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus())); asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus()));
if (deleteCount == 0) { if (deleteCount == 0) {
throw exception(COUPON_DELETE_FAIL_USED); throw exception(COUPON_DELETE_FAIL_USED);
} }
// 减少优惠劵模板的领取数量 -1 // 传入优惠券模板ID减少优惠劵模板的领取数量 -1
couponTemplateService.updateCouponTemplateTakeCount(id, -1); couponTemplateService.updateCouponTemplateTakeCount(couponDO.getTemplateId(), -1);
} }
@Override @Override