fix(listing): 分销站商品审核按所属租户可见
分销站商品按站点归属租户参与审核;商品管理、审核详情及首页待审数量统一租户范围。
This commit is contained in:
@@ -82,7 +82,8 @@ func (r *Repository) Summary(ctx context.Context) (*DashboardDTO, error) {
|
||||
Scan(&metrics.TodayLedgerAmountCent).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := listingQuery.Session(&gorm.Session{}).Where("review_status = ?", "pending").Count(&pending.ListingReviews).Error; err != nil {
|
||||
reviewListingQuery := tenancy.ApplyListingTenantScope(ctx, db.Model(&model.RentalListing{}), "")
|
||||
if err := reviewListingQuery.Where("review_status = ? AND status <> ?", "pending", "offline").Count(&pending.ListingReviews).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
disputeQuery := db.Table("disputes AS d")
|
||||
|
||||
@@ -127,3 +127,83 @@ func TestSummaryScopesBuyerAndSourceMetricsByTenant(t *testing.T) {
|
||||
t.Fatalf("source tenant stats = %+v", summary.Tenant)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryPendingReviewsIncludeTenantDistributionSites(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
tenants := []model.Tenant{
|
||||
{ID: 101, Code: "dashboard_scope_a", Name: "A站", Status: "active"},
|
||||
{ID: 202, Code: "dashboard_scope_b", Name: "B站", Status: "active"},
|
||||
}
|
||||
if err := db.Create(&tenants).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
sites := []model.DistributionSite{
|
||||
{SiteCode: "dashboard_scope_site_a", SiteName: "A分销站", Domain: "dash-scope-a.example.com", Status: "active", DisplayAccountEnabled: true},
|
||||
{SiteCode: "dashboard_scope_site_b", SiteName: "B分销站", Domain: "dash-scope-b.example.com", Status: "active", DisplayAccountEnabled: true},
|
||||
}
|
||||
if err := db.Create(&sites).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := db.Create(&[]model.ChatSiteTenantLink{
|
||||
{SiteID: sites[0].ID, TenantID: 101, Enabled: true},
|
||||
{SiteID: sites[1].ID, TenantID: 202, Enabled: true},
|
||||
}).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
users := []model.User{
|
||||
{TenantID: 101, Phone: "13200000301", Status: "active"},
|
||||
{TenantID: 202, Phone: "13200000302", Status: "active"},
|
||||
{TenantID: 0, DistributionSiteID: sites[0].ID, Phone: "13200000303", Status: "active"},
|
||||
{TenantID: 0, DistributionSiteID: sites[1].ID, Phone: "13200000304", Status: "active"},
|
||||
}
|
||||
if err := db.Create(&users).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
createAccount := func(tenantID, ownerID uint64, title string) model.GameAccount {
|
||||
account := model.GameAccount{
|
||||
SourceTenantID: tenantID,
|
||||
OwnerID: ownerID,
|
||||
GameName: "delta_force",
|
||||
ServerRegion: "国服",
|
||||
LoginPlatform: "steam",
|
||||
Title: title,
|
||||
Status: "draft",
|
||||
}
|
||||
if err := db.Create(&account).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return account
|
||||
}
|
||||
createPending := func(sourceTenantID, ownerID uint64, siteID *uint64, suffix, status string) model.RentalListing {
|
||||
account := createAccount(sourceTenantID, ownerID, suffix)
|
||||
listing := model.RentalListing{
|
||||
SourceTenantID: sourceTenantID,
|
||||
ListingNo: "DASH-" + suffix,
|
||||
AccountID: account.ID,
|
||||
OwnerID: ownerID,
|
||||
PriceCent: 1000,
|
||||
Status: status,
|
||||
ReviewStatus: "pending",
|
||||
DistributionSiteID: siteID,
|
||||
}
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
return listing
|
||||
}
|
||||
|
||||
createPending(101, users[0].ID, nil, "MAIN-A", "draft")
|
||||
createPending(0, users[2].ID, &sites[0].ID, "SITE-A", "draft")
|
||||
createPending(202, users[1].ID, nil, "MAIN-B", "draft")
|
||||
createPending(0, users[3].ID, &sites[1].ID, "SITE-B", "draft")
|
||||
createPending(101, users[0].ID, nil, "OFFLINE-A", "offline")
|
||||
|
||||
summary, err := NewRepository(db).Summary(dashboardTenantContext(101))
|
||||
if err != nil {
|
||||
t.Fatalf("tenant summary: %v", err)
|
||||
}
|
||||
if summary.Pending.ListingReviews != 2 {
|
||||
t.Fatalf("pending listing reviews = %d, want 2 (main A + site A)", summary.Pending.ListingReviews)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user