|
|
@@ -906,16 +906,32 @@ public class PayScoreServiceImpl implements PayScoreService {
|
|
|
|
|
|
if (cancelResult.isSuccess()) {
|
|
|
log.info("[支付分服务] 取消成功 - outOrderNo: {}", outOrderNo);
|
|
|
- if (localOrderId != null) {
|
|
|
- Order order = orderService.getById(localOrderId);
|
|
|
- if (order != null) {
|
|
|
- order.setPayScoreState(PayScoreState.REVOKED.getCode());
|
|
|
- orderService.updateById(order);
|
|
|
- }
|
|
|
- }
|
|
|
+ markOrderRevoked(localOrderId);
|
|
|
+ } else if (cancelResult.getErrorMsg() != null
|
|
|
+ && cancelResult.getErrorMsg().contains("ORDER_NOT_EXIST")) {
|
|
|
+ // 微信侧已不存在,同步清理本地状态,避免反复尝试
|
|
|
+ log.debug("[支付分服务] 微信侧已不存在,清理本地记录 - outOrderNo: {}", outOrderNo);
|
|
|
+ markOrderRevoked(localOrderId);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ // 网络异常等,微信侧可能已取消成功,保守清理本地状态
|
|
|
+ log.debug("[支付分服务] 取消异常,清理本地记录 - outOrderNo: {}", outOrderNo);
|
|
|
+ markOrderRevoked(localOrderId);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void markOrderRevoked(Long localOrderId) {
|
|
|
+ if (localOrderId == null) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ Order order = orderService.getById(localOrderId);
|
|
|
+ if (order != null && !PayScoreState.isFinished(order.getPayScoreState())) {
|
|
|
+ order.setPayScoreState(PayScoreState.REVOKED.getCode());
|
|
|
+ orderService.updateById(order);
|
|
|
}
|
|
|
} catch (Exception e) {
|
|
|
- log.debug("[支付分服务] 取消订单异常(可能微信侧已不存在) - outOrderNo: {}", outOrderNo);
|
|
|
+ log.warn("[支付分服务] 更新本地订单状态失败 - orderId: {}", localOrderId, e);
|
|
|
}
|
|
|
}
|
|
|
|