chore(init): 初始化解忧商行项目并完成 Phase 0 基座

This commit is contained in:
yml2213
2026-10-30 11:46:10 +08:00
commit 8d9481c251
689 changed files with 138703 additions and 0 deletions
@@ -0,0 +1,36 @@
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 按分站加价比例重算售价。
// 在「1 元兑换多少万哈夫币」的比例机制下:比例越小,售价越高(提价);比例越大,售价越低(打折)。
// 分站货架自主提价应调小兑换比例(siteRatio = baseRatio - ratioDelta),使分站售价高于主站基准价。
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.01 {
siteRatio = 0.01
}
priceCent = yuanToCent(CoinWan(hafCoinAmount) / siteRatio)
if priceCent < basePriceCent {
priceCent = basePriceCent
}
return priceCent, baseRatio, siteRatio
}