feat(distribution): 分站可下调收号比例且不超过主站上限
让分销站能按自身能力下调收号比例扩大利润,同时把主站回收比例作为硬边界,避免分站把比例加得比主站更高。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1008,3 +1008,139 @@ func TestListMineSiteIsolation(t *testing.T) {
|
||||
t.Fatalf("expected 2 listings, got %d", len(allItems))
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDistributionListingUsesMainSiteReceiveRatio(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
t.Fatalf("migrate err: %v", err)
|
||||
}
|
||||
svc := NewService(NewRepository(db, nil), stubConfigReader{})
|
||||
|
||||
user := model.User{Phone: "18800000021", Nickname: "分销收号卖家", RealnameStatus: "verified", Status: "active"}
|
||||
if err := db.Create(&user).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
site := model.DistributionSite{
|
||||
SiteCode: "dist_ratio_1",
|
||||
SiteName: "收号比例站",
|
||||
Domain: "ratio.example.com",
|
||||
Status: "active",
|
||||
DisplayAccountEnabled: true,
|
||||
}
|
||||
if err := db.Create(&site).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dto, err := svc.Create(context.Background(), user.ID, CreateRequest{
|
||||
Title: "分销收号商品",
|
||||
ServerRegion: "QQ",
|
||||
LoginPlatform: "PC",
|
||||
RankLevel: "钻石",
|
||||
HafCoinAmount: 100_000_000,
|
||||
PriceCent: 100,
|
||||
DepositAmountCent: 15000,
|
||||
ScreenshotURLS: []string{"https://example.com/ratio.png"},
|
||||
AssetSummary: map[string]any{
|
||||
"fire_level": 50,
|
||||
"season_insurance": "3*3",
|
||||
"stamina_level": "7级",
|
||||
"load_level": "7级",
|
||||
"daily_loss_m": 10,
|
||||
"online_time": map[string]any{
|
||||
"start": "09:00",
|
||||
"end": "23:00",
|
||||
},
|
||||
"price_breakdown": map[string]any{
|
||||
"seller_ratio": 10.0,
|
||||
"seller_total_price": 1.0,
|
||||
"buyer_total_price": 1.0,
|
||||
},
|
||||
},
|
||||
AgreedVirtualAssetSale: true,
|
||||
AgreedSellerAgreement: true,
|
||||
}, "dist_ratio_1")
|
||||
if err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
|
||||
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
||||
if pricing.SellerRatio != 43 {
|
||||
t.Fatalf("distribution receive seller_ratio = %v, want 43 from main-site ratio_config", pricing.SellerRatio)
|
||||
}
|
||||
if pricing.SellerTotalPriceCent != 23260 {
|
||||
t.Fatalf("seller_total_price_cent = %d, want 23260", pricing.SellerTotalPriceCent)
|
||||
}
|
||||
if dto.PriceCent != 26320 {
|
||||
t.Fatalf("listing PriceCent = %d, want 26320 from main-site sale price", dto.PriceCent)
|
||||
}
|
||||
if dto.DistributionSiteCode != "dist_ratio_1" {
|
||||
t.Fatalf("DistributionSiteCode = %s, want dist_ratio_1", dto.DistributionSiteCode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateDistributionListingAppliesSiteReceiveRatioDelta(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
if err := database.MigrateListingLifecycleTestSchema(db); err != nil {
|
||||
t.Fatalf("migrate err: %v", err)
|
||||
}
|
||||
svc := NewService(NewRepository(db, nil), stubConfigReader{})
|
||||
|
||||
user := model.User{Phone: "18800000022", Nickname: "分销下调卖家", RealnameStatus: "verified", Status: "active"}
|
||||
if err := db.Create(&user).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
site := model.DistributionSite{
|
||||
SiteCode: "dist_ratio_down",
|
||||
SiteName: "下调收号站",
|
||||
Domain: "ratio-down.example.com",
|
||||
Status: "active",
|
||||
DisplayAccountEnabled: true,
|
||||
ReceiveRatioDelta: 3,
|
||||
}
|
||||
if err := db.Create(&site).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
dto, err := svc.Create(context.Background(), user.ID, CreateRequest{
|
||||
Title: "分销下调收号",
|
||||
ServerRegion: "QQ",
|
||||
LoginPlatform: "PC",
|
||||
RankLevel: "钻石",
|
||||
HafCoinAmount: 100_000_000,
|
||||
PriceCent: 100,
|
||||
DepositAmountCent: 15000,
|
||||
ScreenshotURLS: []string{"https://example.com/ratio-down.png"},
|
||||
AssetSummary: map[string]any{
|
||||
"fire_level": 50,
|
||||
"season_insurance": "3*3",
|
||||
"stamina_level": "7级",
|
||||
"load_level": "7级",
|
||||
"daily_loss_m": 10,
|
||||
"online_time": map[string]any{
|
||||
"start": "09:00",
|
||||
"end": "23:00",
|
||||
},
|
||||
"price_breakdown": map[string]any{
|
||||
"seller_ratio": 50.0,
|
||||
},
|
||||
},
|
||||
AgreedVirtualAssetSale: true,
|
||||
AgreedSellerAgreement: true,
|
||||
}, "dist_ratio_down")
|
||||
if err != nil {
|
||||
t.Fatalf("Create failed: %v", err)
|
||||
}
|
||||
pricing := ReceivePricingFromAssetSummary(mustMarshalSummary(t, dto.AssetSummary))
|
||||
if pricing.SellerRatio != 40 {
|
||||
t.Fatalf("seller_ratio = %v, want 40 after site delta 3 below main-site 43", pricing.SellerRatio)
|
||||
}
|
||||
}
|
||||
|
||||
func mustMarshalSummary(t *testing.T, summary map[string]any) []byte {
|
||||
t.Helper()
|
||||
raw, err := json.Marshal(summary)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return raw
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user