From c379942852a9b3e42d45c24af85c3108e0aa96a3 Mon Sep 17 00:00:00 2001 From: zhaoxing <2558691827@qq.com> Date: Sat, 21 Nov 2026 16:37:16 +0800 Subject: [PATCH] =?UTF-8?q?feat(listing):=20=E5=95=86=E5=93=81=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E5=B1=95=E7=A4=BA=E6=9D=A5=E6=BA=90=E5=95=86=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/internal/modules/listing/dto.go | 1 + backend/internal/modules/listing/presenter.go | 4 + backend/internal/modules/listing/query.go | 2 + .../modules/listing/source_merchant_test.go | 113 ++++++++++++++++++ .../admin/views/AdminListingsView.vue | 43 ++++--- .../src/features/listings/api/listings.ts | 1 + frontend/src/styles/admin.css | 11 ++ 7 files changed, 160 insertions(+), 15 deletions(-) create mode 100644 backend/internal/modules/listing/source_merchant_test.go diff --git a/backend/internal/modules/listing/dto.go b/backend/internal/modules/listing/dto.go index 4f026684..0e3d4feb 100644 --- a/backend/internal/modules/listing/dto.go +++ b/backend/internal/modules/listing/dto.go @@ -11,6 +11,7 @@ import ( type ListingDTO struct { ID uint64 `json:"id"` SourceTenantID uint64 `json:"source_tenant_id"` + SourceMerchantName string `json:"source_merchant_name,omitempty"` ListingNo string `json:"listing_no"` AccountID uint64 `json:"account_id"` OwnerID uint64 `json:"owner_id"` diff --git a/backend/internal/modules/listing/presenter.go b/backend/internal/modules/listing/presenter.go index 59a3bca6..b7e7570e 100644 --- a/backend/internal/modules/listing/presenter.go +++ b/backend/internal/modules/listing/presenter.go @@ -23,6 +23,7 @@ type listingRow struct { IsExternalUpload bool `gorm:"column:is_external_upload"` DistributionSiteCode string `gorm:"column:distribution_site_code"` DistributionSiteName string `gorm:"column:distribution_site_name"` + SourceMerchantName string `gorm:"column:source_merchant_name"` Description string GameName string ServerRegion string @@ -72,6 +73,7 @@ func applyPublicListingURLs(item *ListingDTO) { return } item.SourceChannel = "" + item.SourceMerchantName = "" item.IsExternalUpload = false rawScreenshotURLs := item.ScreenshotURLS item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus) @@ -138,6 +140,7 @@ func applySellerListingPrice(item *ListingDTO) { return } item.SourceChannel = "" + item.SourceMerchantName = "" item.IsExternalUpload = false if item.AssetSummary == nil { return @@ -198,6 +201,7 @@ func (row listingRow) toDTO() ListingDTO { DistributionSiteID: row.DistributionSiteID, DistributionSiteCode: row.DistributionSiteCode, DistributionSiteName: row.DistributionSiteName, + SourceMerchantName: row.SourceMerchantName, IsPremium: row.IsPremium, CompensationPlan: normalizedCompensationPlan(row.CompensationPlan), InsuranceFeeBps: row.InsuranceFeeBps, diff --git a/backend/internal/modules/listing/query.go b/backend/internal/modules/listing/query.go index fcb7c993..4d874ab4 100644 --- a/backend/internal/modules/listing/query.go +++ b/backend/internal/modules/listing/query.go @@ -245,6 +245,7 @@ func (r *Repository) baseQuery(ctx context.Context) *gorm.DB { CASE WHEN lu.id IS NULL THEN 0 ELSE 1 END AS is_external_upload, COALESCE(src_site.site_code, '') AS distribution_site_code, COALESCE(src_site.site_name, '') AS distribution_site_name, + COALESCE(NULLIF(src_site.site_name, ''), NULLIF(src_tenant.name, ''), '') AS source_merchant_name, CASE WHEN l.distribution_site_id IS NOT NULL AND src_site.id IS NOT NULL THEN CONCAT('分销站 - ', src_site.site_name, ' (', src_site.site_code, ')') WHEN lu.id IS NULL THEN ? @@ -254,6 +255,7 @@ func (r *Repository) baseQuery(ctx context.Context) *gorm.DB { Joins("JOIN game_accounts AS a ON a.id = l.account_id"). Joins("LEFT JOIN users AS u ON u.id = l.owner_id"). Joins("LEFT JOIN distribution_sites AS src_site ON src_site.id = l.distribution_site_id"). + Joins("LEFT JOIN tenants AS src_tenant ON src_tenant.id = l.source_tenant_id"). // 逐商品按 listing_id 索引定位最后一次导入,避免每次列表查询都对全量导入记录分组。 Joins(`LEFT JOIN listing_uploads AS lu ON lu.id = ( SELECT MAX(lu_latest.id) FROM listing_uploads AS lu_latest WHERE lu_latest.listing_id = l.id diff --git a/backend/internal/modules/listing/source_merchant_test.go b/backend/internal/modules/listing/source_merchant_test.go new file mode 100644 index 00000000..f760c066 --- /dev/null +++ b/backend/internal/modules/listing/source_merchant_test.go @@ -0,0 +1,113 @@ +package listing + +import ( + "testing" + + "hfb_sys/backend/internal/database" + "hfb_sys/backend/internal/model" +) + +func TestAdminListIncludesSourceMerchantName(t *testing.T) { + db := database.NewTestDB() + if err := database.MigrateListingLifecycleTestSchema(db); err != nil { + t.Fatalf("failed to migrate test db: %v", err) + } + + tenants := []model.Tenant{ + {Code: "source_merchant_dachui", Name: "大锤商行", Status: "active"}, + {Code: "source_merchant_jieyou", Name: "解忧商行", Status: "active"}, + } + if err := db.Create(&tenants).Error; err != nil { + t.Fatalf("failed to create tenants: %v", err) + } + site := model.DistributionSite{ + SiteCode: "source_merchant_tianyu", + SiteName: "天域商行", + Domain: "source-merchant-tianyu.example.com", + Status: "active", + DisplayAccountEnabled: true, + } + if err := db.Create(&site).Error; err != nil { + t.Fatalf("failed to create distribution site: %v", err) + } + users := []model.User{ + {TenantID: tenants[0].ID, Phone: "18800000901", RealnameStatus: "verified", Status: "active"}, + {TenantID: tenants[1].ID, Phone: "18800000902", RealnameStatus: "verified", Status: "active"}, + } + if err := db.Create(&users).Error; err != nil { + t.Fatalf("failed to create users: %v", err) + } + + createListing := func(sourceTenantID, ownerID uint64, siteID *uint64, listingNo string) model.RentalListing { + account := model.GameAccount{ + SourceTenantID: sourceTenantID, + OwnerID: ownerID, + GameName: "delta_force", + ServerRegion: "QQ", + LoginPlatform: "扫码", + Title: listingNo, + Status: "draft", + } + if err := db.Create(&account).Error; err != nil { + t.Fatalf("failed to create account %s: %v", listingNo, err) + } + listing := model.RentalListing{ + SourceTenantID: sourceTenantID, + ListingNo: listingNo, + AccountID: account.ID, + OwnerID: ownerID, + PriceCent: 10000, + Status: "draft", + ReviewStatus: "pending", + DistributionSiteID: siteID, + } + if err := db.Create(&listing).Error; err != nil { + t.Fatalf("failed to create listing %s: %v", listingNo, err) + } + return listing + } + + dachuiMain := createListing(tenants[0].ID, users[0].ID, nil, "SM-DACHUI") + jieyouMain := createListing(tenants[1].ID, users[1].ID, nil, "SM-JIEYOU") + tianyuOwned := createListing(tenants[0].ID, users[0].ID, &site.ID, "SM-TIANYU") + tianyuLegacy := createListing(0, users[0].ID, &site.ID, "SM-TIANYU-OLD") + + repo := NewRepository(db, nil) + result, err := repo.ListAdmin(t.Context(), AdminListQuery{Page: 1, PageSize: 20}) + if err != nil { + t.Fatalf("ListAdmin() error = %v", err) + } + if result.Total != 4 || len(result.Items) != 4 { + t.Fatalf("ListAdmin() total=%d items=%d, want 4", result.Total, len(result.Items)) + } + + got := make(map[uint64]string, len(result.Items)) + for _, item := range result.Items { + got[item.ID] = item.SourceMerchantName + } + want := map[uint64]string{ + dachuiMain.ID: "大锤商行", + jieyouMain.ID: "解忧商行", + tianyuOwned.ID: "天域商行", + tianyuLegacy.ID: "天域商行", + } + for listingID, merchantName := range want { + if got[listingID] != merchantName { + t.Fatalf("listing %d source merchant = %q, want %q", listingID, got[listingID], merchantName) + } + } +} + +func TestPublicAndSellerListingsHideSourceMerchantName(t *testing.T) { + publicItem := ListingDTO{SourceMerchantName: "大锤商行"} + applyPublicListingURLs(&publicItem) + if publicItem.SourceMerchantName != "" { + t.Fatalf("public listing leaked source merchant name: %q", publicItem.SourceMerchantName) + } + + sellerItem := ListingDTO{SourceMerchantName: "解忧商行"} + applySellerListingPrice(&sellerItem) + if sellerItem.SourceMerchantName != "" { + t.Fatalf("seller listing leaked source merchant name: %q", sellerItem.SourceMerchantName) + } +} diff --git a/frontend/src/features/admin/views/AdminListingsView.vue b/frontend/src/features/admin/views/AdminListingsView.vue index ecdffd3e..52050a72 100644 --- a/frontend/src/features/admin/views/AdminListingsView.vue +++ b/frontend/src/features/admin/views/AdminListingsView.vue @@ -60,21 +60,22 @@ const listingTableWidth = ref(1296) const activeFilterPopover = ref('') const publishOptions = ref(emptyListingPublishOptions) const listingColumnUnits = { - code: 68, - zone: 70, - region: 62, - login: 38, - core: 80, - level: 58, - equipment: 78, - skin: 135, - face: 58, - remark: 80, - purePrice: 72, - period: 50, - rentDeposit: 76, - ratio: 30, - detail: 45, + merchant: 62, + code: 62, + zone: 64, + region: 58, + login: 36, + core: 74, + level: 52, + equipment: 72, + skin: 128, + face: 52, + remark: 72, + purePrice: 68, + period: 46, + rentDeposit: 72, + ratio: 28, + detail: 44, } as const type ListingColumnKey = keyof typeof listingColumnUnits const listingColumnWidths = computed(() => allocateListingColumnWidths(listingTableWidth.value)) @@ -155,6 +156,7 @@ const skinFilterLabel = computed(() => { }) const screenshotColumns = [ + { label: '商行', width: 76, read: (row: Listing) => sourceMerchantText(row) }, { label: '商品编码', width: 95, read: (row: Listing) => formatListingCode(row) }, { label: '专区/赔付', @@ -625,6 +627,10 @@ function listingCoinM(row: Listing) { return formatHafCoinM(getCoinWan(row)) } +function sourceMerchantText(row: Listing) { + return row.source_merchant_name?.trim() || '-' +} + function assetText(row: Listing, key: string) { const value = row.asset_summary?.[key] if (typeof value === 'number') return formatQuantity(value) @@ -1055,6 +1061,13 @@ function formatQuantity(value: number) { stripe empty-text="暂无商品" > + + +