添加套餐计费模式
This commit is contained in:
1 parent
829f357bae
commit
5bc5a91b3b
4 files changed
+30
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -11,14 +11,25 @@ public final class RentalPricing {
|
||||
private RentalPricing() { }
|
||||
|
||||
public static Map<String, Object> price(Map<String, Object> product, Map<String, Object> 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<String, Object> 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
|
||||
|
||||
Reference in new issue
Block a user