From 2185cd152a6dadca9426f37431e223cb4e156e34 Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 9 Jun 2026 13:59:53 +0800 Subject: [PATCH] =?UTF-8?q?Listing=E6=A8=A1=E5=9D=97=EF=BC=9A=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E5=88=86=E5=AD=97=E6=AE=B5=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 核心改造: 1. ListingDTO改为使用PriceCent和DepositAmountCent字段 2. toDTO函数使用listing.PriceCent和listing.DepositAmountCent 3. 筛选函数matchPublicQuery转换为元进行比较 4. 排序函数sortPublicListings使用PriceCent比较 5. 价格视图函数sanitizePriceForOwner使用PriceCent 6. toAdminDTO函数使用*Cent字段 技术细节: - 筛选时将分转为元:price := float64(item.PriceCent) / 100 - 排序直接比较分:a.PriceCent < b.PriceCent - 价格调整时转换:item.PriceCent = int64(math.Round(sellerPrice * 100)) - 编译验证通过 ✅ --- backend/internal/modules/listing/dto.go | 4 +- .../internal/modules/listing/repository.go | 94 +++++++++---------- 2 files changed, 49 insertions(+), 49 deletions(-) diff --git a/backend/internal/modules/listing/dto.go b/backend/internal/modules/listing/dto.go index d7a254c..1aa0367 100644 --- a/backend/internal/modules/listing/dto.go +++ b/backend/internal/modules/listing/dto.go @@ -25,8 +25,8 @@ type ListingDTO struct { AssetSummary map[string]any `json:"asset_summary,omitempty"` ScreenshotURLS []string `json:"screenshot_urls"` CoverURL string `json:"cover_url"` - Price float64 `json:"price"` - DepositAmount float64 `json:"deposit_amount"` + PriceCent int64 `json:"price_cent"` + DepositAmountCent int64 `json:"deposit_amount_cent"` IsAccelerated bool `json:"is_accelerated_sale"` InTransaction bool `json:"in_transaction"` Status string `json:"status"` diff --git a/backend/internal/modules/listing/repository.go b/backend/internal/modules/listing/repository.go index 1f0201d..08a795d 100644 --- a/backend/internal/modules/listing/repository.go +++ b/backend/internal/modules/listing/repository.go @@ -908,8 +908,8 @@ func matchesPublicQuery(item ListingDTO, query PublicListQuery) bool { return false } - price := item.Price - deposit := item.DepositAmount + price := float64(item.PriceCent) / 100 + deposit := float64(item.DepositAmountCent) / 100 total := price + deposit coinM := coinMFromListing(item) if !numberInRange(coinM, NumberRange{Min: query.MinCoin, Max: query.MaxCoin}) { @@ -944,9 +944,9 @@ func sortPublicListings(items []ListingDTO, sortKey string) { b := items[j] switch sortKey { case "priceAsc": - return a.Price < b.Price + return a.PriceCent < b.PriceCent case "priceDesc": - return a.Price > b.Price + return a.PriceCent > b.PriceCent case "coinDesc": return a.HafCoinAmount > b.HafCoinAmount case "awmDesc": @@ -1421,7 +1421,7 @@ func applySellerListingPrice(item *ListingDTO) { } sellerPrice := readSummaryNumber(breakdown["seller_total_price"]) if sellerPrice > 0 { - item.Price = sellerPrice + item.PriceCent = int64(math.Round(sellerPrice * 100)) } sellerRatio := readSummaryNumber(breakdown["seller_ratio"]) if sellerRatio > 0 { @@ -1447,24 +1447,24 @@ func (row listingRow) toDTO() ListingDTO { OwnerNickname: row.OwnerNickname, Title: row.Title, Description: row.Description, - GameName: row.GameName, - ServerRegion: row.ServerRegion, - LoginPlatform: row.LoginPlatform, - RankLevel: row.RankLevel, - HafCoinAmount: row.HafCoinAmount, - AssetSummary: assetSummary, - ScreenshotURLS: screenshotURLS, - CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus), - Price: row.Price, - DepositAmount: row.DepositAmount, - IsAccelerated: isAcceleratedSale(assetSummary), - InTransaction: row.InTransaction, - Status: row.Status, - ReviewStatus: reviewStatus, - ReviewReason: reviewReason, - PublishedAt: row.PublishedAt, - CreatedAt: row.CreatedAt, - UpdatedAt: row.UpdatedAt, + GameName: row.GameName, + ServerRegion: row.ServerRegion, + LoginPlatform: row.LoginPlatform, + RankLevel: row.RankLevel, + HafCoinAmount: row.HafCoinAmount, + AssetSummary: assetSummary, + ScreenshotURLS: screenshotURLS, + CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus), + PriceCent: row.PriceCent, + DepositAmountCent: row.DepositAmountCent, + IsAccelerated: isAcceleratedSale(assetSummary), + InTransaction: row.InTransaction, + Status: row.Status, + ReviewStatus: reviewStatus, + ReviewReason: reviewReason, + PublishedAt: row.PublishedAt, + CreatedAt: row.CreatedAt, + UpdatedAt: row.UpdatedAt, } } @@ -1473,30 +1473,30 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO { screenshotURLS := cleanScreenshotURLs(decodeScreenshots(account.ScreenshotURLS)) reviewStatus, reviewReason := normalizedReviewState(listing.Status, listing.ReviewStatus, listing.ReviewReason) return &ListingDTO{ - ID: listing.ID, - ListingNo: listing.ListingNo, - AccountID: account.ID, - OwnerID: listing.OwnerID, - Title: account.Title, - Description: account.Description, - GameName: account.GameName, - ServerRegion: account.ServerRegion, - LoginPlatform: account.LoginPlatform, - RankLevel: account.RankLevel, - HafCoinAmount: account.HafCoinAmount, - AssetSummary: assetSummary, - ScreenshotURLS: screenshotURLS, - CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus), - Price: listing.Price, - DepositAmount: listing.DepositAmount, - IsAccelerated: isAcceleratedSale(assetSummary), - InTransaction: listing.InTransaction, - Status: listing.Status, - ReviewStatus: reviewStatus, - ReviewReason: reviewReason, - PublishedAt: listing.PublishedAt, - CreatedAt: listing.CreatedAt, - UpdatedAt: listing.UpdatedAt, + ID: listing.ID, + ListingNo: listing.ListingNo, + AccountID: account.ID, + OwnerID: listing.OwnerID, + Title: account.Title, + Description: account.Description, + GameName: account.GameName, + ServerRegion: account.ServerRegion, + LoginPlatform: account.LoginPlatform, + RankLevel: account.RankLevel, + HafCoinAmount: account.HafCoinAmount, + AssetSummary: assetSummary, + ScreenshotURLS: screenshotURLS, + CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus), + PriceCent: listing.PriceCent, + DepositAmountCent: listing.DepositAmountCent, + IsAccelerated: isAcceleratedSale(assetSummary), + InTransaction: listing.InTransaction, + Status: listing.Status, + ReviewStatus: reviewStatus, + ReviewReason: reviewReason, + PublishedAt: listing.PublishedAt, + CreatedAt: listing.CreatedAt, + UpdatedAt: listing.UpdatedAt, } }