From e3f412c5474311a471345ea508db4875c9ec648e Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期四, 17 九月 2026 15:47:59 +0800
Subject: [PATCH] feat(payment): 支付按支付尝试收敛,取消与放弃以关单回执为准

---
 talent-card-server/src/main/java/com/talentcard/server/business/portal/PendingOrderPortalController.java |   32 +++++++++++++++++++++++++++++++-
 1 files changed, 31 insertions(+), 1 deletions(-)

diff --git a/talent-card-server/src/main/java/com/talentcard/server/business/portal/PendingOrderPortalController.java b/talent-card-server/src/main/java/com/talentcard/server/business/portal/PendingOrderPortalController.java
index 23cc2f1..5c124ca 100644
--- a/talent-card-server/src/main/java/com/talentcard/server/business/portal/PendingOrderPortalController.java
+++ b/talent-card-server/src/main/java/com/talentcard/server/business/portal/PendingOrderPortalController.java
@@ -1,11 +1,15 @@
 package com.talentcard.server.business.portal;
 
+import java.util.LinkedHashMap;
 import java.util.Map;
 import java.util.List;
 
 import com.talentcard.server.business.auth.TalentAuthService;
 import com.talentcard.server.business.auth.TalentSessionPrincipal;
 import com.talentcard.server.business.payment.HuifuPaymentService;
+import com.talentcard.server.business.payment.PaymentReconciliationService;
+import com.talentcard.server.business.payment.PaymentReconciliationService.PendingPaymentConfirmation;
+import com.talentcard.server.business.payment.PaymentReconciliationService.PendingPaymentState;
 import com.talentcard.server.common.ApiResponse;
 import com.talentcard.server.common.BusinessException;
 import com.talentcard.server.common.ErrorCode;
@@ -25,11 +29,14 @@
 public class PendingOrderPortalController {
 	private final PendingOrderPortalService pendingOrderPortalService;
 	private final HuifuPaymentService huifuPaymentService;
+	private final PaymentReconciliationService paymentReconciliationService;
 	private final TalentAuthService talentAuthService;
 
-	public PendingOrderPortalController(PendingOrderPortalService pendingOrderPortalService, HuifuPaymentService huifuPaymentService, TalentAuthService talentAuthService) {
+	public PendingOrderPortalController(PendingOrderPortalService pendingOrderPortalService, HuifuPaymentService huifuPaymentService,
+			PaymentReconciliationService paymentReconciliationService, TalentAuthService talentAuthService) {
 		this.pendingOrderPortalService = pendingOrderPortalService;
 		this.huifuPaymentService = huifuPaymentService;
+		this.paymentReconciliationService = paymentReconciliationService;
 		this.talentAuthService = talentAuthService;
 	}
 
@@ -85,6 +92,29 @@
 		return ApiResponse.success(huifuPaymentService.paymentStatus(orderNo, talentId, paymentNo));
 	}
 
+	/**
+	 * 放弃支付:客户端在收银台里点了关闭时调用,服务端立刻尝试关单。
+	 *
+	 * <p>只触发关单、绝不结算:客户端说「我放弃了」只当作信号,钱收没收下一律以通道回执为准。
+	 */
+	@PostMapping("/{orderNo}/payment/abandon")
+	public ApiResponse<Map<String, Object>> abandonPayment(
+			@PathVariable String orderNo,
+			@Valid @RequestBody PendingOrderAbandonRequest request,
+			@RequestHeader(value = HttpHeaders.AUTHORIZATION, required = false) String authorization
+	) {
+		ensureSessionTalent(authorization, request.talentId());
+		PendingPaymentConfirmation confirmation =
+				paymentReconciliationService.abandonPendingPayments(orderNo, request.paymentNo());
+		Map<String, Object> result = new LinkedHashMap<>();
+		result.put("paymentNo", confirmation.paymentNo());
+		// 关单有结论(关掉了/通道拒绝关单但仍然允许继续)就是 CANCELLED;
+		// 通道说还在处理中就是 PAYMENT_PROCESSING——后台会接着关,客户端按可等待渲染。
+		result.put("paymentStatus", confirmation.state() == PendingPaymentState.UNCONFIRMED
+				? "PAYMENT_PROCESSING" : "CANCELLED");
+		return ApiResponse.success(result);
+	}
+
 	private void ensureSessionTalent(String authorization, Long talentId) {
 		TalentSessionPrincipal principal = talentAuthService.authenticate(authorization);
 		if (!principal.talentId().equals(talentId)) throw new BusinessException(ErrorCode.FORBIDDEN, "无权操作其他人才用户的订单");

--
Gitblit v1.7.1