| @@ -198,37 +198,41 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| Date currentDate = new Date(); | 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); | updateRecord.setUpdateDate(currentDate); | ||||
| */ | |||||
| return wxOrderMapper.updateByPrimaryKey(updateRecord); | return wxOrderMapper.updateByPrimaryKey(updateRecord); | ||||
| } | } | ||||