diff --git a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java index 554a3ebbe..d83183692 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -531,7 +531,13 @@ public class WxOrderServiceImpl implements WxOrderService { } try { - wxCouponMapper.backInventory(coupon.getId(), 1, coupon.getRemainInventory()); + int num = wxCouponMapper.backInventory(coupon.getId(), 1, coupon.getRemainInventory()); + if (num <= 0) { + // 解锁 + redisLock.unlock(couponIdStr, timeStr); + logger.error("此券加库存失败, couponId: " + couponIdStr); + throw new MallinkException(ErrorCode.ORDER_IS_FAIL); + } } catch (Exception e) { logger.error("数据库更新失败,库存+1失败, e:" + e.getMessage()); throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "库存恢复失败"); diff --git a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml index 8e5506d6f..33619e3c0 100644 --- a/mallinkService/src/main/resources/mapper/WxCouponMapper.xml +++ b/mallinkService/src/main/resources/mapper/WxCouponMapper.xml @@ -526,11 +526,11 @@ - update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory= #{remainInventory} + update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory - #{number} >= 0 - update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory= #{remainInventory} + update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory + #{number} <= #{inventory}