diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponDO.java index 31cef2e78..296d2a2fd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/coupon/CouponDO.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.enums.coupon.CouponStatusEnum; import cn.iocoder.yudao.module.promotion.enums.coupon.CouponTakeTypeEnum; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableField; +import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; import lombok.Data; import lombok.EqualsAndHashCode; @@ -30,6 +31,7 @@ public class CouponDO extends BaseDO { /** * 优惠劵编号 */ + @TableId private Long id; /** * 优惠劵模板编号 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 82402d3f4..6b1b0b64d 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 @@ -25,6 +25,7 @@ import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; import jakarta.annotation.Resource; + import java.time.LocalDateTime; import java.util.*; import java.util.stream.Collectors; @@ -134,6 +135,8 @@ public class CouponServiceImpl implements CouponService { // 校验存在 validateCouponExists(id); + // 查询优惠券信息 + CouponDO couponDO = couponMapper.selectById(id); // 更新优惠劵 int deleteCount = couponMapper.delete(id, asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus())); @@ -141,7 +144,7 @@ public class CouponServiceImpl implements CouponService { throw exception(COUPON_DELETE_FAIL_USED); } // 传入优惠券模板ID,减少优惠劵模板的领取数量 -1 - couponTemplateService.updateCouponTemplateTakeCount(couponMapper.selectById(id).getTemplateId(), -1); + couponTemplateService.updateCouponTemplateTakeCount(couponDO.getTemplateId(), -1); } @Override