From d0cd8383d072961dc8390a78f929a07d44385bde Mon Sep 17 00:00:00 2001 From: "Stormeye.Wu" Date: Tue, 14 Aug 2018 17:31:25 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=94=AF=E4=BB=98][=E6=96=B0=E5=A2=9E]:?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E7=8A=B6=E6=80=81=E6=94=B9=E5=8F=98=E5=90=8E?= =?UTF-8?q?=E5=A4=84=E7=90=86=EF=BC=8C=E5=B7=B2=E5=8F=96=E6=B6=88/?= =?UTF-8?q?=E5=B7=B2=E9=80=80=E6=AC=BE,=E5=BA=93=E5=AD=98=E5=86=8D?= =?UTF-8?q?=E5=8A=A01?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/WxOrderServiceImpl.java | 58 ++++++++++--------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java b/mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java index 3b45b9fe4..649a09f68 100644 --- a/mallinkService/src/main/java/com/simple/service/impl/WxOrderServiceImpl.java +++ b/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 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); }