修复卖家商品价格展示

This commit is contained in:
yml
2026-05-25 15:12:40 +08:00
parent 7e7e6dc166
commit e270ce8bfc
5 changed files with 78 additions and 23 deletions
+28 -2
View File
@@ -378,7 +378,7 @@ func (r *Repository) ListMine(ownerID uint64) ([]ListingDTO, error) {
if err != nil {
return nil, err
}
return rowsToDTO(rows), nil
return sellerListings(rowsToDTO(rows)), nil
}
func (r *Repository) FindPublic(id uint64) (*ListingDTO, error) {
@@ -412,7 +412,12 @@ func (r *Repository) FindPublicScreenshotKey(id uint64, index int) (string, erro
}
func (r *Repository) FindMine(ownerID uint64, id uint64) (*ListingDTO, error) {
return r.findDTO("l.id = ? AND l.owner_id = ?", id, ownerID)
dto, err := r.findDTO("l.id = ? AND l.owner_id = ?", id, ownerID)
if err != nil {
return nil, err
}
applySellerListingPrice(dto)
return dto, nil
}
func (r *Repository) findOwnedForUpdate(tx *gorm.DB, ownerID uint64, listingID uint64) (*model.RentalListing, *model.GameAccount, error) {
@@ -493,6 +498,13 @@ func publicListings(items []ListingDTO) []ListingDTO {
return items
}
func sellerListings(items []ListingDTO) []ListingDTO {
for index := range items {
applySellerListingPrice(&items[index])
}
return items
}
func applyPublicListingURLs(item *ListingDTO) {
item.ScreenshotURLS = publicScreenshotURLs(item.ID, item.ScreenshotURLS, item.Status, item.ReviewStatus)
if item.AssetSummary != nil {
@@ -500,6 +512,20 @@ func applyPublicListingURLs(item *ListingDTO) {
}
}
func applySellerListingPrice(item *ListingDTO) {
if item == nil || item.AssetSummary == nil {
return
}
breakdown, ok := item.AssetSummary["price_breakdown"].(map[string]any)
if !ok {
return
}
sellerPrice := readSummaryNumber(breakdown["seller_total_price"])
if sellerPrice > 0 {
item.Price = sellerPrice
}
}
func (row listingRow) toDTO() ListingDTO {
assetSummary := decodeAssetSummary(row.AssetSummary)
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(row.ScreenshotURLS))