From 971e637c2eebe93011a485ddfa99d4f19289811d Mon Sep 17 00:00:00 2001
From: shinnosuke <tantao@1hoper.com>
Date: 星期三, 05 八月 2026 16:06:36 +0800
Subject: [PATCH] feat(admin): 添加优惠券人才等级数量配置功能并完善商户入驻流程

---
 talent-card-server/src/main/java/com/talentcard/server/business/payment/HuifuPaymentService.java |   30 ++++++++++++++++++++----------
 1 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/talent-card-server/src/main/java/com/talentcard/server/business/payment/HuifuPaymentService.java b/talent-card-server/src/main/java/com/talentcard/server/business/payment/HuifuPaymentService.java
index dd049ae..8de86cb 100644
--- a/talent-card-server/src/main/java/com/talentcard/server/business/payment/HuifuPaymentService.java
+++ b/talent-card-server/src/main/java/com/talentcard/server/business/payment/HuifuPaymentService.java
@@ -47,7 +47,7 @@
         Map<String, Object> response;
         try {
             response = gateway.createMiniProgramPayment(new HuifuMiniProgramPaymentCommand(
-                    prepared.paymentNo(), prepared.openId(), prepared.amountInCent(), prepared.goodsDescription(), prepared.expiresAt()));
+                    prepared.paymentNo(), prepared.huifuId(), prepared.openId(), prepared.amountInCent(), prepared.goodsDescription(), prepared.expiresAt()));
         } catch (HuifuPaymentGatewayException exception) {
             if (exception.isOutcomeUnknown()) {
                 transactions.executeWithoutResult(status -> markCreateUnknown(prepared.paymentNo(), "GATEWAY_UNKNOWN", exception.getMessage()));
@@ -77,9 +77,16 @@
             throw new BusinessException(ErrorCode.BAD_REQUEST, "缺少有效支付幂等键");
         }
         List<Map<String, Object>> orders = rows("""
-                select o.id, o.order_no, o.talent_id, o.merchant_id, o.pay_amount, o.order_status, o.price_version,
+                select o.id, o.order_no, o.talent_id, o.merchant_id, o.store_id, o.pay_amount, o.order_status, o.price_version,
                        o.expires_at, coalesce(o.product_name_snapshot, o.order_type, '人才权益服务') goods_description,
-                       t.openid
+                       t.openid,
+                       coalesce((select a.provider_huifu_id
+                                 from merchant_onboarding_application a
+                                 where a.merchant_id = o.merchant_id
+                                   and a.status = 'approved'
+                                   and a.provider_huifu_id is not null
+                                   and trim(a.provider_huifu_id) <> ''
+                                 order by a.id desc limit 1), '') provider_huifu_id
                 from benefit_order o
                 join talent_user t on t.id = o.talent_id and t.deleted = 0
                 where o.deleted = 0 and o.order_no = ? and o.talent_id = ?
@@ -88,7 +95,7 @@
         if (orders.isEmpty()) throw new BusinessException(ErrorCode.NOT_FOUND, "订单不存在或无权支付");
         Map<String, Object> order = orders.get(0);
         long payAmount = number(order.get("payAmount"));
-        if (number(order.get("orderStatus")) == 1) return new PreparedPayment("", "", 0, "", LocalDateTime.now(), false, true, "", false);
+        if (number(order.get("orderStatus")) == 1) return new PreparedPayment("", "", "", 0, "", LocalDateTime.now(), false, true, "", false);
         if (number(order.get("orderStatus")) != 0) throw new BusinessException(ErrorCode.CONFLICT, "订单当前不可支付");
         if (number(order.get("priceVersion")) != priceVersion) throw new BusinessException(ErrorCode.CONFLICT, "订单金额已更新,请重新确认");
         LocalDateTime expiresAt = localDateTime(order.get("expiresAt"));
@@ -100,10 +107,12 @@
                         verify_status = case when order_type = 'STORE_CONSUME' then 1 else verify_status end
                     where id = ? and order_status = 0
                     """, number(order.get("id")));
-            return new PreparedPayment("", "", 0, "", LocalDateTime.now(), false, true, "", false);
+            return new PreparedPayment("", "", "", 0, "", LocalDateTime.now(), false, true, "", false);
         }
         String openId = string(order.get("openid"));
         if (openId.isBlank()) throw new BusinessException(ErrorCode.CONFLICT, "当前用户未完成微信支付授权");
+        String huifuId = string(order.get("providerHuifuId"));
+        if (huifuId.isBlank()) throw new BusinessException(ErrorCode.CONFLICT, "商户汇付商户号未配置或尚未审核通过");
 
         List<Map<String, Object>> existingRows = rows("""
                 select payment_no, order_no, talent_id, status, attempt_no, client_payment_payload
@@ -119,22 +128,22 @@
             }
             String status = string(existing.get("status"));
             String paymentNo = string(existing.get("paymentNo"));
-            if ("SUCCEEDED".equals(status)) return new PreparedPayment(paymentNo, "", 0, "", LocalDateTime.now(), false, true, "", false);
+            if ("SUCCEEDED".equals(status)) return new PreparedPayment(paymentNo, "", "", 0, "", LocalDateTime.now(), false, true, "", false);
             if ("PREPAY_CREATED".equals(status)) {
-                return new PreparedPayment(paymentNo, "", 0, "", LocalDateTime.now(), false, false, string(existing.get("clientPaymentPayload")), false);
+                return new PreparedPayment(paymentNo, "", "", 0, "", LocalDateTime.now(), false, false, string(existing.get("clientPaymentPayload")), false);
             }
             if ("CREATED".equals(status) || "CREATE_UNKNOWN".equals(status)) {
-                return new PreparedPayment(paymentNo, "", 0, "", LocalDateTime.now(), false, false, "", true);
+                return new PreparedPayment(paymentNo, "", "", 0, "", LocalDateTime.now(), false, false, "", true);
             }
             int nextAttempt = (int) number(existing.get("attemptNo")) + 1;
             String retryPaymentNo = BusinessIdGenerator.next("P");
             insertPaymentTransaction(retryPaymentNo, order, orderNo, talentId, payAmount, idempotencyKey, nextAttempt);
-            return new PreparedPayment(retryPaymentNo, openId, payAmount, string(order.get("goodsDescription")), expiryOrDefault(expiresAt), true, false, "", false);
+            return new PreparedPayment(retryPaymentNo, huifuId, openId, payAmount, string(order.get("goodsDescription")), expiryOrDefault(expiresAt), true, false, "", false);
         }
 
         String paymentNo = BusinessIdGenerator.next("P");
         insertPaymentTransaction(paymentNo, order, orderNo, talentId, payAmount, idempotencyKey, 1);
-        return new PreparedPayment(paymentNo, openId, payAmount, string(order.get("goodsDescription")), expiryOrDefault(expiresAt), true, false, "", false);
+        return new PreparedPayment(paymentNo, huifuId, openId, payAmount, string(order.get("goodsDescription")), expiryOrDefault(expiresAt), true, false, "", false);
     }
 
     private void insertPaymentTransaction(
@@ -327,6 +336,7 @@
 
     private record PreparedPayment(
             String paymentNo,
+            String huifuId,
             String openId,
             long amountInCent,
             String goodsDescription,

--
Gitblit v1.7.1