|
|
|
@@ -23,9 +23,7 @@ import org.springframework.stereotype.Service; |
|
|
|
import org.springframework.transaction.annotation.Propagation; |
|
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
import java.util.Calendar; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
@Service |
|
|
|
public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
@@ -83,6 +81,7 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
// + couponOrder ---待使用 |
|
|
|
int countOrder = 0, countCouponOrder = 0; |
|
|
|
WxOrder orderQ = new WxOrder(); |
|
|
|
orderQ.setTenantId(user.getTenantId()); |
|
|
|
orderQ.setCouponId(counpon.getId()); |
|
|
|
orderQ.setCUserId(user.getId()); |
|
|
|
orderQ.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); |
|
|
|
@@ -93,12 +92,21 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
WxCouponOrder couponOrderQ = new WxCouponOrder(); |
|
|
|
couponOrderQ.setCouponId(counpon.getId()); |
|
|
|
couponOrderQ.setCUserId(user.getId()); |
|
|
|
//////couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); |
|
|
|
try { |
|
|
|
countCouponOrder = wxCouponOrderMapper.countList(couponOrderQ); |
|
|
|
if (counpon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) { |
|
|
|
// 停车券 每日限领1张 |
|
|
|
Map params = new HashMap<String, Object>(); |
|
|
|
params.put("couponId", counpon.getId()); |
|
|
|
params.put("cUserId", user.getId()); |
|
|
|
countCouponOrder = wxCouponOrderMapper.countCarList(params); |
|
|
|
} else { |
|
|
|
WxCouponOrder couponOrderQ = new WxCouponOrder(); |
|
|
|
couponOrderQ.setTenantId(user.getTenantId()); |
|
|
|
couponOrderQ.setCouponId(counpon.getId()); |
|
|
|
couponOrderQ.setCUserId(user.getId()); |
|
|
|
//////couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); |
|
|
|
countCouponOrder = wxCouponOrderMapper.countList(couponOrderQ); |
|
|
|
} |
|
|
|
} catch (Exception e) { |
|
|
|
logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage()); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_FAIL); |
|
|
|
@@ -125,22 +133,27 @@ public class WxOrderServiceImpl implements WxOrderService { |
|
|
|
} |
|
|
|
|
|
|
|
// check 购买是否超限 |
|
|
|
int count = 0; |
|
|
|
try { |
|
|
|
count = getUserCouponOrderCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
if (coupon.getType().equals(EnumCouponType.COUPON_TINGCHE.getCode())) { |
|
|
|
|
|
|
|
if (count >= coupon.getUseLimitQuantity()) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED); |
|
|
|
} else { |
|
|
|
int count = 0; |
|
|
|
try { |
|
|
|
count = getUserCouponOrderCount(user, coupon); |
|
|
|
} catch (Exception e) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
throw new MallinkException(ErrorCode.DB_FAIL); |
|
|
|
} |
|
|
|
|
|
|
|
if (count >= coupon.getUseLimitQuantity()) { |
|
|
|
//解锁 |
|
|
|
redisLock.unlock(couponIdStr, timeStr); |
|
|
|
logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count); |
|
|
|
throw new MallinkException(ErrorCode.ORDER_IS_LIMITED); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
try { |
|
|
|
// 减库存 |
|
|
|
coupon.setRemainInventory(coupon.getRemainInventory() - 1); |
|
|
|
|