package listing // CoinWan 将内部哈夫币数量转为万。 func CoinWan(hafCoinAmount int64) float64 { return float64(hafCoinAmount) / 10000 } // BaseExchangeRatio 是主站挂牌的「1 元兑换哈夫币」比例。 func BaseExchangeRatio(hafCoinAmount, priceCent int64) float64 { if hafCoinAmount <= 0 || priceCent <= 0 { return 0 } return roundRatio(CoinWan(hafCoinAmount) / centToYuan(priceCent)) } // ApplyShelfRatio 按分站加价比例重算售价。delta=0 时保持原价,避免四舍五入漂移。 func ApplyShelfRatio(hafCoinAmount, basePriceCent int64, ratioDelta float64) (priceCent int64, baseRatio, siteRatio float64) { baseRatio = BaseExchangeRatio(hafCoinAmount, basePriceCent) if ratioDelta < 0 { ratioDelta = 0 } if baseRatio <= 0 || ratioDelta == 0 { return basePriceCent, baseRatio, baseRatio } siteRatio = roundRatio(baseRatio + ratioDelta) if siteRatio <= 0 { return basePriceCent, baseRatio, baseRatio } priceCent = yuanToCent(CoinWan(hafCoinAmount) / siteRatio) if priceCent < 0 { priceCent = 0 } return priceCent, baseRatio, siteRatio }