Commit a86ce73542c2bdc5af8817afbcf6c901ab90af70
1 parent
55f26123
【代码优化】商城:优惠券回收之后,领取数量和剩余数量的更新
Showing
1 changed file
with
8 additions
and
7 deletions
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 { |
| 133 | 133 | @Transactional |
| 134 | 134 | public void deleteCoupon(Long id) { |
| 135 | 135 | // 校验存在 |
| 136 | - validateCouponExists(id); | |
| 136 | + CouponDO coupon = validateCouponExists(id); | |
| 137 | 137 | |
| 138 | - // 查询优惠券信息 | |
| 139 | - CouponDO couponDO = couponMapper.selectById(id); | |
| 140 | 138 | // 更新优惠劵 |
| 141 | 139 | int deleteCount = couponMapper.delete(id, |
| 142 | 140 | asList(CouponStatusEnum.UNUSED.getStatus(), CouponStatusEnum.EXPIRE.getStatus())); |
| 143 | 141 | if (deleteCount == 0) { |
| 144 | 142 | throw exception(COUPON_DELETE_FAIL_USED); |
| 145 | 143 | } |
| 146 | - // 传入优惠券模板ID,减少优惠劵模板的领取数量 -1 | |
| 147 | - couponTemplateService.updateCouponTemplateTakeCount(couponDO.getTemplateId(), -1); | |
| 144 | + | |
| 145 | + // 减少优惠劵模板的领取数量 -1 | |
| 146 | + couponTemplateService.updateCouponTemplateTakeCount(coupon.getTemplateId(), -1); | |
| 148 | 147 | } |
| 149 | 148 | |
| 150 | 149 | @Override |
| ... | ... | @@ -152,10 +151,12 @@ public class CouponServiceImpl implements CouponService { |
| 152 | 151 | return couponMapper.selectListByUserIdAndStatus(userId, status); |
| 153 | 152 | } |
| 154 | 153 | |
| 155 | - private void validateCouponExists(Long id) { | |
| 156 | - if (couponMapper.selectById(id) == null) { | |
| 154 | + private CouponDO validateCouponExists(Long id) { | |
| 155 | + CouponDO coupon = couponMapper.selectById(id); | |
| 156 | + if (coupon == null) { | |
| 157 | 157 | throw exception(COUPON_NOT_EXISTS); |
| 158 | 158 | } |
| 159 | + return coupon; | |
| 159 | 160 | } |
| 160 | 161 | |
| 161 | 162 | @Override | ... | ... |