feat(distribution): 支持一键同步主站商品池并在货架区分货源归属

This commit is contained in:
yml2213
2026-09-09 13:44:50 +08:00
parent cf4bea9b6d
commit 9452cf608e
5 changed files with 59 additions and 28 deletions
@@ -480,6 +480,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
DepositAmountCent int64 `gorm:"column:deposit_amount_cent"`
ListingStatus string `gorm:"column:listing_status"`
InTransaction bool `gorm:"column:in_transaction"`
ListingSiteID *uint64 `gorm:"column:listing_site_id"`
SourceChannel string `gorm:"column:source_channel"`
}
var rows []accountDisplayRow
@@ -494,6 +496,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
COALESCE(dsa.markup_amount_cent, 0) AS markup_amount_cent,
COALESCE(dsa.shelf_ratio_delta, 0) AS shelf_ratio_delta,
COALESCE(l.listing_no, '') AS listing_no,
l.distribution_site_id AS listing_site_id,
COALESCE(l.source_channel, '') AS source_channel,
COALESCE(ga.title, '') AS title,
COALESCE(ga.game_name, '') AS game_name,
COALESCE(ga.server_region, '') AS server_region,
@@ -540,6 +544,8 @@ func (r *Repository) ListAccountDisplays(ctx context.Context, siteID uint64, sta
DepositAmountCent: row.DepositAmountCent,
ListingStatus: row.ListingStatus,
InTransaction: row.InTransaction,
ListingSiteID: row.ListingSiteID,
SourceChannel: row.SourceChannel,
})
}
return items, nil
@@ -627,13 +633,6 @@ func (r *Repository) SyncSiteAccounts(ctx context.Context, adminID, siteID uint6
}
var candidates []model.RentalListing
if err := r.db.WithContext(ctx).
Where("distribution_site_id = ? AND status = ? AND review_status = ?", siteID, "published", "approved").
Order("id ASC").
Find(&candidates).Error; err != nil {
return nil, err
}
if len(selectedIDs) > 0 {
var selected []model.RentalListing
if err := r.db.WithContext(ctx).Where("id IN ?", selectedIDs).Find(&selected).Error; err != nil {
@@ -642,16 +641,14 @@ func (r *Repository) SyncSiteAccounts(ctx context.Context, adminID, siteID uint6
if len(selected) != len(selectedIDs) {
return nil, ErrSyncListingNotFound
}
seenListing := make(map[uint64]bool, len(candidates)+len(selected))
for _, l := range candidates {
seenListing[l.ID] = true
}
for _, l := range selected {
if seenListing[l.ID] {
continue
}
seenListing[l.ID] = true
candidates = append(candidates, l)
candidates = selected
} else {
// 未显式指定 listingIDs 时,默认将主站自营及全网审核通过的在售商品全部同步至本分站货架
if err := r.db.WithContext(ctx).
Where("status = ? AND review_status = ?", "published", "approved").
Order("id ASC").
Find(&candidates).Error; err != nil {
return nil, err
}
}