|
|
|
@@ -603,42 +603,52 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY.getCode(),coupon.getTitle()+"["+couponIdStr+"]库存不足"); |
|
|
|
} |
|
|
|
|
|
|
|
int count = 0; |
|
|
|
int unPaidcount = 0; |
|
|
|
// 有价券 |
|
|
|
if (coupon.getSalePrice() > 0) { |
|
|
|
if (!allowUnPayOrder) { |
|
|
|
// 检查是否未支付订单 |
|
|
|
try { |
|
|
|
count = getUserOrderCount(user, coupon); |
|
|
|
unPaidcount = getUserOrderCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询未支付订单失败."); |
|
|
|
} |
|
|
|
if (count > 0) { |
|
|
|
logger.error("此券有未支付的订单, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
if (unPaidcount > 0) { |
|
|
|
logger.error("此券有未支付的订单, couponId: " + couponIdStr + ", count: " + unPaidcount); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_UNPAID.getCode(),"["+coupon.getTitle()+"]您有未支付的订单."); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
//检查拼团中的数量 |
|
|
|
int grouponCount = 0; |
|
|
|
try { |
|
|
|
count = getUserOrderGroupCount(user, coupon); |
|
|
|
grouponCount = getUserOrderGroupCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询拼团中订单错误."); |
|
|
|
} |
|
|
|
if (count >= coupon.getUseLimitQuantity()) { |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
if (grouponCount >= coupon.getUseLimitQuantity()) { |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + grouponCount); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"["+coupon.getTitle()+"]购买超限."); |
|
|
|
} |
|
|
|
|
|
|
|
// 检查用户已购买数量 |
|
|
|
int paidCount = 0; |
|
|
|
try { |
|
|
|
count = getUserCouponOrderCount(user, coupon,number); |
|
|
|
paidCount = getUserCouponOrderCount(user, coupon,number); |
|
|
|
} catch (Exception e) { |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL.getCode(),"["+coupon.getTitle()+"]查询待使用订单错误."); |
|
|
|
} |
|
|
|
if (count > coupon.getUseLimitQuantity()) { |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"此券购买数量已超限["+coupon.getTitle()+"], couponId: " + couponIdStr + ", count: " + count); |
|
|
|
if (paidCount > coupon.getUseLimitQuantity()) { |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + paidCount); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"此券购买数量已超限["+coupon.getTitle()+"], couponId: " + couponIdStr + ", count: " + paidCount); |
|
|
|
} |
|
|
|
|
|
|
|
//如果允许未支付的,则未支付的+已支付的不能超过限购 |
|
|
|
if (allowUnPayOrder) { |
|
|
|
if ((unPaidcount+paidCount) > coupon.getUseLimitQuantity()) { |
|
|
|
logger.error("此券[未支付+已支付]购买数量已超限, couponId: " + couponIdStr + ", count: " + paidCount); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED.getCode(),"此券[未支付+已支付]购买数量已超限["+coupon.getTitle()+"], couponId: " + couponIdStr + ", count: " + paidCount); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
|