From a86ce73542c2bdc5af8817afbcf6c901ab90af70 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 8 Aug 2024 23:35:20 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90=E4=BB=A3=E7=A0=81=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E3=80=91=E5=95=86=E5=9F=8E=EF=BC=9A=E4=BC=98=E6=83=A0=E5=88=B8?= =?UTF-8?q?=E5=9B=9E=E6=94=B6=E4=B9=8B=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?=E7=9A=84=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/coupon/CouponServiceImpl.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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 6b1b0b64d..abf933d83 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 @@ -133,18 +133,17 @@ public class CouponServiceImpl implements CouponService { @Transactional public void deleteCoupon(Long id) { // 校验存在 - validateCouponExists(id); + CouponDO coupon = validateCouponExists(id); - // 查询优惠券信息 - CouponDO couponDO = couponMapper.selectById(id); // 更新优惠劵 int deleteCount = couponMapper.delete(id, asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus())); if (deleteCount == 0) { throw exception(COUPON_DELETE_FAIL_USED); } - // 传入优惠券模板ID,减少优惠劵模板的领取数量 -1 - couponTemplateService.updateCouponTemplateTakeCount(couponDO.getTemplateId(), -1); + + // 减少优惠劵模板的领取数量 -1 + couponTemplateService.updateCouponTemplateTakeCount(coupon.getTemplateId(), -1); } @Override @@ -152,10 +151,12 @@ public class CouponServiceImpl implements CouponService { return couponMapper.selectListByUserIdAndStatus(userId, status); } - private void validateCouponExists(Long id) { - if (couponMapper.selectById(id) == null) { + private CouponDO validateCouponExists(Long id) { + CouponDO coupon = couponMapper.selectById(id); + if (coupon == null) { throw exception(COUPON_NOT_EXISTS); } + return coupon; } @Override