| @@ -531,7 +531,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| } | } | ||||
| try { | 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) { | } catch (Exception e) { | ||||
| logger.error("数据库更新失败,库存+1失败, e:" + e.getMessage()); | logger.error("数据库更新失败,库存+1失败, e:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "库存恢复失败"); | throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "库存恢复失败"); | ||||
| @@ -526,11 +526,11 @@ | |||||
| </select> | </select> | ||||
| <update id="reduceInventory"> | <update id="reduceInventory"> | ||||
| 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> | </update> | ||||
| <update id="backInventory"> | <update id="backInventory"> | ||||
| 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} | |||||
| </update> | </update> | ||||
| <update id="offExpiriedCouponByValidDate"> | <update id="offExpiriedCouponByValidDate"> | ||||