页面调整
This commit is contained in:
1 parent
5bc5a91b3b
commit
e14e7c51db
5 files changed
+54
-3
No files matched your search
@@ -100,6 +100,7 @@ public class RentalApiController {
|
||||
RentalOrders.validatePackage(product);
|
||||
Map<String, Object> price = RentalPricing.price(product, data);
|
||||
return AjaxResult.success(map("package_id", price.get("id"), "network", price.get("network"),
|
||||
"billing_mode", price.get("billing_mode"), "requested_resource_quantity", price.get("requested_resource_quantity"),
|
||||
"duration_seconds", price.get("duration_seconds"), "amount", amount(price, "sale_amount").toPlainString(),
|
||||
"resource_quantity", price.get("resource_quantity"), "currency", "USDT"));
|
||||
}
|
||||
|
||||
@@ -80,6 +80,10 @@ public class RentalOrders {
|
||||
if (request.containsKey("duration_seconds")) {
|
||||
hash = RentalCrypto.sha256(hash + ":" + number(request, "duration_seconds"));
|
||||
}
|
||||
// 保留未提交资源数量的旧摘要;同单号不能更改资源数量重新冻结资金。
|
||||
if (request.containsKey("resource_quantity")) {
|
||||
hash = RentalCrypto.sha256(hash + ":resource_quantity:" + number(request, "resource_quantity"));
|
||||
}
|
||||
if (existing != null) {
|
||||
require(hash.equals(text(existing, "request_hash")), "同一商户订单号参数不一致");
|
||||
return existing;
|
||||
|
||||
@@ -22,14 +22,25 @@ public final class RentalPricing {
|
||||
require(base > 0 && duration > 0 && duration % base == 0
|
||||
&& ("PER_ORDER".equals(billingMode) || duration / base <= 720), "租赁时长必须为套餐基础租期的1至720倍");
|
||||
BigDecimal units = "PER_ORDER".equals(billingMode) ? BigDecimal.ONE : BigDecimal.valueOf(duration / base);
|
||||
// resource_quantity表示本次选择的基础资源,DURATION再乘租期倍数。
|
||||
long baseQuantity = number(product, "resource_quantity");
|
||||
long selectedQuantity = request.containsKey("resource_quantity")
|
||||
? number(request, "resource_quantity") : baseQuantity;
|
||||
require(baseQuantity > 0 && selectedQuantity > 0 && selectedQuantity % baseQuantity == 0
|
||||
&& selectedQuantity / baseQuantity <= 720, "资源数量必须为套餐基础资源的1至720倍");
|
||||
require(!"PER_ORDER".equals(billingMode) || (duration == base && selectedQuantity == baseQuantity),
|
||||
"按次套餐的资源数量与租期固定");
|
||||
long resourceUnits = selectedQuantity / baseQuantity;
|
||||
Map<String, Object> result = new HashMap<>(product);
|
||||
result.put("requested_resource_quantity", selectedQuantity);
|
||||
result.put("billing_mode", billingMode);
|
||||
result.put("duration_seconds", duration);
|
||||
if ("DURATION".equals(billingMode)) {
|
||||
long quantity = number(product, "resource_quantity");
|
||||
long multiplied = Math.multiplyExact(quantity, units.longValueExact());
|
||||
long multiplied = Math.multiplyExact(selectedQuantity, units.longValueExact());
|
||||
require(multiplied > 0, "套餐资源数量超过允许范围");
|
||||
result.put("resource_quantity", multiplied);
|
||||
}
|
||||
units = units.multiply(BigDecimal.valueOf(resourceUnits));
|
||||
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