feat(payment): 更新微信支付配置逻辑以支持新旧类型兼容

- 在WxPayConfigService中引入PaymentType枚举类
- 修改支付配置查询逻辑,优先使用新的微信支付类型(WECHAT)
- 添加对旧微信Native支付类型(WECHAT_NATIVE)的兼容查询
- 调整日志记录内容以反映新的查询流程
- 优化缓存键的生成方式并保持1天的有效期

fix(order): 简化订单退款状态设置逻辑

- 移除基于微信退款响应状态的复杂判断逻辑
- 固定设置订单状态为6(退款成功)当退款请求发出后
- 删除冗余的状态切换代码段落
- 保留关键的日志记录功能以便追踪退款过程
This commit is contained in:
2025-12-10 09:26:17 +08:00
parent 006c1cabec
commit 35dfaa0d72
2 changed files with 32 additions and 21 deletions

View File

@@ -9,6 +9,7 @@ import com.gxwebsoft.common.system.entity.Payment;
import com.gxwebsoft.common.system.param.PaymentParam; import com.gxwebsoft.common.system.param.PaymentParam;
import com.gxwebsoft.common.system.service.PaymentService; import com.gxwebsoft.common.system.service.PaymentService;
import com.gxwebsoft.payment.exception.PaymentException; import com.gxwebsoft.payment.exception.PaymentException;
import com.gxwebsoft.payment.enums.PaymentType;
import com.wechat.pay.java.core.Config; import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig; import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@@ -121,19 +122,28 @@ public class WxPayConfigService {
System.out.println("payment = " + payment); System.out.println("payment = " + payment);
if (payment != null) { if (payment != null) {
log.debug("从缓存获取支付配置成功租户ID: {}", tenantId); log.debug("从缓存获取支付配置成功租户ID: {}", tenantId);
// return payment; return payment;
} }
// 缓存中没有,尝试从数据库查询 // 缓存中没有,尝试从数据库查询
try { try {
final PaymentParam paymentParam = new PaymentParam(); final PaymentParam paymentParam = new PaymentParam();
paymentParam.setType(102); // 优先使用新的微信支付类型1 = WECHAT
paymentParam.setType(PaymentType.WECHAT.getCode());
paymentParam.setTenantId(tenantId); paymentParam.setTenantId(tenantId);
log.debug("查询数据库支付配置,参数: type=102, tenantId={}", tenantId); log.debug("查询数据库支付配置,参数: type={}, tenantId={}", paymentParam.getType(), tenantId);
payment = paymentService.getByType(paymentParam); payment = paymentService.getByType(paymentParam);
log.debug("数据库查询结果: {}", payment != null ? "找到配置" : "未找到配置"); log.debug("数据库查询结果: {}", payment != null ? "找到配置" : "未找到配置");
// 兼容旧数据如果没有查到再尝试旧的微信Native类型102
if (payment == null) {
paymentParam.setType(PaymentType.WECHAT_NATIVE.getCode());
log.debug("未找到type=1配置尝试兼容旧type={}, tenantId={}", paymentParam.getType(), tenantId);
payment = paymentService.getByType(paymentParam);
log.debug("兼容查询结果: {}", payment != null ? "找到配置" : "未找到配置");
}
if (payment != null) { if (payment != null) {
log.info("从数据库获取支付配置成功租户ID: {},将缓存配置", tenantId); log.info("从数据库获取支付配置成功租户ID: {},将缓存配置", tenantId);
@@ -148,7 +158,7 @@ public class WxPayConfigService {
redisUtil.set(cacheKey, payment, 1L, TimeUnit.DAYS); redisUtil.set(cacheKey, payment, 1L, TimeUnit.DAYS);
return payment; return payment;
} else { } else {
log.warn("数据库中未找到支付配置租户ID: {}, type: 102", tenantId); log.warn("数据库中未找到支付配置租户ID: {}已尝试type=1和type=102", tenantId);
} }
} catch (Exception e) { } catch (Exception e) {
log.error("从数据库查询支付配置失败租户ID: {},错误: {}", tenantId, e.getMessage(), e); log.error("从数据库查询支付配置失败租户ID: {},错误: {}", tenantId, e.getMessage(), e);

View File

@@ -266,27 +266,28 @@ public class ShopOrderController extends BaseController {
shopOrder.setRefundOrder(refundNo); shopOrder.setRefundOrder(refundNo);
shopOrder.setRefundMoney(refundAmount); shopOrder.setRefundMoney(refundAmount);
shopOrder.setRefundTime(LocalDateTime.now()); shopOrder.setRefundTime(LocalDateTime.now());
shopOrder.setOrderStatus(6); // 退款成功
// 根据退款状态决定订单状态 // 根据退款状态决定订单状态
// 如果微信返回退款处理中则设置订单状态为5退款处理中 // 如果微信返回退款处理中则设置订单状态为5退款处理中
// 如果微信返回退款成功则保持状态为6退款成功 // 如果微信返回退款成功则保持状态为6退款成功
if (refundResponse.getPaymentStatus() != null) { // if (refundResponse.getPaymentStatus() != null) {
switch (refundResponse.getPaymentStatus()) { // switch (refundResponse.getPaymentStatus()) {
case REFUNDING: // case REFUNDING:
shopOrder.setOrderStatus(5); // 退款处理中 // shopOrder.setOrderStatus(5); // 退款处理中
logger.info("订单退款处理中,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo); // logger.info("订单退款处理中,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo);
break; // break;
case REFUNDED: // case REFUNDED:
shopOrder.setOrderStatus(6); // 退款成功 // shopOrder.setOrderStatus(6); // 退款成功
logger.info("订单退款成功,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo); // logger.info("订单退款成功,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo);
break; // break;
case REFUND_FAILED: // case REFUND_FAILED:
logger.error("订单退款失败,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo); // logger.error("订单退款失败,订单号: {}, 退款单号: {}", shopOrderNow.getOrderNo(), refundNo);
return fail("退款失败,请联系管理员"); // return fail("退款失败,请联系管理员");
default: // default:
shopOrder.setOrderStatus(5); // 默认为退款处理中 // shopOrder.setOrderStatus(5); // 默认为退款处理中
} // }
} // }
logger.info("订单退款请求成功 - 订单号: {}, 退款单号: {}, 微信退款单号: {}", logger.info("订单退款请求成功 - 订单号: {}, 退款单号: {}, 微信退款单号: {}",
shopOrderNow.getOrderNo(), refundNo, refundResponse.getTransactionId()); shopOrderNow.getOrderNo(), refundNo, refundResponse.getTransactionId());