From 5bc5a91b3b07a1c7afa1be90c568e01f41189064 Mon Sep 17 00:00:00 2001 From: luqingjie <544309509@qq.com> Date: Mon, 26 Oct 2026 11:23:58 -0400 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=A5=97=E9=A4=90=E8=AE=A1?= =?UTF-8?q?=E8=B4=B9=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/ruoyi/system/rental/RentalOrders.java | 4 ++++ .../com/ruoyi/system/rental/RentalPricing.java | 15 +++++++++++++-- sql/rent_billing_mode_migration.sql | 11 +++++++++++ sql/rent_init.sql | 2 ++ 4 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 sql/rent_billing_mode_migration.sql diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalOrders.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalOrders.java index a5d98e9..6daf6b8 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalOrders.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalOrders.java @@ -126,6 +126,8 @@ public class RentalOrders { hash, "package_id", packageId, + "billing_mode", + text(product, "billing_mode").isEmpty() ? "DURATION" : text(product, "billing_mode"), "network", text(product, "network"), "receiver_address", @@ -182,6 +184,8 @@ public class RentalOrders { BigDecimal percent = new BigDecimal(text(row, "supplier_fee_percent")); BigDecimal fee = gross.multiply(percent).movePointLeft(2).setScale(6, RoundingMode.HALF_UP); require( + (text(row, "billing_mode").isEmpty() || "DURATION".equals(text(row, "billing_mode")) || "PER_ORDER".equals(text(row, "billing_mode"))) + && sale.signum() > 0 && gross.signum() > 0 && gross.compareTo(sale) <= 0 diff --git a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPricing.java b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPricing.java index 8a60f56..0420cbd 100644 --- a/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPricing.java +++ b/ruoyi-system/src/main/java/com/ruoyi/system/rental/RentalPricing.java @@ -11,14 +11,25 @@ public final class RentalPricing { private RentalPricing() { } public static Map price(Map product, Map request) { + String billingMode = text(product, "billing_mode").trim().toUpperCase(); + if (billingMode.isEmpty()) { + billingMode = "DURATION"; + } + require("DURATION".equals(billingMode) || "PER_ORDER".equals(billingMode), "套餐计费模式无效"); long base = number(product, "duration_seconds"); long duration = request.containsKey("duration_seconds") ? number(request, "duration_seconds") : base; require(base > 0 && duration > 0 && duration % base == 0 - && duration / base <= 720, "租赁时长必须为套餐基础租期的1至720倍"); - BigDecimal units = BigDecimal.valueOf(duration / base); + && ("PER_ORDER".equals(billingMode) || duration / base <= 720), "租赁时长必须为套餐基础租期的1至720倍"); + BigDecimal units = "PER_ORDER".equals(billingMode) ? BigDecimal.ONE : BigDecimal.valueOf(duration / base); Map result = new HashMap<>(product); result.put("duration_seconds", duration); + if ("DURATION".equals(billingMode)) { + long quantity = number(product, "resource_quantity"); + long multiplied = Math.multiplyExact(quantity, units.longValueExact()); + require(multiplied > 0, "套餐资源数量超过允许范围"); + result.put("resource_quantity", multiplied); + } result.put("sale_amount", amount(product, "sale_amount").multiply(units)); result.put("supplier_amount", amount(product, "supplier_amount").multiply(units)); require(amount(result, "sale_amount").precision() <= 30 diff --git a/sql/rent_billing_mode_migration.sql b/sql/rent_billing_mode_migration.sql new file mode 100644 index 0000000..2277bdc --- /dev/null +++ b/sql/rent_billing_mode_migration.sql @@ -0,0 +1,11 @@ +-- 为已有租赁套餐增加计费模式;默认保持原有按时长计费。 +ALTER TABLE rent_package + ADD COLUMN billing_mode VARCHAR(16) NOT NULL DEFAULT 'DURATION' + COMMENT '计费模式:DURATION按时长,PER_ORDER按订单次数' AFTER sale_amount; + +ALTER TABLE rent_order + ADD COLUMN billing_mode VARCHAR(16) NOT NULL DEFAULT 'DURATION' + COMMENT '计费模式快照' AFTER package_id; + +-- 示例:将指定套餐改为按订单次数计费(每次创建订单固定收取 sale_amount)。 +-- UPDATE rent_package SET billing_mode = 'PER_ORDER' WHERE id = 3; diff --git a/sql/rent_init.sql b/sql/rent_init.sql index 6b6aa54..cd408eb 100644 --- a/sql/rent_init.sql +++ b/sql/rent_init.sql @@ -151,6 +151,7 @@ CREATE TABLE IF NOT EXISTS `rent_package` ( `redundancy_percent` DECIMAL(10,4) NOT NULL DEFAULT 20.0000 COMMENT '资源冗余百分数,20表示20%,必须大于0;目标量必须严格大于请求量,创建订单锁定', `duration_seconds` INT NOT NULL COMMENT '业务租期秒,不代表链上自动撤销', `sale_amount` DECIMAL(30,6) NOT NULL DEFAULT 0 COMMENT '售价USDT', + `billing_mode` VARCHAR(16) NOT NULL DEFAULT 'DURATION' COMMENT '计费模式:DURATION按时长,PER_ORDER按订单次数', `supplier_amount` DECIMAL(30,6) NOT NULL DEFAULT 0 COMMENT '供应商扣平台手续费前毛收入USDT,包含约定链上操作成本,不是净结算额', `supplier_fee_percent` DECIMAL(7,4) NOT NULL COMMENT '平台向供应商收取的手续费百分数,必须显式配置且大于0小于100,5表示5%;下单锁定', `fee_limit_sun` BIGINT NOT NULL DEFAULT 0 COMMENT '节点单笔操作本地费用预算SUN,零不可广播;委托撤销非合约交易,不假定协议支持fee_limit硬上限', @@ -207,6 +208,7 @@ CREATE TABLE IF NOT EXISTS `rent_order` ( `merchant_order_no` VARCHAR(64) NOT NULL COMMENT '商户订单号,兼作业务幂等键', `request_hash` VARCHAR(64) NOT NULL COMMENT '原请求规范化摘要,同编号不同内容拒绝', `package_id` BIGINT NOT NULL COMMENT 'rent_package.id', + `billing_mode` VARCHAR(16) NOT NULL DEFAULT 'DURATION' COMMENT '计费模式快照:DURATION或PER_ORDER', `network` VARCHAR(16) CHARACTER SET ascii COLLATE ascii_bin NOT NULL COMMENT '网络:NILE、MAINNET,必须与所有关联对象一致', `receiver_address` VARCHAR(64) CHARACTER SET ascii COLLATE ascii_bin NOT NULL COMMENT '资源接收者,TRON Base58Check地址', `resource_type` VARCHAR(16) NOT NULL COMMENT '套餐资源类型快照:ENERGY能量、BANDWIDTH带宽,订单创建后不可修改',