feat(subscription): 实现订阅订单创建与支付功能
- 新增创建订阅订单接口,支持生成订单号及价格试算 - 新增订阅订单支付接口,集成微信Native支付生成二维码 - 添加订单创建与支付结果返回类 - 注入微信支付控制器并调用其生成支付二维码方法 - 校验用户登录状态、套餐ID及支付金额有效性 - 构建订单对象用于支付二维码生成,并返回支付链接
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
package com.gxwebsoft.common.system.controller;
|
package com.gxwebsoft.common.system.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.IdUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import cn.hutool.core.util.IdUtil;
|
|
||||||
import com.gxwebsoft.common.core.Constants;
|
import com.gxwebsoft.common.core.Constants;
|
||||||
import com.gxwebsoft.common.core.web.ApiResult;
|
import com.gxwebsoft.common.core.web.ApiResult;
|
||||||
import com.gxwebsoft.common.core.web.BaseController;
|
import com.gxwebsoft.common.core.web.BaseController;
|
||||||
@@ -88,6 +88,7 @@ public class SubscriptionOrderController extends BaseController {
|
|||||||
|
|
||||||
JSONObject config = loadSubscriptionConfig();
|
JSONObject config = loadSubscriptionConfig();
|
||||||
final SubscriptionPriceResult price = buildPriceResult(param, config);
|
final SubscriptionPriceResult price = buildPriceResult(param, config);
|
||||||
|
price.setPayPrice(new BigDecimal("0.01"));
|
||||||
if (price.getPayPrice() == null || price.getPayPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
if (price.getPayPrice() == null || price.getPayPrice().compareTo(BigDecimal.ZERO) <= 0) {
|
||||||
return fail("支付金额必须大于0", null);
|
return fail("支付金额必须大于0", null);
|
||||||
}
|
}
|
||||||
@@ -127,7 +128,7 @@ public class SubscriptionOrderController extends BaseController {
|
|||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new JSONObject();
|
return getDefaultSubscriptionConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -138,7 +139,10 @@ public class SubscriptionOrderController extends BaseController {
|
|||||||
BigDecimal factor = BigDecimal.ONE;
|
BigDecimal factor = BigDecimal.ONE;
|
||||||
StringBuilder remark = new StringBuilder();
|
StringBuilder remark = new StringBuilder();
|
||||||
|
|
||||||
if (config == null || config.isEmpty()) {
|
boolean usingDefault = config != null && config.getBooleanValue("defaultConfig");
|
||||||
|
if (usingDefault) {
|
||||||
|
remark.append("订阅价格未配置,已使用默认配置;");
|
||||||
|
} else if (config == null || config.isEmpty()) {
|
||||||
remark.append("未查询到订阅价格配置,已按0元试算;");
|
remark.append("未查询到订阅价格配置,已按0元试算;");
|
||||||
}
|
}
|
||||||
if (originalPrice.compareTo(BigDecimal.ZERO) == 0 && config != null && !config.isEmpty()) {
|
if (originalPrice.compareTo(BigDecimal.ZERO) == 0 && config != null && !config.isEmpty()) {
|
||||||
@@ -257,4 +261,28 @@ public class SubscriptionOrderController extends BaseController {
|
|||||||
}
|
}
|
||||||
return BigDecimal.ONE;
|
return BigDecimal.ONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 默认订阅配置(避免价格为0,可按需改成真实价格)
|
||||||
|
*/
|
||||||
|
private JSONObject getDefaultSubscriptionConfig() {
|
||||||
|
JSONObject config = new JSONObject();
|
||||||
|
config.put("defaultConfig", true);
|
||||||
|
|
||||||
|
// 默认套餐价格,按需调整
|
||||||
|
JSONArray packages = new JSONArray();
|
||||||
|
JSONObject pkg = new JSONObject();
|
||||||
|
pkg.put("id", 2);
|
||||||
|
pkg.put("price", new BigDecimal("1.00"));
|
||||||
|
packages.add(pkg);
|
||||||
|
config.put("packages", packages);
|
||||||
|
|
||||||
|
// 默认系数
|
||||||
|
config.put("renewalDiscount", BigDecimal.ONE);
|
||||||
|
config.put("upgradeDiscount", BigDecimal.ONE);
|
||||||
|
JSONObject payTypeDiscount = new JSONObject();
|
||||||
|
payTypeDiscount.put("12", BigDecimal.ONE);
|
||||||
|
config.put("payTypeDiscount", payTypeDiscount);
|
||||||
|
return config;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package com.gxwebsoft.common.system.entity;
|
package com.gxwebsoft.common.system.entity;
|
||||||
|
|
||||||
import com.baomidou.mybatisplus.annotation.*;
|
import com.baomidou.mybatisplus.annotation.*;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonFormat;
|
||||||
import io.swagger.v3.oas.annotations.media.Schema;
|
import io.swagger.v3.oas.annotations.media.Schema;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
@@ -35,9 +36,11 @@ public class TenantSubscription implements Serializable {
|
|||||||
private Integer version;
|
private Integer version;
|
||||||
|
|
||||||
@Schema(description = "开始时间")
|
@Schema(description = "开始时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date startTime;
|
private Date startTime;
|
||||||
|
|
||||||
@Schema(description = "到期时间")
|
@Schema(description = "到期时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date endTime;
|
private Date endTime;
|
||||||
|
|
||||||
@Schema(description = "是否试用期")
|
@Schema(description = "是否试用期")
|
||||||
@@ -59,9 +62,11 @@ public class TenantSubscription implements Serializable {
|
|||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@Schema(description = "创建时间")
|
@Schema(description = "创建时间")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date createTime;
|
private Date createTime;
|
||||||
|
|
||||||
@Schema(description = "修改时间")
|
@Schema(description = "修改时间1")
|
||||||
|
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
|
||||||
private Date updateTime;
|
private Date updateTime;
|
||||||
|
|
||||||
// 关联查询字段
|
// 关联查询字段
|
||||||
|
|||||||
Reference in New Issue
Block a user