|
|
@ -1,5 +1,7 @@ |
|
|
|
package com.gxwebsoft.payment.service.impl; |
|
|
|
|
|
|
|
import cn.hutool.core.util.IdUtil; |
|
|
|
import com.gxwebsoft.common.core.utils.CommonUtil; |
|
|
|
import com.gxwebsoft.common.system.entity.User; |
|
|
|
import com.gxwebsoft.payment.constants.PaymentConstants; |
|
|
|
import com.gxwebsoft.payment.dto.PaymentRequest; |
|
|
@ -8,6 +10,7 @@ import com.gxwebsoft.payment.dto.PaymentWithOrderRequest; |
|
|
|
import com.gxwebsoft.payment.enums.PaymentType; |
|
|
|
import com.gxwebsoft.payment.exception.PaymentException; |
|
|
|
import com.gxwebsoft.payment.service.PaymentService; |
|
|
|
import com.gxwebsoft.payment.service.WxPayConfigService; |
|
|
|
import com.gxwebsoft.payment.strategy.PaymentStrategy; |
|
|
|
import com.gxwebsoft.shop.dto.OrderCreateRequest; |
|
|
|
import com.gxwebsoft.shop.service.OrderBusinessService; |
|
|
@ -50,6 +53,12 @@ public class PaymentServiceImpl implements PaymentService { |
|
|
|
@Resource |
|
|
|
private OrderBusinessService orderBusinessService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 微信支付配置服务 |
|
|
|
*/ |
|
|
|
@Resource |
|
|
|
private WxPayConfigService wxPayConfigService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 初始化策略映射 |
|
|
|
*/ |
|
|
@ -416,6 +425,34 @@ public class PaymentServiceImpl implements PaymentService { |
|
|
|
.collect(Collectors.toList()); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public Map<String, Object> checkPaymentConfig(Integer tenantId) { |
|
|
|
Map<String, Object> result = new HashMap<>(); |
|
|
|
result.put("tenantId", tenantId); |
|
|
|
|
|
|
|
try { |
|
|
|
// 检查微信支付配置
|
|
|
|
wxPayConfigService.getPaymentConfigForStrategy(tenantId); |
|
|
|
result.put("wechatConfigExists", true); |
|
|
|
result.put("wechatConfigError", null); |
|
|
|
} catch (Exception e) { |
|
|
|
result.put("wechatConfigExists", false); |
|
|
|
result.put("wechatConfigError", e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
try { |
|
|
|
// 检查微信支付Config构建
|
|
|
|
wxPayConfigService.getWxPayConfig(tenantId); |
|
|
|
result.put("wechatConfigValid", true); |
|
|
|
result.put("wechatConfigValidError", null); |
|
|
|
} catch (Exception e) { |
|
|
|
result.put("wechatConfigValid", false); |
|
|
|
result.put("wechatConfigValidError", e.getMessage()); |
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取支付策略 |
|
|
|
*/ |
|
|
@ -554,6 +591,11 @@ public class PaymentServiceImpl implements PaymentService { |
|
|
|
private OrderCreateRequest convertToOrderCreateRequest(PaymentWithOrderRequest request, User loginUser) { |
|
|
|
OrderCreateRequest orderRequest = new OrderCreateRequest(); |
|
|
|
|
|
|
|
// 生成订单号(使用雪花算法保证全局唯一)
|
|
|
|
String orderNo = Long.toString(IdUtil.getSnowflakeNextId()); |
|
|
|
orderRequest.setOrderNo(orderNo); |
|
|
|
log.info("为订单创建请求生成订单号(雪花算法): {}", orderNo); |
|
|
|
|
|
|
|
// 设置基本信息
|
|
|
|
orderRequest.setType(request.getOrderInfo().getType()); |
|
|
|
orderRequest.setTitle(request.getSubject()); |
|
|
@ -614,8 +656,13 @@ public class PaymentServiceImpl implements PaymentService { |
|
|
|
|
|
|
|
// 设置额外信息
|
|
|
|
response.setSuccess(true); |
|
|
|
// 确保orderNo被正确设置
|
|
|
|
response.setOrderNo(orderNo); |
|
|
|
|
|
|
|
// 调试日志
|
|
|
|
log.info("构建支付响应成功, 订单号: {}, 二维码URL: {}, 响应中的orderNo: {}", |
|
|
|
orderNo, wxOrderInfo.get("codeUrl"), response.getOrderNo()); |
|
|
|
|
|
|
|
log.debug("构建支付响应成功, 订单号: {}, 二维码URL: {}", orderNo, wxOrderInfo.get("codeUrl")); |
|
|
|
return response; |
|
|
|
} |
|
|
|
} |
|
|
|