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 e7d4bfe2a..0dbee96e3 100644 --- a/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java +++ b/mallinkService/src/main/java/com/iformall/service/impl/WxOrderServiceImpl.java @@ -487,12 +487,17 @@ public class WxOrderServiceImpl implements WxOrderService { try { // 减库存 - wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory()); + int num = wxCouponMapper.reduceInventory(coupon.getId(), 1, coupon.getRemainInventory()); + if (num <= 0) { + logger.error("此券减库存失败, couponId: " + couponIdStr); + throw new MallinkException(ErrorCode.ORDER_IS_FAIL); + } } catch (RuntimeException e) { - // 解锁 - redisLock.unlock(couponIdStr, timeStr); logger.error("此券减库存失败, couponId: " + couponIdStr); throw new MallinkException(ErrorCode.ORDER_IS_FAIL); + } finally { + // 解锁 + redisLock.unlock(couponIdStr, timeStr); } } @@ -527,8 +532,6 @@ public class WxOrderServiceImpl implements WxOrderService { try { 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); } diff --git a/mallinkService/src/main/java/com/iformall/utils/RedisLock.java b/mallinkService/src/main/java/com/iformall/utils/RedisLock.java index e8e8b99af..67e2f388b 100644 --- a/mallinkService/src/main/java/com/iformall/utils/RedisLock.java +++ b/mallinkService/src/main/java/com/iformall/utils/RedisLock.java @@ -34,7 +34,6 @@ public class RedisLock { public boolean lock(String key,String value){ ValueOperations operations = stringRedisTemplate.opsForValue(); if(operations.setIfAbsent(key,value)){//对应setnx命令 - operations.set(key, value, 1, TimeUnit.SECONDS); //可以成功设置,也就是key不存在 return true; }