feat(listing): 商品列表展示来源商行
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
type ListingDTO struct {
|
type ListingDTO struct {
|
||||||
ID uint64 `json:"id"`
|
ID uint64 `json:"id"`
|
||||||
SourceTenantID uint64 `json:"source_tenant_id"`
|
SourceTenantID uint64 `json:"source_tenant_id"`
|
||||||
|
SourceMerchantName string `json:"source_merchant_name,omitempty"`
|
||||||
ListingNo string `json:"listing_no"`
|
ListingNo string `json:"listing_no"`
|
||||||
AccountID uint64 `json:"account_id"`
|
AccountID uint64 `json:"account_id"`
|
||||||
OwnerID uint64 `json:"owner_id"`
|
OwnerID uint64 `json:"owner_id"`
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ type listingRow struct {
|
|||||||
IsExternalUpload bool `gorm:"column:is_external_upload"`
|
IsExternalUpload bool `gorm:"column:is_external_upload"`
|
||||||
DistributionSiteCode string `gorm:"column:distribution_site_code"`
|
DistributionSiteCode string `gorm:"column:distribution_site_code"`
|
||||||
DistributionSiteName string `gorm:"column:distribution_site_name"`
|
DistributionSiteName string `gorm:"column:distribution_site_name"`
|
||||||
|
SourceMerchantName string `gorm:"column:source_merchant_name"`
|
||||||
Description string
|
Description string
|
||||||
GameName string
|
GameName string
|
||||||
ServerRegion string
|
ServerRegion string
|
||||||
@@ -72,6 +73,7 @@ func applyPublicListingURLs(item *ListingDTO) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.SourceChannel = ""
|
item.SourceChannel = ""
|
||||||
|
item.SourceMerchantName = ""
|
||||||
item.IsExternalUpload = false
|
item.IsExternalUpload = false
|
||||||
rawScreenshotURLs := item.ScreenshotURLS
|
rawScreenshotURLs := item.ScreenshotURLS
|
||||||
item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus)
|
item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus)
|
||||||
@@ -138,6 +140,7 @@ func applySellerListingPrice(item *ListingDTO) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
item.SourceChannel = ""
|
item.SourceChannel = ""
|
||||||
|
item.SourceMerchantName = ""
|
||||||
item.IsExternalUpload = false
|
item.IsExternalUpload = false
|
||||||
if item.AssetSummary == nil {
|
if item.AssetSummary == nil {
|
||||||
return
|
return
|
||||||
@@ -198,6 +201,7 @@ func (row listingRow) toDTO() ListingDTO {
|
|||||||
DistributionSiteID: row.DistributionSiteID,
|
DistributionSiteID: row.DistributionSiteID,
|
||||||
DistributionSiteCode: row.DistributionSiteCode,
|
DistributionSiteCode: row.DistributionSiteCode,
|
||||||
DistributionSiteName: row.DistributionSiteName,
|
DistributionSiteName: row.DistributionSiteName,
|
||||||
|
SourceMerchantName: row.SourceMerchantName,
|
||||||
IsPremium: row.IsPremium,
|
IsPremium: row.IsPremium,
|
||||||
CompensationPlan: normalizedCompensationPlan(row.CompensationPlan),
|
CompensationPlan: normalizedCompensationPlan(row.CompensationPlan),
|
||||||
InsuranceFeeBps: row.InsuranceFeeBps,
|
InsuranceFeeBps: row.InsuranceFeeBps,
|
||||||
|
|||||||
@@ -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,
|
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_code, '') AS distribution_site_code,
|
||||||
COALESCE(src_site.site_name, '') AS distribution_site_name,
|
COALESCE(src_site.site_name, '') AS distribution_site_name,
|
||||||
|
COALESCE(NULLIF(src_site.site_name, ''), NULLIF(src_tenant.name, ''), '') AS source_merchant_name,
|
||||||
CASE
|
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 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 ?
|
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("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 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 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 索引定位最后一次导入,避免每次列表查询都对全量导入记录分组。
|
// 逐商品按 listing_id 索引定位最后一次导入,避免每次列表查询都对全量导入记录分组。
|
||||||
Joins(`LEFT JOIN listing_uploads AS lu ON lu.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
|
SELECT MAX(lu_latest.id) FROM listing_uploads AS lu_latest WHERE lu_latest.listing_id = l.id
|
||||||
|
|||||||
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -60,21 +60,22 @@ const listingTableWidth = ref(1296)
|
|||||||
const activeFilterPopover = ref<FilterPopover | ''>('')
|
const activeFilterPopover = ref<FilterPopover | ''>('')
|
||||||
const publishOptions = ref(emptyListingPublishOptions)
|
const publishOptions = ref(emptyListingPublishOptions)
|
||||||
const listingColumnUnits = {
|
const listingColumnUnits = {
|
||||||
code: 68,
|
merchant: 62,
|
||||||
zone: 70,
|
code: 62,
|
||||||
region: 62,
|
zone: 64,
|
||||||
login: 38,
|
region: 58,
|
||||||
core: 80,
|
login: 36,
|
||||||
level: 58,
|
core: 74,
|
||||||
equipment: 78,
|
level: 52,
|
||||||
skin: 135,
|
equipment: 72,
|
||||||
face: 58,
|
skin: 128,
|
||||||
remark: 80,
|
face: 52,
|
||||||
purePrice: 72,
|
remark: 72,
|
||||||
period: 50,
|
purePrice: 68,
|
||||||
rentDeposit: 76,
|
period: 46,
|
||||||
ratio: 30,
|
rentDeposit: 72,
|
||||||
detail: 45,
|
ratio: 28,
|
||||||
|
detail: 44,
|
||||||
} as const
|
} as const
|
||||||
type ListingColumnKey = keyof typeof listingColumnUnits
|
type ListingColumnKey = keyof typeof listingColumnUnits
|
||||||
const listingColumnWidths = computed(() => allocateListingColumnWidths(listingTableWidth.value))
|
const listingColumnWidths = computed(() => allocateListingColumnWidths(listingTableWidth.value))
|
||||||
@@ -155,6 +156,7 @@ const skinFilterLabel = computed(() => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const screenshotColumns = [
|
const screenshotColumns = [
|
||||||
|
{ label: '商行', width: 76, read: (row: Listing) => sourceMerchantText(row) },
|
||||||
{ label: '商品编码', width: 95, read: (row: Listing) => formatListingCode(row) },
|
{ label: '商品编码', width: 95, read: (row: Listing) => formatListingCode(row) },
|
||||||
{
|
{
|
||||||
label: '专区/赔付',
|
label: '专区/赔付',
|
||||||
@@ -625,6 +627,10 @@ function listingCoinM(row: Listing) {
|
|||||||
return formatHafCoinM(getCoinWan(row))
|
return formatHafCoinM(getCoinWan(row))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sourceMerchantText(row: Listing) {
|
||||||
|
return row.source_merchant_name?.trim() || '-'
|
||||||
|
}
|
||||||
|
|
||||||
function assetText(row: Listing, key: string) {
|
function assetText(row: Listing, key: string) {
|
||||||
const value = row.asset_summary?.[key]
|
const value = row.asset_summary?.[key]
|
||||||
if (typeof value === 'number') return formatQuantity(value)
|
if (typeof value === 'number') return formatQuantity(value)
|
||||||
@@ -1055,6 +1061,13 @@ function formatQuantity(value: number) {
|
|||||||
stripe
|
stripe
|
||||||
empty-text="暂无商品"
|
empty-text="暂无商品"
|
||||||
>
|
>
|
||||||
|
<el-table-column label="商行" :width="listingColumnWidths.merchant">
|
||||||
|
<template #default="{ row }">
|
||||||
|
<span class="listing-merchant" :title="sourceMerchantText(row)">
|
||||||
|
{{ sourceMerchantText(row) }}
|
||||||
|
</span>
|
||||||
|
</template>
|
||||||
|
</el-table-column>
|
||||||
<el-table-column label="商品编码" :width="listingColumnWidths.code">
|
<el-table-column label="商品编码" :width="listingColumnWidths.code">
|
||||||
<template #default="{ row }">
|
<template #default="{ row }">
|
||||||
<strong class="listing-code">{{ formatListingCode(row) }}</strong>
|
<strong class="listing-code">{{ formatListingCode(row) }}</strong>
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ export interface Listing {
|
|||||||
owner_nickname?: string
|
owner_nickname?: string
|
||||||
owner_is_quality_owner?: boolean
|
owner_is_quality_owner?: boolean
|
||||||
source_channel?: string
|
source_channel?: string
|
||||||
|
source_merchant_name?: string
|
||||||
is_external_upload?: boolean
|
is_external_upload?: boolean
|
||||||
title: string
|
title: string
|
||||||
description: string
|
description: string
|
||||||
|
|||||||
@@ -1177,6 +1177,17 @@ h1 {
|
|||||||
word-break: keep-all;
|
word-break: keep-all;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.admin-listings-table .listing-merchant {
|
||||||
|
display: block;
|
||||||
|
max-width: 100%;
|
||||||
|
overflow: hidden;
|
||||||
|
font-size: 11px;
|
||||||
|
line-height: 1.2;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
word-break: keep-all;
|
||||||
|
}
|
||||||
|
|
||||||
.admin-listings-table .face-owner-no {
|
.admin-listings-table .face-owner-no {
|
||||||
color: #dc2626;
|
color: #dc2626;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
|
|||||||
Reference in New Issue
Block a user