feat:功能支付类模块完善

This commit is contained in:
2025-06-03 15:56:31 +08:00
parent ee840a2df1
commit 1dec9d2035
31 changed files with 433 additions and 798 deletions
@@ -8,14 +8,9 @@ import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo;
import com.wechat.pay.java.service.profitsharing.ProfitsharingService;
import com.wechat.pay.java.service.refund.RefundService;
import lombok.Getter;
import lombok.Setter;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import java.util.concurrent.Executor;
@@ -28,11 +23,11 @@ import java.util.concurrent.ThreadPoolExecutor;
* @date 2025-01-14
*
*/
@Getter
@Setter
@Configuration
@ConfigurationProperties(prefix = "tencent")
@EnableConfigurationProperties(ProfitSharingProperties.class)
//@Getter
//@Setter
//@Configuration
//@ConfigurationProperties(prefix = "tencent")
//@EnableConfigurationProperties(ProfitSharingProperties.class)
public class TencentPayConfiguration {
private String merchantId;
@@ -1,98 +1,98 @@
//package com.central.order.service;
//
//import com.central.common.context.LoginUserContextHolder;
//import com.central.common.exception.BusinessException;
//import com.central.common.model.SysUser;
//import com.central.order.feign.UserCenterService;
//import com.central.order.model.Order;
//import com.central.order.model.QrCode;
//import com.central.wechat.wechat.entity.WechatConfig;
//import com.central.wechat.wechat.feign.WechatConfigService;
//import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
//import com.wechat.pay.java.service.payments.jsapi.model.*;
//import com.zlt.wechat.config.WxPayConfigFactory;
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Service;
//
//@Slf4j
//@Service
//public class PaymentService {
// @Autowired
// private WxPayConfigFactory wxPayConfigFactory;
// @Autowired
// private UserCenterService userCenterService;
// @Autowired
// private IOrderService orderService;
// @Autowired
// private IQrCodeService qrCodeService;
// @Autowired
// private IProfitSharingService profitSharingService;
// @Autowired
// private WechatConfigService configService;
//
//
//
// public PrepayWithRequestPaymentResponse createPayment(Long orderId) {
// // 1. 获取用户和订单信息
// SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
// Order order = orderService.getById(orderId);
// if (order == null) {
// throw new BusinessException("订单数据不存在");
// }
//
// // 2. 获取二维码信息
// QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
// if (qrCode == null) {
// throw new BusinessException("二维码不存在");
// }
//
// // 3. 创建支付请求
// PrepayRequest request = new PrepayRequest();
//
// // 设置基本支付信息
// Amount amount = new Amount();
// amount.setTotal(Integer.parseInt(order.getOrderAmount()));
// request.setAmount(amount);
//
// // 从二维码配置中获取支付配置
// WechatConfig payConfig = configService.getConfig("PAY", qrCode.getTenantId());
// request.setAppid(payConfig.getAppId());
// request.setMchid(payConfig.getMerchantId());
// request.setDescription(order.getOrderNo());
// request.setNotifyUrl(payConfig.getNotifyUrl());
// request.setOutTradeNo(order.getOrderNo());
//
// // 设置支付者信息
// Payer payer = new Payer();
// payer.setOpenid(user.getOpenId());
// request.setPayer(payer);
//
// // 设置分账信息
// SettleInfo settleInfo = new SettleInfo();
// if (isEnableProfit(qrCode)) {
// settleInfo.setProfitSharing(true);
// request.setSettleInfo(settleInfo);
// // 创建分账记录
// profitSharingService.createProfitSharing(order, qrCode);
// } else {
// settleInfo.setProfitSharing(false);
// request.setSettleInfo(settleInfo);
// }
//
// // 4. 创建对应租户的支付服务
// JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId());
//
// // 5. 调用支付接口
// return jsapiService.prepayWithRequestPayment(request);
// }
//
// private boolean isEnableProfit(QrCode qrCode) {
// return qrCode != null &&
// Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
// qrCode.getPayeeStatus() != null &&
// qrCode.getPayeeStatus() == 1 &&
// qrCode.getPayeeAccount() != null &&
// qrCode.getProfitRate() != null;
// }
//}
package com.central.order.service;
import com.central.common.context.LoginUserContextHolder;
import com.central.common.exception.BusinessException;
import com.central.common.model.SysUser;
import com.central.order.feign.UserCenterService;
import com.central.order.model.Order;
import com.central.order.model.QrCode;
import com.central.wechat.config.WxPayConfigFactory;
import com.central.wechat.entity.WechatConfig;
import com.central.wechat.feign.WechatConfigService;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import com.wechat.pay.java.service.payments.jsapi.model.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class PaymentService {
@Autowired
private WxPayConfigFactory wxPayConfigFactory;
@Autowired
private UserCenterService userCenterService;
@Autowired
private IOrderService orderService;
@Autowired
private IQrCodeService qrCodeService;
@Autowired
private IProfitSharingService profitSharingService;
@Autowired
private WechatConfigService configService;
public PrepayWithRequestPaymentResponse createPayment(Long orderId) {
// 1. 获取用户和订单信息
SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId());
Order order = orderService.getById(orderId);
if (order == null) {
throw new BusinessException("订单数据不存在");
}
// 2. 获取二维码信息
QrCode qrCode = qrCodeService.getByCodeId(order.getCodeId());
if (qrCode == null) {
throw new BusinessException("二维码不存在");
}
// 3. 创建支付请求
PrepayRequest request = new PrepayRequest();
// 设置基本支付信息
Amount amount = new Amount();
amount.setTotal(Integer.parseInt(order.getOrderAmount()));
request.setAmount(amount);
// 从二维码配置中获取支付配置
WechatConfig payConfig = configService.getConfig("PAY", qrCode.getTenantId());
request.setAppid(payConfig.getAppId());
request.setMchid(payConfig.getMerchantId());
request.setDescription(order.getOrderNo());
request.setNotifyUrl(payConfig.getNotifyUrl());
request.setOutTradeNo(order.getOrderNo());
// 设置支付者信息
Payer payer = new Payer();
payer.setOpenid(user.getOpenId());
request.setPayer(payer);
// 设置分账信息
SettleInfo settleInfo = new SettleInfo();
if (isEnableProfit(qrCode)) {
settleInfo.setProfitSharing(true);
request.setSettleInfo(settleInfo);
// 创建分账记录
profitSharingService.createProfitSharing(order, qrCode);
} else {
settleInfo.setProfitSharing(false);
request.setSettleInfo(settleInfo);
}
// 4. 创建对应租户的支付服务
JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId());
// 5. 调用支付接口
return jsapiService.prepayWithRequestPayment(request);
}
private boolean isEnableProfit(QrCode qrCode) {
return qrCode != null &&
Integer.valueOf(1).equals(qrCode.getEnableProfit()) &&
qrCode.getPayeeStatus() != null &&
qrCode.getPayeeStatus() == 1 &&
qrCode.getPayeeAccount() != null &&
qrCode.getProfitRate() != null;
}
}