|
@@ -171,6 +171,10 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
if (null == detail) {
|
|
|
return HttpResponseResult.failed("未找到订单信息");
|
|
|
}
|
|
|
+ if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
|
|
|
+ return HttpResponseResult.failed("订单已完成");
|
|
|
+ }
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
try {
|
|
|
Map<String, Object> resMap = paymentSdk.queryPayment(detail.getTransNo());
|
|
@@ -179,14 +183,14 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
orderSuccess(detail);
|
|
|
return HttpResponseResult.failed("订单已经交易完成");
|
|
|
}
|
|
|
- //关闭订单
|
|
|
- doOrderCancel(detail, OrderStatusEnum.CLOSE, StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
log.error("轮询处理支付中订单异常,异常参数: {}", JSONObject.toJSONString(payReq));
|
|
|
return HttpResponseResult.failed("取消订单失败");
|
|
|
}
|
|
|
}
|
|
|
+ //关闭订单
|
|
|
+ doOrderCancel(detail, OrderStatusEnum.CLOSE, StringUtil.isEmpty(payReq.getReason()) ? "用户取消订单" : payReq.getReason());
|
|
|
return HttpResponseResult.succeed(true);
|
|
|
|
|
|
}
|
|
@@ -346,9 +350,8 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
log.error("汇付支付回调,订单未找到。 req is {}", hfRes.toJSONString());
|
|
|
return;
|
|
|
}
|
|
|
- if (!detail.getStatus().equals(OrderStatusEnum.PAID)
|
|
|
- && !detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
|
|
|
- && !detail.getStatus().equals(OrderStatusEnum.CLOSE)) {
|
|
|
+ if (detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
|
|
|
+ || detail.getStatus().equals(OrderStatusEnum.PAYING)) {
|
|
|
orderSuccess(detail, hfRes);
|
|
|
} else {
|
|
|
log.error("汇付支付回调,订单状态异常。 req is {}", hfRes.toJSONString());
|
|
@@ -362,27 +365,14 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
* @updateTime 2022/4/27 15:09
|
|
|
*/
|
|
|
private void paymentFailedHandle(JSONObject hfRes) {
|
|
|
- //订单完成
|
|
|
UserOrderVo detail = detail(hfRes.getString("order_no"));
|
|
|
-
|
|
|
if (null == detail) {
|
|
|
log.error("汇付支付回调,订单未找到。 req is {}", hfRes.toJSONString());
|
|
|
return;
|
|
|
}
|
|
|
- if (!detail.getStatus().equals(OrderStatusEnum.PAID)
|
|
|
- && !detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
|
|
|
- && !detail.getStatus().equals(OrderStatusEnum.CLOSE)) {
|
|
|
-
|
|
|
- doOrderCancel(detail, OrderStatusEnum.FAIL, "支付失败");
|
|
|
- //查询
|
|
|
- UserOrderPayment orderPayment = orderPaymentService.detailByOrderNo(hfRes.getString("order_no"));
|
|
|
- if (null == orderPayment) {
|
|
|
- return;
|
|
|
- }
|
|
|
- orderPayment.setPayFailMsg("支付回调失败");
|
|
|
- orderPayment.setStatus(TradeStatusEnum.failed);
|
|
|
- orderPayment.setUpdateTime(new Date());
|
|
|
- orderPaymentService.updateById(orderPayment);
|
|
|
+ if (detail.getStatus().equals(OrderStatusEnum.WAIT_PAY)
|
|
|
+ || detail.getStatus().equals(OrderStatusEnum.PAYING)) {
|
|
|
+ doOrderCancel(detail, OrderStatusEnum.FAIL, "支付回调失败");
|
|
|
} else {
|
|
|
log.error("汇付支付回调,订单状态异常。 req is {}", hfRes.toJSONString());
|
|
|
}
|
|
@@ -454,6 +444,10 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
if (null == detail) {
|
|
|
return;
|
|
|
}
|
|
|
+ if(!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
if (!StringUtil.isEmpty(detail.getTransNo())) {
|
|
|
try {
|
|
|
Map<String, Object> resMap = paymentSdk.queryPayment(detail.getTransNo());
|
|
@@ -464,13 +458,13 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
orderSuccess(detail);
|
|
|
return;
|
|
|
}
|
|
|
- //关闭订单
|
|
|
- doOrderCancel(detail, OrderStatusEnum.CLOSE, "订单超时");
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
+ //关闭订单
|
|
|
+ doOrderCancel(detail, OrderStatusEnum.CLOSE, "订单超时");
|
|
|
}
|
|
|
|
|
|
/***
|
|
@@ -754,7 +748,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
void doOrderCancel(UserOrderVo userOrder, OrderStatusEnum orderStatus, String reason) {
|
|
|
- //已经取消过的订单,不能再取消
|
|
|
+ //已经完成过的订单,不能再取消
|
|
|
if (!OrderStatusEnum.WAIT_PAY.equals(userOrder.getStatus())
|
|
|
&& !OrderStatusEnum.PAYING.equals(userOrder.getStatus())) {
|
|
|
return;
|
|
@@ -814,6 +808,11 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
*/
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
void orderSuccess(UserOrderVo detail, JSONObject hfRes) {
|
|
|
+ //订单已完成
|
|
|
+ if (!OrderStatusEnum.WAIT_PAY.equals(detail.getStatus())
|
|
|
+ && !OrderStatusEnum.PAYING.equals(detail.getStatus())) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
Date now = new Date();
|
|
|
detail.setStatus(OrderStatusEnum.PAID);
|
|
|
detail.setPayTime(now);
|
|
@@ -827,7 +826,7 @@ public class UserOrderServiceImpl extends ServiceImpl<UserOrderDao, UserOrder> i
|
|
|
orderPayment.setUpdateTime(now);
|
|
|
if (null != hfRes) {
|
|
|
try {
|
|
|
- orderPayment.setPayAmt(new BigDecimal(hfRes.getString("pay_amt")));
|
|
|
+ orderPayment.setBackPayAmt(new BigDecimal(hfRes.getString("pay_amt")));
|
|
|
orderPayment.setFeeAmt(new BigDecimal(hfRes.getString("fee_amt")));
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|