From 61e873aada7f8c55ccebb4c5fdf93ec21eb5fffe Mon Sep 17 00:00:00 2001
From: yeg <1347747024@qq.com>
Date: 星期一, 14 九月 2026 14:41:13 +0800
Subject: [PATCH] refactor(merchant): 核销收敛为一份实现,按是否涉及资金拆两个接口
---
talent-card-server/src/main/java/com/talentcard/server/business/order/OrderService.java | 38 ++++++++++++--------------------------
1 files changed, 12 insertions(+), 26 deletions(-)
diff --git a/talent-card-server/src/main/java/com/talentcard/server/business/order/OrderService.java b/talent-card-server/src/main/java/com/talentcard/server/business/order/OrderService.java
index 1334a9a..4a2dab2 100644
--- a/talent-card-server/src/main/java/com/talentcard/server/business/order/OrderService.java
+++ b/talent-card-server/src/main/java/com/talentcard/server/business/order/OrderService.java
@@ -29,14 +29,14 @@
private final HuifuRefundService refundService;
private final MerchantPaymentReadinessService merchantPaymentReadinessService;
private final OrderFundBoundaryService orderFundBoundary;
- private final PaymentFundConfirmationService fundConfirmation;
+ private final OrderVerificationService orderVerificationService;
- public OrderService(JdbcTemplate jdbcTemplate, HuifuRefundService refundService, MerchantPaymentReadinessService merchantPaymentReadinessService, OrderFundBoundaryService orderFundBoundary, PaymentFundConfirmationService fundConfirmation) {
+ public OrderService(JdbcTemplate jdbcTemplate, HuifuRefundService refundService, MerchantPaymentReadinessService merchantPaymentReadinessService, OrderFundBoundaryService orderFundBoundary, OrderVerificationService orderVerificationService) {
this.jdbcTemplate = jdbcTemplate;
this.refundService = refundService;
this.merchantPaymentReadinessService = merchantPaymentReadinessService;
this.orderFundBoundary = orderFundBoundary;
- this.fundConfirmation = fundConfirmation;
+ this.orderVerificationService = orderVerificationService;
}
@Transactional
@@ -93,39 +93,25 @@
public Map<String, Object> verify(String orderNo, OrderVerifyRequest request) {
Map<String, Object> order = detail(orderNo);
Long orderId = ((Number) order.get("id")).longValue();
- // 后台核销与商户核销、退款共用同一把订单行锁,重复核销只会产生一次有效结果。
- OrderFundBoundaryService.LockedOrder locked = orderFundBoundary.lock(orderId);
- locked.requireVerifiable();
Long orderMerchantId = order.get("merchantId") == null ? null : ((Number) order.get("merchantId")).longValue();
if (request.merchantId() != null && !request.merchantId().equals(orderMerchantId)) {
throw new BusinessException(ErrorCode.BAD_REQUEST, "订单不属于该商户");
}
- String verifyNo = BusinessIdGenerator.next("V");
- jdbcTemplate.update("""
- insert into verify_record(verify_no, order_id, talent_id, card_id, benefit_id, merchant_id,
- staff_id, verify_type, verify_amount, subsidy_amount, remark)
- values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
- """,
- verifyNo,
- order.get("id"),
- order.get("talentId"),
- order.get("cardId"),
- order.get("benefitId"),
- orderMerchantId,
- request.staffId(),
+ Long storeId = order.get("storeId") == null ? null : ((Number) order.get("storeId")).longValue();
+ // 后台核销同样走那份唯一实现:置已核销 + 写核销记录 + 确认延迟入账的资金。
+ String verifyNo = orderVerificationService.verifyByMerchant(orderMerchantId, storeId, request.staffId(), orderId,
normalizeVerifyType(request.verifyType(), (String) order.get("orderType")),
- order.get("payAmount"),
- order.get("subsidyAmount"),
- request.remark());
- int updated = jdbcTemplate.update("update benefit_order set verify_status = 1 where id = ? and verify_status = 0", orderId);
- if (updated != 1) {
+ value(order.get("payAmount")), value(order.get("subsidyAmount")), request.remark(), null, null);
+ if (verifyNo.isBlank()) {
throw new BusinessException(ErrorCode.CONFLICT, "订单已核销");
}
- // 后台核销是第三条核销入口,同样要在核销后把延迟入账的钱确认给商户。
- fundConfirmation.confirmForOrder(orderId);
return detail(orderNo);
}
+ private long value(Object value) {
+ return value instanceof Number number ? number.longValue() : 0L;
+ }
+
public Map<String, Object> refund(String orderNo, OrderRefundRequest request) {
return refundService.request(orderNo, request);
}
--
Gitblit v1.7.1