fix(distribution): 分成改为分主站提价利润,分站自主提价溢价全额归卖方

- 文档:升级至 v0.7,固化号主保底、主站提价利润分账(35/40/25)与分站加价溢价独享逻辑
- 定价:修正货架兑换比例调价方向为调减比例提价(site_ratio = base_ratio - delta)
- 分账:分成基数剔除号主成本与分站加价,提价利润按规则切分,分站自主加价溢价 100% 归卖出方
- 前端:更新分销后台提价说明文案,提示调减比例提高售价且溢价归本站
This commit is contained in:
yml2213
2026-09-08 19:45:05 +08:00
parent d762b33f54
commit 4aab9e7e33
11 changed files with 176 additions and 132 deletions
@@ -701,7 +701,7 @@ func TestListPublicWithDistributionSiteCode(t *testing.T) {
site := model.DistributionSite{SiteCode: "site_alpha", SiteName: "分销A", Domain: "a.com", Status: "active", DisplayAccountEnabled: true}
db.Create(&site)
dsa := model.DistributionSiteAccount{SiteID: site.ID, AccountID: account1.ID, ListingID: l1.ID, DisplayStatus: "enabled", ShelfRatioDelta: 25}
dsa := model.DistributionSiteAccount{SiteID: site.ID, AccountID: account1.ID, ListingID: l1.ID, DisplayStatus: "enabled", ShelfRatioDelta: 20}
db.Create(&dsa)
res, err := repo.ListPublic(context.Background(), PublicListQuery{
@@ -713,16 +713,17 @@ func TestListPublicWithDistributionSiteCode(t *testing.T) {
if len(res.Items) != 1 || res.Items[0].ListingNo != "L101" {
t.Fatalf("expected only L101, got %+v", res.Items)
}
if res.Items[0].PriceCent != 8000 {
t.Fatalf("expected public price 8000 with ratio delta, got %d", res.Items[0].PriceCent)
// 主站 100 元 (10000 分,100 比例);分站提价减 20 比例 (80 比例) → 售价 125 元 (12500 分)
if res.Items[0].PriceCent != 12500 {
t.Fatalf("expected public price 12500 with ratio delta, got %d", res.Items[0].PriceCent)
}
detail, err := repo.FindPublic(context.Background(), l1.ID, "site_alpha")
if err != nil {
t.Fatalf("FindPublic err: %v", err)
}
if detail.PriceCent != 8000 {
t.Fatalf("expected detail price 8000 with ratio delta, got %d", detail.PriceCent)
if detail.PriceCent != 12500 {
t.Fatalf("expected detail price 12500 with ratio delta, got %d", detail.PriceCent)
}
mainDetail, err := repo.FindPublic(context.Background(), l1.ID, "")
if err != nil {
@@ -13,7 +13,9 @@ func BaseExchangeRatio(hafCoinAmount, priceCent int64) float64 {
return roundRatio(CoinWan(hafCoinAmount) / centToYuan(priceCent))
}
// ApplyShelfRatio 按分站加价比例重算售价。delta=0 时保持原价,避免四舍五入漂移。
// ApplyShelfRatio 按分站加价比例重算售价。
// 在「1 元兑换多少万哈夫币」的比例机制下:比例越小,售价越高(提价);比例越大,售价越低(打折)。
// 分站货架自主提价应调小兑换比例(siteRatio = baseRatio - ratioDelta),使分站售价高于主站基准价。
func ApplyShelfRatio(hafCoinAmount, basePriceCent int64, ratioDelta float64) (priceCent int64, baseRatio, siteRatio float64) {
baseRatio = BaseExchangeRatio(hafCoinAmount, basePriceCent)
if ratioDelta < 0 {
@@ -22,13 +24,13 @@ func ApplyShelfRatio(hafCoinAmount, basePriceCent int64, ratioDelta float64) (pr
if baseRatio <= 0 || ratioDelta == 0 {
return basePriceCent, baseRatio, baseRatio
}
siteRatio = roundRatio(baseRatio + ratioDelta)
if siteRatio <= 0 {
return basePriceCent, baseRatio, baseRatio
siteRatio = roundRatio(baseRatio - ratioDelta)
if siteRatio <= 0.01 {
siteRatio = 0.01
}
priceCent = yuanToCent(CoinWan(hafCoinAmount) / siteRatio)
if priceCent < 0 {
priceCent = 0
if priceCent < basePriceCent {
priceCent = basePriceCent
}
return priceCent, baseRatio, siteRatio
}
@@ -2,17 +2,18 @@ package listing
import "testing"
func TestApplyShelfRatioIncreasesExchangeRatio(t *testing.T) {
// 100M = 10000 万,主站 100 元 → 1 元 = 100w
price, base, site := ApplyShelfRatio(100_000_000, 10000, 25)
func TestApplyShelfRatioIncreasesPriceByLoweringRatio(t *testing.T) {
// 100M = 10000 万,主站 100 元 → 1 元 = 100w 比例
// 分站提价减 20 比例 → 1 元 = 80w 比例 → 售价 125 元 (12500 分)
price, base, site := ApplyShelfRatio(100_000_000, 10000, 20)
if base != 100 {
t.Fatalf("base ratio = %v, want 100", base)
}
if site != 125 {
t.Fatalf("site ratio = %v, want 125", site)
if site != 80 {
t.Fatalf("site ratio = %v, want 80", site)
}
if price != 8000 {
t.Fatalf("site price = %d, want 8000", price)
if price != 12500 {
t.Fatalf("site price = %d, want 12500", price)
}
}