fix(distribution): 修正商品归属回填、禁止全站灌货并拒绝无效站点头
用货架写入时间与上传来源回滚误标产地,不再依赖绝对时间戳;同步仅收本站上传与显式勾选。
This commit is contained in:
@@ -225,7 +225,7 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
listing1 := model.RentalListing{
|
||||
mainListing := model.RentalListing{
|
||||
ListingNo: "L10001",
|
||||
AccountID: account1.ID,
|
||||
OwnerID: 1,
|
||||
@@ -235,11 +235,36 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
||||
ReviewStatus: "approved",
|
||||
InTransaction: false,
|
||||
}
|
||||
if err := db.Create(&listing1).Error; err != nil {
|
||||
if err := db.Create(&mainListing).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ownAccount := model.GameAccount{
|
||||
Title: "本站上传号",
|
||||
GameName: "delta_force",
|
||||
ServerRegion: "QQ区",
|
||||
LoginPlatform: "PC",
|
||||
Status: "active",
|
||||
}
|
||||
if err := db.Create(&ownAccount).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
siteID := site.ID
|
||||
ownListing := model.RentalListing{
|
||||
ListingNo: "L10003",
|
||||
AccountID: ownAccount.ID,
|
||||
OwnerID: 2,
|
||||
PriceCent: 1800,
|
||||
DepositAmountCent: 8000,
|
||||
Status: "published",
|
||||
ReviewStatus: "approved",
|
||||
DistributionSiteID: &siteID,
|
||||
SourceChannel: site.SiteCode,
|
||||
}
|
||||
if err := db.Create(&ownListing).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 草稿状态的商品不应该被同步
|
||||
listingDraft := model.RentalListing{
|
||||
ListingNo: "L10002",
|
||||
AccountID: 999,
|
||||
@@ -253,17 +278,16 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// 首次同步:应当成功新增 1 条,跳过 0 条
|
||||
res1, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID)
|
||||
// 默认同步不得灌入主站全量目录,只收本站上传货
|
||||
resMain, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("SyncSiteAccounts err = %v", err)
|
||||
t.Fatalf("SyncSiteAccounts own-only err = %v", err)
|
||||
}
|
||||
if res1.SyncedCount != 1 || res1.SkippedCount != 0 || res1.TotalActive != 1 {
|
||||
t.Fatalf("unexpected res1: %+v", res1)
|
||||
if resMain.SyncedCount != 1 || resMain.SkippedCount != 0 || resMain.TotalActive != 1 {
|
||||
t.Fatalf("unexpected own-only res: %+v", resMain)
|
||||
}
|
||||
|
||||
// 再次同步:幂等保证,跳过 1 条,新增 0 条
|
||||
res2, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID)
|
||||
res2, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, nil)
|
||||
if err != nil {
|
||||
t.Fatalf("SyncSiteAccounts retry err = %v", err)
|
||||
}
|
||||
@@ -271,35 +295,51 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
||||
t.Fatalf("unexpected res2: %+v", res2)
|
||||
}
|
||||
|
||||
// 验证管理后台列表查询携带丰富字段
|
||||
if _, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, []uint64{999999}); !errors.Is(err, ErrSyncListingNotFound) {
|
||||
t.Fatalf("missing listing_ids err = %v", err)
|
||||
}
|
||||
|
||||
resSelect, err := repo.SyncSiteAccounts(t.Context(), 0, site.ID, []uint64{mainListing.ID})
|
||||
if err != nil {
|
||||
t.Fatalf("explicit select err = %v", err)
|
||||
}
|
||||
if resSelect.SyncedCount != 1 || resSelect.SkippedCount != 1 || resSelect.TotalActive != 2 {
|
||||
t.Fatalf("unexpected explicit select res: %+v", resSelect)
|
||||
}
|
||||
|
||||
displays, err := repo.ListAccountDisplays(t.Context(), site.ID, "")
|
||||
if err != nil {
|
||||
t.Fatalf("ListAccountDisplays err = %v", err)
|
||||
}
|
||||
if len(displays) != 1 {
|
||||
t.Fatalf("expected 1 display, got %d", len(displays))
|
||||
if len(displays) != 2 {
|
||||
t.Fatalf("expected 2 displays, got %d", len(displays))
|
||||
}
|
||||
d := displays[0]
|
||||
if d.Title != "三角洲极品金枪号" || d.GameName != "delta_force" || d.PriceCent != 2500 || d.DepositAmountCent != 10000 || d.ListingNo != "L10001" {
|
||||
t.Fatalf("unexpected enriched display: %+v", d)
|
||||
byNo := map[string]AccountDisplayDTO{}
|
||||
for _, item := range displays {
|
||||
byNo[item.ListingNo] = item
|
||||
}
|
||||
mainDisplay, ok := byNo["L10001"]
|
||||
if !ok || mainDisplay.Title != "三角洲极品金枪号" || mainDisplay.PriceCent != 2500 || mainDisplay.DepositAmountCent != 10000 {
|
||||
t.Fatalf("unexpected main display: %+v", byNo)
|
||||
}
|
||||
if _, ok := byNo["L10003"]; !ok {
|
||||
t.Fatalf("missing own-site display: %+v", byNo)
|
||||
}
|
||||
|
||||
// 验证公共端点浏览查询
|
||||
pubList, err := repo.ListPublicSiteListings(t.Context(), site.SiteCode, 1, 20)
|
||||
if err != nil {
|
||||
t.Fatalf("ListPublicSiteListings err = %v", err)
|
||||
}
|
||||
if pubList.Total != 1 || len(pubList.Items) != 1 {
|
||||
t.Fatalf("expected 1 public item, got %+v", pubList)
|
||||
}
|
||||
if pubList.Items[0].Title != "三角洲极品金枪号" || pubList.Items[0].SiteCode != site.SiteCode {
|
||||
t.Fatalf("unexpected public item: %+v", pubList.Items[0])
|
||||
if pubList.Total != 2 || len(pubList.Items) != 2 {
|
||||
t.Fatalf("expected 2 public items, got %+v", pubList)
|
||||
}
|
||||
|
||||
// 下架该展示账号后,公共端点不再返回
|
||||
if _, err := repo.UpdateAccountDisplay(t.Context(), 0, d.ID, "disabled"); err != nil {
|
||||
if _, err := repo.UpdateAccountDisplay(t.Context(), 0, mainDisplay.ID, "disabled"); err != nil {
|
||||
t.Fatalf("UpdateAccountDisplay disabled err = %v", err)
|
||||
}
|
||||
if _, err := repo.UpdateAccountDisplay(t.Context(), 0, byNo["L10003"].ID, "disabled"); err != nil {
|
||||
t.Fatalf("UpdateAccountDisplay own disabled err = %v", err)
|
||||
}
|
||||
pubList2, err := repo.ListPublicSiteListings(t.Context(), site.SiteCode, 1, 20)
|
||||
if err != nil {
|
||||
t.Fatalf("ListPublicSiteListings after disabled err = %v", err)
|
||||
@@ -309,7 +349,7 @@ func TestSyncSiteAccountsAndPublicListings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOnboardSiteAutoSyncsActiveListings(t *testing.T) {
|
||||
func TestOnboardSiteDoesNotDumpCatalog(t *testing.T) {
|
||||
db := distributionTestDB(t)
|
||||
repo := NewRepository(db)
|
||||
|
||||
@@ -353,11 +393,8 @@ func TestOnboardSiteAutoSyncsActiveListings(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("ListAccountDisplays err = %v", err)
|
||||
}
|
||||
if len(displays) != 1 {
|
||||
t.Fatalf("expected 1 auto-synced account, got %d", len(displays))
|
||||
}
|
||||
if displays[0].Title != "王者荣耀国服账号" || displays[0].ListingNo != "L20001" {
|
||||
t.Fatalf("unexpected auto-synced display: %+v", displays[0])
|
||||
if len(displays) != 0 {
|
||||
t.Fatalf("onboard must not dump catalog, got %d displays", len(displays))
|
||||
}
|
||||
if onboardResp.Rule.Status != "draft" || onboardResp.Rule.DistributorReceiveRatio != 0 || onboardResp.Rule.PlatformSellRatio != 0 {
|
||||
t.Fatalf("onboard must not activate default 3.5/4 split, got %+v", onboardResp.Rule)
|
||||
|
||||
Reference in New Issue
Block a user