From 65e2209a850f8b729aac45ee4e04293774fd6a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E5=BF=A0=E6=9E=97?= <170083662@qq.com> Date: Sun, 14 Dec 2025 01:22:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(subscription):=20=E5=AE=9E=E7=8E=B0?= =?UTF-8?q?=E8=AE=A2=E9=98=85=E8=AE=A2=E5=8D=95=E5=88=9B=E5=BB=BA=E4=B8=8E?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增创建订阅订单接口,支持生成订单号及价格试算 - 新增订阅订单支付接口,集成微信Native支付生成二维码 - 添加订单创建与支付结果返回类 - 注入微信支付控制器并调用其生成支付二维码方法 - 校验用户登录状态、套餐ID及支付金额有效性 - 构建订单对象用于支付二维码生成,并返回支付链接 --- .../SubscriptionOrderController.java | 65 +++++++++++++++++++ .../result/SubscriptionOrderCreateResult.java | 18 +++++ .../result/SubscriptionOrderPayResult.java | 21 ++++++ 3 files changed, 104 insertions(+) create mode 100644 src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderCreateResult.java create mode 100644 src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderPayResult.java diff --git a/src/main/java/com/gxwebsoft/common/system/controller/SubscriptionOrderController.java b/src/main/java/com/gxwebsoft/common/system/controller/SubscriptionOrderController.java index 7b026b6..ba6ece5 100644 --- a/src/main/java/com/gxwebsoft/common/system/controller/SubscriptionOrderController.java +++ b/src/main/java/com/gxwebsoft/common/system/controller/SubscriptionOrderController.java @@ -2,10 +2,15 @@ package com.gxwebsoft.common.system.controller; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; +import cn.hutool.core.util.IdUtil; +import com.gxwebsoft.common.core.Constants; import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.BaseController; +import com.gxwebsoft.common.system.entity.Order; import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.param.SubscriptionOrderParam; +import com.gxwebsoft.common.system.result.SubscriptionOrderCreateResult; +import com.gxwebsoft.common.system.result.SubscriptionOrderPayResult; import com.gxwebsoft.common.system.result.SubscriptionPriceResult; import com.gxwebsoft.common.system.service.SettingService; import io.swagger.v3.oas.annotations.Operation; @@ -31,6 +36,8 @@ public class SubscriptionOrderController extends BaseController { @Resource private SettingService settingService; + @Resource + private WxNativePayController wxNativePayController; @Operation(summary = "计算订阅订单价格") @PostMapping("/calculate-price") @@ -48,6 +55,64 @@ public class SubscriptionOrderController extends BaseController { return success(result); } + @Operation(summary = "创建订阅订单") + @PostMapping("/create") + public ApiResult create(@RequestBody SubscriptionOrderParam param) { + final User loginUser = getLoginUser(); + if (loginUser == null) { + return fail("请先登录", null); + } + if (param.getPackageId() == null) { + return fail("套餐ID不能为空", null); + } + + JSONObject config = loadSubscriptionConfig(); + final SubscriptionPriceResult price = buildPriceResult(param, config); + + SubscriptionOrderCreateResult result = new SubscriptionOrderCreateResult(); + result.setOrderNo(IdUtil.getSnowflakeNextIdStr()); + result.setPrice(price); + return success(result); + } + + @Operation(summary = "订阅订单支付(生成微信Native二维码)") + @PostMapping("/pay") + public ApiResult pay(@RequestBody SubscriptionOrderParam param) { + final User loginUser = getLoginUser(); + if (loginUser == null) { + return fail("请先登录", null); + } + if (param.getPackageId() == null) { + return fail("套餐ID不能为空", null); + } + + JSONObject config = loadSubscriptionConfig(); + final SubscriptionPriceResult price = buildPriceResult(param, config); + if (price.getPayPrice() == null || price.getPayPrice().compareTo(BigDecimal.ZERO) <= 0) { + return fail("支付金额必须大于0", null); + } + + // 构造订单用于生成支付二维码 + Order order = new Order(); + order.setPayPrice(price.getPayPrice()); + order.setTotalPrice(price.getTotalPrice()); + order.setComments("订阅套餐-" + param.getPackageId()); + order.setPayType(param.getPayType()); + order.setUserId(loginUser.getUserId()); + order.setTenantId(loginUser.getTenantId()); + + ApiResult payResp = wxNativePayController.getCodeUrl(order); + if (payResp.getCode() == null || !payResp.getCode().equals(Constants.RESULT_OK_CODE)) { + return fail(payResp.getMessage(), null); + } + + SubscriptionOrderPayResult result = new SubscriptionOrderPayResult(); + result.setOrderNo(order.getOrderNo()); + result.setCodeUrl(String.valueOf(payResp.getData())); + result.setPrice(price); + return success(result); + } + /** * 从配置表读取订阅套餐配置(尝试多种key以兼容历史数据) */ diff --git a/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderCreateResult.java b/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderCreateResult.java new file mode 100644 index 0000000..eb7bc8b --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderCreateResult.java @@ -0,0 +1,18 @@ +package com.gxwebsoft.common.system.result; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 订阅订单创建结果 + */ +@Data +@Schema(description = "订阅订单创建结果") +public class SubscriptionOrderCreateResult { + + @Schema(description = "订单号") + private String orderNo; + + @Schema(description = "价格试算结果") + private SubscriptionPriceResult price; +} diff --git a/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderPayResult.java b/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderPayResult.java new file mode 100644 index 0000000..69de555 --- /dev/null +++ b/src/main/java/com/gxwebsoft/common/system/result/SubscriptionOrderPayResult.java @@ -0,0 +1,21 @@ +package com.gxwebsoft.common.system.result; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +/** + * 订阅订单支付结果 + */ +@Data +@Schema(description = "订阅订单支付结果") +public class SubscriptionOrderPayResult { + + @Schema(description = "订单号") + private String orderNo; + + @Schema(description = "支付二维码链接") + private String codeUrl; + + @Schema(description = "价格信息") + private SubscriptionPriceResult price; +}