Skip to content

Commit

Permalink
fix close order bug
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteInternetHK committed Jan 4, 2021
1 parent 2e297ee commit 10f61f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,18 +216,20 @@ public Result getOrder(HttpServletRequest request) {
@Override
public List<Order> getCheckedOrder() throws AlipayApiException {
Date now = new Date();
// 查5分钟前的订单
// 查询10分钟前到5分钟前的订单->关闭
QueryWrapper<Order> 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<Order> 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<Order> orderUpdateWrapper = new UpdateWrapper<>();
orderUpdateWrapper.set("status", 2).lt("create_time", DateUtil.offsetMinute(now, -5)).eq("status", 0);
this.update(orderUpdateWrapper);
Expand Down

0 comments on commit 10f61f9

Please sign in to comment.