mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-22 15:21:53 +08:00
【代码优化】商城:优惠券回收之后,领取数量和剩余数量的更新
This commit is contained in:
parent
55f2612369
commit
a86ce73542
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user