fix: reconcile source currencies and retail token pricing
This commit is contained in:
1 parent
ea9069e332
commit
512ca52262
12 files changed
+458
-12
No files matched your search
@@ -230,8 +230,22 @@ public class CatalogService {
|
||||
return findModel(id);
|
||||
}
|
||||
|
||||
private void validatePricing(Object input) {
|
||||
static void validatePricing(Object input) {
|
||||
if (!(input instanceof Map<?,?> prices)) return;
|
||||
if (prices.get("listPriceUsd") != null && prices.get("listPriceCny") != null)
|
||||
throw new ApiException("INVALID_PRICE", "标准价只能选择一种币种:人民币或美元");
|
||||
Object discount = prices.get("discount");
|
||||
if (discount != null) {
|
||||
try {
|
||||
var value = new java.math.BigDecimal(String.valueOf(discount));
|
||||
if (value.signum() < 0 || value.compareTo(java.math.BigDecimal.TEN) > 0) throw new NumberFormatException();
|
||||
} catch (NumberFormatException e) { throw new ApiException("INVALID_PRICE", "折扣须在 0–10 折之间,例如 5.5 表示 5.5 折"); }
|
||||
}
|
||||
if (prices.get("listPriceCny") != null && prices.get("exchangeRate") != null) {
|
||||
try {
|
||||
if (new java.math.BigDecimal(String.valueOf(prices.get("exchangeRate"))).compareTo(java.math.BigDecimal.ONE) != 0) throw new NumberFormatException();
|
||||
} catch (NumberFormatException e) { throw new ApiException("INVALID_PRICE", "人民币原价的换算系数必须为 1"); }
|
||||
}
|
||||
for(String field: List.of("price","input","output","cachedInput")) {
|
||||
Object amount=prices.get(field);
|
||||
if(amount==null) continue;
|
||||
|
||||
Reference in new issue
Block a user