Преглед изворни кода

[支付][新增]:支付状态改变后处理,已取消/已退款,库存再加1

release_toaliyun_real
Stormeye.Wu пре 7 година
родитељ
комит
d0cd8383d0
1 измењених фајлова са 31 додато и 27 уклоњено
  1. +31
    -27
      mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java

+ 31
- 27
mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java Прегледај датотеку

@@ -198,37 +198,41 @@ public class WxOrderServiceImpl implements WxOrderService {
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND);
}
Date currentDate = new Date();
/*
// 0:待付款
// 1:已支付
if (enumOrderStatus == EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS) {
updateRecord.setPaymentTime(currentDate);
}
// 2:已取消, 库存加1
if (enumOrderStatus == EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL) {
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(updateRecord.getCouponId());
if (coupon.getRemainInventory() <= 0) {
logger.error("coupon not found, couponId: " + updateRecord.getCouponId());
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY);

switch (enumOrderStatus) {
case ORDER_STATUS_PAYMENT_SUCCESS: {
// 已支付,更新支付时间
updateRecord.setPaymentTime(currentDate);
break;
}
coupon.setRemainInventory(coupon.getRemainInventory() + 1);
wxCouponMapper.updateByPrimaryKeySelective(coupon);
}
// 3:待退款
// 4:已退款
if (enumOrderStatus == EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS) {
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(updateRecord.getCouponId());
if (coupon.getRemainInventory() <= 0) {
logger.error("coupon not found, couponId: " + updateRecord.getCouponId());
throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY);
case ORDER_STATUS_OVERTIME_CANCEL:
case ORDER_STATUS_REFUND_SUCCESS:
{
// 已取消/已退款,库存加1
// 获取订单相关coupon
WxCouponOrder couponOrder = new WxCouponOrder();
couponOrder.setOrderId(orderId);
List<WxCouponOrder> colist = wxCouponOrderMapper.findList(couponOrder);
for(WxCouponOrder couponOrderX : colist) {
String couponIdStr = String.valueOf(couponOrderX.getCouponId());
//加锁
long time = System.currentTimeMillis() + RedisLock.TIMEOUT;
String timeStr = String.valueOf(time);
if(!redisLock.lock(couponIdStr, timeStr)) {
logger.error("此券被锁定, couponId: " + couponIdStr);
throw new MallinkException(ErrorCode.TOO_MANY_REQUEST);
}
WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponOrderX.getCouponId());
coupon.setRemainInventory(coupon.getRemainInventory() + 1);
wxCouponMapper.updateByPrimaryKeySelective(coupon);
//解锁
redisLock.unlock(couponIdStr, timeStr);
}
break;
}
coupon.setRemainInventory(coupon.getRemainInventory() + 1);
wxCouponMapper.updateByPrimaryKeySelective(coupon);
}
// 5:退款失败
updateRecord.setStatus(enumOrderStatus.getCode());
updateRecord.setOrderStatus(enumOrderStatus.getCode());
updateRecord.setUpdateDate(currentDate);
*/
return wxOrderMapper.updateByPrimaryKey(updateRecord);
}



Loading…
Откажи
Сачувај