From 10f61f94c761aae064cec86f86ec12b653cc09b7 Mon Sep 17 00:00:00 2001 From: ByteInternetHK Date: Mon, 4 Jan 2021 21:49:45 +0800 Subject: [PATCH] fix close order bug --- .../panel/common/payment/alipay/Alipay.java | 23 ++++++++++++++++--- .../panel/serviceImpl/OrderServiceImpl.java | 10 ++++---- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/project/daihao18/panel/common/payment/alipay/Alipay.java b/src/main/java/project/daihao18/panel/common/payment/alipay/Alipay.java index d6104d2..94d9549 100644 --- a/src/main/java/project/daihao18/panel/common/payment/alipay/Alipay.java +++ b/src/main/java/project/daihao18/panel/common/payment/alipay/Alipay.java @@ -305,13 +305,30 @@ public AlipayTradeQueryResponse query(CommonOrder order) throws AlipayApiExcepti public AlipayTradeCloseResponse close(CommonOrder order) throws AlipayApiException { AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); AlipayTradeCloseModel model = new AlipayTradeCloseModel(); - model.setOutTradeNo(order.getId()); + model.setOutTradeNo(order.getId() + "_0"); request.setBizModel(model); // 设置alipayClient + // 关闭2次 + AlipayTradeCloseResponse execute = null; if (isCertMode) { - return alipayClient.certificateExecute(request); + execute = alipayClient.certificateExecute(request); } else { - return alipayClient.execute(request); + execute = alipayClient.execute(request); + } + if (!"40004".equals(execute.getCode())) { + return execute; + } else { + model.setOutTradeNo(order.getId() + "_1"); + request.setBizModel(model); + if (isCertMode) { + execute = alipayClient.certificateExecute(request); + } else { + execute = alipayClient.execute(request); + } + if (!"40004".equals(execute.getCode())) { + return execute; + } } + return null; } } \ No newline at end of file diff --git a/src/main/java/project/daihao18/panel/serviceImpl/OrderServiceImpl.java b/src/main/java/project/daihao18/panel/serviceImpl/OrderServiceImpl.java index 0174406..7ab4ff1 100644 --- a/src/main/java/project/daihao18/panel/serviceImpl/OrderServiceImpl.java +++ b/src/main/java/project/daihao18/panel/serviceImpl/OrderServiceImpl.java @@ -216,18 +216,20 @@ public Result getOrder(HttpServletRequest request) { @Override public List getCheckedOrder() throws AlipayApiException { Date now = new Date(); - // 查5分钟前的订单 + // 查询10分钟前到5分钟前的订单->关闭 QueryWrapper orderQueryWrapper = new QueryWrapper<>(); - orderQueryWrapper.lt("create_time", DateUtil.offsetMinute(now, -5)).in("status", 0, 2); + orderQueryWrapper.between("create_time", DateUtil.offsetMinute(now, -10), DateUtil.offsetMinute(now, -5)).in("status", 0, 2); List orders = this.list(orderQueryWrapper); for (Order order : orders) { // 关闭支付宝订单 CommonOrder commonOrder = new CommonOrder(); commonOrder.setId(order.getOrderId()); AlipayTradeCloseResponse close = alipay.close(commonOrder); - log.debug("closeResponse: {}", close.toString()); + if (ObjectUtil.isNotEmpty(close)) { + log.debug("closeResponse: {}", close.getBody()); + } } - // 关闭本地订单 + // 关闭5分钟前本地订单 UpdateWrapper orderUpdateWrapper = new UpdateWrapper<>(); orderUpdateWrapper.set("status", 2).lt("create_time", DateUtil.offsetMinute(now, -5)).eq("status", 0); this.update(orderUpdateWrapper);