feat(distribution): 分站可下调收号比例且不超过主站上限
让分销站能按自身能力下调收号比例扩大利润,同时把主站回收比例作为硬边界,避免分站把比例加得比主站更高。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package distribution
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"testing"
|
||||
"time"
|
||||
@@ -8,6 +9,7 @@ import (
|
||||
"hfb_sys/backend/internal/database"
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
"gorm.io/datatypes"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -666,7 +668,19 @@ func TestDistributionBrandingAndMarkup(t *testing.T) {
|
||||
t.Fatalf("cleared listing_qrcode_url = %q, want empty", qrCleared.ListingQrcodeURL)
|
||||
}
|
||||
|
||||
// Verify PublicSiteInfo contains branding
|
||||
delta := 3.5
|
||||
ratioUpdated, err := repo.UpdateSite(t.Context(), 0, site.ID, UpdateSiteRequest{ReceiveRatioDelta: &delta})
|
||||
if err != nil {
|
||||
t.Fatalf("UpdateSite receive ratio failed: %v", err)
|
||||
}
|
||||
if ratioUpdated.ReceiveRatioDelta != 3.5 {
|
||||
t.Fatalf("receive_ratio_delta = %v, want 3.5", ratioUpdated.ReceiveRatioDelta)
|
||||
}
|
||||
negative := -1.0
|
||||
if _, err := repo.UpdateSite(t.Context(), 0, site.ID, UpdateSiteRequest{ReceiveRatioDelta: &negative}); !errors.Is(err, ErrInvalidAmount) {
|
||||
t.Fatalf("negative receive ratio err = %v, want ErrInvalidAmount", err)
|
||||
}
|
||||
|
||||
pubInfo, err := repo.GetPublicSiteInfo(t.Context(), "brand_site", "")
|
||||
if err != nil {
|
||||
t.Fatalf("GetPublicSiteInfo failed: %v", err)
|
||||
@@ -674,6 +688,9 @@ func TestDistributionBrandingAndMarkup(t *testing.T) {
|
||||
if pubInfo.LogoURL != "https://cdn.example.com/logo.png" {
|
||||
t.Fatalf("expected LogoURL, got: %+v", pubInfo)
|
||||
}
|
||||
if pubInfo.ReceiveRatioDelta != 3.5 {
|
||||
t.Fatalf("public receive_ratio_delta = %v, want 3.5", pubInfo.ReceiveRatioDelta)
|
||||
}
|
||||
|
||||
faviconOnly := "https://cdn.example.com/favicon2.ico"
|
||||
partial, err := repo.UpdateSiteBranding(t.Context(), 0, site.ID, UpdateSiteBrandingRequest{FaviconURL: &faviconOnly})
|
||||
@@ -746,12 +763,24 @@ func TestDistributionReceivedListingsAndWallet(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
summary, err := json.Marshal(map[string]any{
|
||||
"price_breakdown": map[string]any{
|
||||
"seller_ratio": 43.0,
|
||||
"seller_total_price": 232.6,
|
||||
"buyer_ratio": 38.0,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
ga := model.GameAccount{
|
||||
OwnerID: user.ID,
|
||||
GameName: "delta_force",
|
||||
ServerRegion: "cn",
|
||||
LoginPlatform: "pc",
|
||||
Title: "满配三角洲账号",
|
||||
HafCoinAmount: 100_000_000,
|
||||
AssetSummary: datatypes.JSON(summary),
|
||||
}
|
||||
if err := db.Create(&ga).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -786,6 +815,9 @@ func TestDistributionReceivedListingsAndWallet(t *testing.T) {
|
||||
if item.ListingNo != "RL-99001" || item.GameName != "delta_force" || item.OwnerNickname != "seller01" {
|
||||
t.Fatalf("unexpected received listing: %+v", item)
|
||||
}
|
||||
if item.SellerRatio != 43 || item.SellerTotalPriceCent != 23260 || item.BuyerRatio != 38 {
|
||||
t.Fatalf("expected main-site receive pricing, got ratio=%v price=%d buyer=%v", item.SellerRatio, item.SellerTotalPriceCent, item.BuyerRatio)
|
||||
}
|
||||
|
||||
if err := repo.UpdateReceivedListingStatus(t.Context(), 0, listing.ID, "inactive"); !errors.Is(err, ErrInvalidListingStatus) {
|
||||
t.Fatalf("inactive status err = %v", err)
|
||||
|
||||
Reference in New Issue
Block a user