From 04fdc70f582bc869495c07d8178c8732eaa64dba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Thu, 8 Aug 2024 14:13:09 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=9B=9E=E6=94=B6=E5=90=8E=EF=BC=8C=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=92=8C=E5=89=A9=E4=BD=99=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/promotion/service/coupon/CouponServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 1ce9d6959..82402d3f4 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 @@ -140,8 +140,8 @@ public class CouponServiceImpl implements CouponService { if (deleteCount == 0) { throw exception(COUPON_DELETE_FAIL_USED); } - // 减少优惠劵模板的领取数量 -1 - couponTemplateService.updateCouponTemplateTakeCount(id, -1); + // 传入优惠券模板ID,减少优惠劵模板的领取数量 -1 + couponTemplateService.updateCouponTemplateTakeCount(couponMapper.selectById(id).getTemplateId(), -1); } @Override From 960668787845afeebabf97378ea0835a08d0225f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8D=A2=E8=B6=8A?= <552369664@qq.com> Date: Thu, 8 Aug 2024 15:17:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BC=98=E6=83=A0?= =?UTF-8?q?=E5=88=B8=E5=9B=9E=E6=94=B6=E5=90=8E=EF=BC=8C=E9=A2=86=E5=8F=96?= =?UTF-8?q?=E6=95=B0=E9=87=8F=E5=92=8C=E5=89=A9=E4=BD=99=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E4=B8=8D=E6=9B=B4=E6=96=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/promotion/dal/dataobject/coupon/CouponDO.java | 2 ++ .../module/promotion/service/coupon/CouponServiceImpl.java | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) 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