|
@@ -381,6 +381,35 @@ public class PayScoreServiceImpl implements PayScoreService {
|
|
|
return result;
|
|
return result;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
|
|
+ public PayScoreResult payPayScoreOrder(Long orderId) {
|
|
|
|
|
+ log.info("[支付分服务] 发起支付扣款 - orderId: {}", orderId);
|
|
|
|
|
+
|
|
|
|
|
+ PayScoreResult checkResult = checkServiceAvailable();
|
|
|
|
|
+ if (checkResult != null) {
|
|
|
|
|
+ return checkResult;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ Order order = validateAndGetOrder(orderId);
|
|
|
|
|
+
|
|
|
|
|
+ if (order.getPayScoreOrderId() == null) {
|
|
|
|
|
+ return PayScoreResult.fail("ORDER_NOT_CREATED", "该订单未创建支付分服务订单");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 调用微信支付分 /pay 接口发起扣款
|
|
|
|
|
+ PayScoreResult result = payScoreStrategy.payServiceOrder(order.getPayScoreOrderId());
|
|
|
|
|
+
|
|
|
|
|
+ if (result.isSuccess()) {
|
|
|
|
|
+ log.info("[支付分服务] 支付扣款成功 - orderId: {}, outOrderNo: {}", orderId, order.getPayScoreOrderId());
|
|
|
|
|
+ } else {
|
|
|
|
|
+ log.error("[支付分服务] 支付扣款失败 - orderId: {}, errorCode: {}, errorMsg: {}",
|
|
|
|
|
+ orderId, result.getErrorCode(), result.getErrorMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return result;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public PayScoreResult modifyPayScoreOrder(Long orderId, BigDecimal totalAmount,
|
|
public PayScoreResult modifyPayScoreOrder(Long orderId, BigDecimal totalAmount,
|
|
@@ -496,6 +525,15 @@ public class PayScoreServiceImpl implements PayScoreService {
|
|
|
BigDecimal actualRefundAmount = refundAmount != null ? refundAmount
|
|
BigDecimal actualRefundAmount = refundAmount != null ? refundAmount
|
|
|
: (order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount());
|
|
: (order.getPaidAmount() != null ? order.getPaidAmount() : order.getTotalAmount());
|
|
|
|
|
|
|
|
|
|
+ // 先调用 /pay 接口确保支付资源存在,否则 /pay/refund 会返回 404
|
|
|
|
|
+ log.info("[支付分服务] 退款前先确保支付已发起 - orderId: {}", orderId);
|
|
|
|
|
+ PayScoreResult payResult = payScoreStrategy.payServiceOrder(order.getPayScoreOrderId());
|
|
|
|
|
+ if (!payResult.isSuccess()) {
|
|
|
|
|
+ // /pay 失败可能是已经扣款成功,记录日志后继续尝试退款
|
|
|
|
|
+ log.warn("[支付分服务] /pay 调用未成功(可能已自动扣款),继续尝试退款: code={}, msg={}",
|
|
|
|
|
+ payResult.getErrorCode(), payResult.getErrorMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
PayScoreRefundRequest request = new PayScoreRefundRequest();
|
|
PayScoreRefundRequest request = new PayScoreRefundRequest();
|
|
|
request.setOutOrderNo(order.getPayScoreOrderId());
|
|
request.setOutOrderNo(order.getPayScoreOrderId());
|
|
|
request.setRefundAmount(actualRefundAmount);
|
|
request.setRefundAmount(actualRefundAmount);
|