|
|
|
@@ -87,22 +87,43 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
Date curr = new Date(); |
|
|
|
Date valid_date = null; |
|
|
|
|
|
|
|
// 检查 优惠券 库存 |
|
|
|
if (coupon.getRemainInventory() <= 0) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
logger.error("此券库存为0, couponId: " + couponIdStr); |
|
|
|
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); |
|
|
|
} |
|
|
|
|
|
|
|
// check 购买是否超限 |
|
|
|
try { |
|
|
|
// 检查 优惠券 库存 |
|
|
|
if (coupon.getRemainInventory() <= 0) { |
|
|
|
WxCouponOrder query = new WxCouponOrder(); |
|
|
|
query.setCouponId(couponId); |
|
|
|
query.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); |
|
|
|
List<WxCouponOrder> list = wxCouponOrderMapper.findList(query); |
|
|
|
if (list.size() >= coupon.getUseLimitQuantity()) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
|
|
|
|
logger.error("此券库存为0, couponId: " + couponIdStr); |
|
|
|
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED); |
|
|
|
} |
|
|
|
}catch (Exception e) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
logger.error("此券购买数量检查出问题了, couponId: " + couponIdStr); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 减库存 |
|
|
|
coupon.setRemainInventory(coupon.getRemainInventory() - 1); |
|
|
|
wxCouponMapper.updateByPrimaryKeySelective(coupon); |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
} catch (RuntimeException e) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
|
|
|
|
logger.error("此券减库存失败, couponId: " + couponIdStr); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); |
|
|
|
} |
|
|
|
@@ -118,6 +139,10 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
WxOrder record = new WxOrder(); |
|
|
|
|
|
|
|
|
|
|
|
// body |
|
|
|
// tenant_id + merchant_id + title + subtitle |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 保存订单 |
|
|
|
record.setId(orderNumber); |
|
|
|
|