mirror of
https://gitee.com/dromara/dax-pay.git
synced 2025-09-02 02:34:34 +00:00
perf 优化收银台支付流程
This commit is contained in:
@@ -20,7 +20,7 @@ public enum CheckoutCallTypeEnum {
|
||||
QR_CODE("qr_code", "扫码支付"),
|
||||
BAR_CODE("bar_code", "条码支付"),
|
||||
LINK("link", "跳转链接"),
|
||||
MINI_APP("mini_app", "小程序支付"),
|
||||
JSAPI("jsapi", "JSAPI"),
|
||||
AGGREGATE("aggregate", "聚合支付"),
|
||||
APP("app", "APP支付"),
|
||||
;
|
||||
|
@@ -17,9 +17,6 @@ import java.util.List;
|
||||
@Schema(title = "收银台分类配置")
|
||||
public class CheckoutGroupConfigResult{
|
||||
|
||||
@Schema(description = "主键")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 类型 web/h5/小程序
|
||||
* @see CheckoutTypeEnum
|
||||
|
@@ -21,11 +21,10 @@ public class CheckoutOrderAndConfigResult {
|
||||
private CheckoutOrderResult order;
|
||||
|
||||
/** 收银台配置信息 */
|
||||
@Schema(description = "配置信息")
|
||||
@Schema(description = "收银台配置信息")
|
||||
private CheckoutConfigResult config;
|
||||
|
||||
/** 收银台分类配置信息 */
|
||||
@Schema(description = "分类配置信息")
|
||||
private List<CheckoutGroupConfigResult> groupConfigs;
|
||||
|
||||
}
|
||||
|
@@ -1,27 +0,0 @@
|
||||
package org.dromara.daxpay.core.result.checkout;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
import org.dromara.daxpay.core.enums.PayStatusEnum;
|
||||
|
||||
/**
|
||||
* 收银台支付结果
|
||||
* @author xxm
|
||||
* @since 2024/11/29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Schema(title = "收银台支付结果")
|
||||
public class CheckoutPayResult {
|
||||
|
||||
/** 链接 */
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 支付状态
|
||||
* @see PayStatusEnum
|
||||
*/
|
||||
@Schema(description = "支付结果")
|
||||
private String payStatus;
|
||||
}
|
@@ -12,7 +12,6 @@ import org.dromara.daxpay.core.result.DaxResult;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutAggregateOrderAndConfigResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutOrderAndConfigResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutPayResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutUrlResult;
|
||||
import org.dromara.daxpay.core.result.trade.pay.PayResult;
|
||||
import org.dromara.daxpay.core.util.DaxRes;
|
||||
@@ -71,7 +70,7 @@ public class CheckoutController {
|
||||
|
||||
@Operation(summary = "发起支付(普通)")
|
||||
@PostMapping("/pay")
|
||||
public Result<CheckoutPayResult> pay(@RequestBody CheckoutPayParam param){
|
||||
public Result<PayResult> pay(@RequestBody CheckoutPayParam param){
|
||||
ValidationUtil.validateParam(param);
|
||||
return Res.ok(checkoutService.pay(param));
|
||||
}
|
||||
|
@@ -78,6 +78,10 @@ public class CheckoutAssistService {
|
||||
if (Objects.equals(payOrder.getRefundStatus(), PayRefundStatusEnum.REFUNDING.getCode())) {
|
||||
throw new TradeStatusErrorException("该订单处于退款状态");
|
||||
}
|
||||
// 待支付和支付中返回订单对象
|
||||
if (List.of(PayStatusEnum.WAIT.getCode(), PayStatusEnum.PROGRESS.getCode()).contains(payOrder.getStatus())){
|
||||
return payOrder;
|
||||
}
|
||||
// 其他状态直接抛出兜底异常
|
||||
throw new TradeStatusErrorException("订单不是待支付状态,请重新确认订单状态");
|
||||
}
|
||||
|
@@ -17,7 +17,6 @@ import org.dromara.daxpay.core.param.assist.AuthCodeParam;
|
||||
import org.dromara.daxpay.core.param.checkout.*;
|
||||
import org.dromara.daxpay.core.param.trade.pay.PayParam;
|
||||
import org.dromara.daxpay.core.result.assist.AuthResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutPayResult;
|
||||
import org.dromara.daxpay.core.result.checkout.CheckoutUrlResult;
|
||||
import org.dromara.daxpay.core.result.trade.pay.PayResult;
|
||||
import org.dromara.daxpay.service.dao.config.checkout.CheckoutAggregateConfigManager;
|
||||
@@ -114,7 +113,7 @@ public class CheckoutService {
|
||||
/**
|
||||
* 支付调用
|
||||
*/
|
||||
public CheckoutPayResult pay(CheckoutPayParam param){
|
||||
public PayResult pay(CheckoutPayParam param){
|
||||
// 订单信息
|
||||
PayOrder payOrder = checkoutAssistService.getOrderAndCheck(param.getOrderNo());
|
||||
paymentAssistService.initMchApp(payOrder.getAppId());
|
||||
@@ -124,14 +123,17 @@ public class CheckoutService {
|
||||
// 判断支付调用类型
|
||||
CheckoutCallTypeEnum callTypeEnum = CheckoutCallTypeEnum.findBuyCode(itemConfig.getCallType());
|
||||
switch (callTypeEnum) {
|
||||
case QR_CODE, LINK, BAR_CODE -> {
|
||||
case QR_CODE, LINK, BAR_CODE,JSAPI -> {
|
||||
return this.checkoutPay(param, payOrder);
|
||||
}
|
||||
case AGGREGATE -> {
|
||||
PlatformConfig config = platformConfigService.getConfig();
|
||||
// 直接返回手机端的聚合收银台链接
|
||||
String url = StrUtil.format("{}/aggregate/{}", config.getGatewayPcUrl(), payOrder.getOrderNo());
|
||||
return new CheckoutPayResult().setUrl(url).setPayStatus(PayStatusEnum.WAIT.getCode());
|
||||
PayResult payResult = new PayResult();
|
||||
payResult.setPayBody(url);
|
||||
payResult.setStatus(PayStatusEnum.WAIT.getCode());
|
||||
return payResult;
|
||||
}
|
||||
default -> throw new UnsupportedAbilityException("不支持的支付调用类型");
|
||||
}
|
||||
@@ -140,7 +142,7 @@ public class CheckoutService {
|
||||
/**
|
||||
* 处理参数使用通用支付接口调起支付
|
||||
*/
|
||||
private CheckoutPayResult checkoutPay(CheckoutPayParam param, PayOrder payOrder){
|
||||
private PayResult checkoutPay(CheckoutPayParam param, PayOrder payOrder){
|
||||
// 查询配置
|
||||
CheckoutItemConfig itemConfig = checkoutItemConfigManager.findByIdAndAppId(param.getItemId(),payOrder.getAppId())
|
||||
.orElseThrow(() -> new TradeProcessingException("支付配置项不存在"));
|
||||
@@ -159,10 +161,7 @@ public class CheckoutService {
|
||||
// 进行参数预处理
|
||||
cashierStrategy.handlePayParam(param, payParam);
|
||||
// 发起支付
|
||||
PayResult payResult = payService.pay(payParam, payOrder);
|
||||
return new CheckoutPayResult()
|
||||
.setUrl(payResult.getPayBody())
|
||||
.setPayStatus(payResult.getStatus());
|
||||
return payService.pay(payParam, payOrder);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user