From a1f41a598c4eb9613830f9fa33326b64ca543835 Mon Sep 17 00:00:00 2001 From: Stormeye Wu Date: Mon, 16 Dec 2019 21:24:43 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=87=8F=E5=BA=93=E5=AD=98=E8=BF=98=E6=98=AF?= =?UTF-8?q?=E4=B8=8D=E5=AF=B9][=E4=BF=AE=E6=94=B9]:=E6=81=A2=E5=A4=8D?= =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=89=88=E6=9C=AC,=20=E5=87=8F=E5=A4=9A?= =?UTF-8?q?=E4=BA=86=EF=BC=8C=E5=B9=BF=E5=9C=BA=E6=96=B9=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/iformall/service/impl/WxOrderServiceImpl.java | 8 +++++++- .../src/main/resources/mapper/WxCouponMapper.xml | 4 ++-- 2 files changed, 9 insertions(+), 3 deletions(-) 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}