refactor(listing): 卖家发布定价改用整数分与基点

This commit is contained in:
yml2213
2026-10-30 14:49:33 +08:00
parent 37e1980d2d
commit ce93f1636d
18 changed files with 1492 additions and 343 deletions
@@ -19,12 +19,16 @@ type saleFixedMarkupRule struct {
MinM float64 `json:"min_m"`
MaxM float64 `json:"max_m"`
MarkupAmount float64 `json:"markup_amount"`
// MarkupAmountCent 是规范化固定加价(分);大于 0 时优先使用。
MarkupAmountCent int64 `json:"markup_amount_cent,omitempty"`
}
type saleRatioAdjustmentRule struct {
MinM float64 `json:"min_m"`
MaxM float64 `json:"max_m"`
RatioSubtract float64 `json:"ratio_subtract"`
// RatioSubtractBPS 是规范化比例修正(基点);大于 0 时优先使用。
RatioSubtractBPS int64 `json:"ratio_subtract_bps,omitempty"`
}
type externalPlatformPricing struct {
@@ -87,7 +91,7 @@ func filterFixedMarkupRules(rules []saleFixedMarkupRule) []saleFixedMarkupRule {
for _, rule := range rules {
if !isFiniteNonNegative(rule.MinM) ||
!isFiniteNonNegative(rule.MaxM) ||
!isFiniteNonNegative(rule.MarkupAmount) ||
(rule.MarkupAmountCent <= 0 && !isFiniteNonNegative(rule.MarkupAmount)) ||
(rule.MaxM > 0 && rule.MaxM < rule.MinM) {
continue
}
@@ -101,7 +105,7 @@ func filterRatioAdjustmentRules(rules []saleRatioAdjustmentRule) []saleRatioAdju
for _, rule := range rules {
if !isFiniteNonNegative(rule.MinM) ||
!isFiniteNonNegative(rule.MaxM) ||
!isFiniteNonNegative(rule.RatioSubtract) ||
(rule.RatioSubtractBPS <= 0 && !isFiniteNonNegative(rule.RatioSubtract)) ||
(rule.MaxM > 0 && rule.MaxM < rule.MinM) {
continue
}
@@ -122,6 +126,25 @@ func calculateExternalPlatformPricing(
consumablePrice float64,
config salePriceConfig,
) externalPlatformPricing {
// 新配置提供了 cent/bps 字段时,计算优先走整数路径。
if salePriceConfigHasCentRules(config) {
hafCoinAmount := int64(math.Round(coinM * float64(hafCoinUnitsPerM)))
result := calculateExternalPlatformPricingCent(
hafCoinAmount,
ratioToBPS(sellerRatio),
centFromYuanFloat(sellerCoinBasePrice),
centFromYuanFloat(consumablePrice),
config,
)
return externalPlatformPricing{
BuyerCoinBasePrice: centToYuanFloat(result.BuyerCoinBasePriceCent),
BuyerTotalPrice: centToYuanFloat(result.BuyerTotalPriceCent),
BuyerRatio: bpsToRatio(result.BuyerRatioBPS),
PlatformMarkupPrice: centToYuanFloat(result.PlatformMarkupCent),
RuleType: result.RuleType,
}
}
sellerCoinBasePrice = nonNegativeMoney(sellerCoinBasePrice)
consumablePrice = nonNegativeMoney(consumablePrice)
sellerTotalPrice := roundMoney(sellerCoinBasePrice + consumablePrice)