Commit 8531eaef71a11f6a92813217b372421ab516573d

Authored by 芋道源码
Committed by GitHub
2 parents 3fb2a88e 5f803e17

Merge pull request #1317 from dadiyang/fix/coupon-delete-with-deleted-template

[BUG] 优惠券:券的模板被删除后,这张券就删不掉了
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/coupon/CouponServiceImpl.java
... ... @@ -115,7 +115,11 @@ public class CouponServiceImpl implements CouponService {
115 115 }
116 116  
117 117 // 减少优惠劵模板的领取数量 -1
118   - couponTemplateService.updateCouponTemplateTakeCount(coupon.getTemplateId(), -1);
  118 + // 若模板已被删除则跳过:已删模板的领取计数无业务意义,
  119 + // 且 updateTakeCount 对逻辑删除的模板匹配 0 行,会误报「优惠券模板剩余数量不足」导致删券失败
  120 + if (couponTemplateService.getCouponTemplate(coupon.getTemplateId()) != null) {
  121 + couponTemplateService.updateCouponTemplateTakeCount(coupon.getTemplateId(), -1);
  122 + }
119 123 }
120 124  
121 125 @Override
... ...