Listing模块:完成分字段重构

核心改造:
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))
- 编译验证通过 
This commit is contained in:
yml
2026-06-09 13:59:53 +08:00
parent 4f3be229bd
commit 2185cd152a
2 changed files with 49 additions and 49 deletions
+2 -2
View File
@@ -25,8 +25,8 @@ type ListingDTO struct {
AssetSummary map[string]any `json:"asset_summary,omitempty"` AssetSummary map[string]any `json:"asset_summary,omitempty"`
ScreenshotURLS []string `json:"screenshot_urls"` ScreenshotURLS []string `json:"screenshot_urls"`
CoverURL string `json:"cover_url"` CoverURL string `json:"cover_url"`
Price float64 `json:"price"` PriceCent int64 `json:"price_cent"`
DepositAmount float64 `json:"deposit_amount"` DepositAmountCent int64 `json:"deposit_amount_cent"`
IsAccelerated bool `json:"is_accelerated_sale"` IsAccelerated bool `json:"is_accelerated_sale"`
InTransaction bool `json:"in_transaction"` InTransaction bool `json:"in_transaction"`
Status string `json:"status"` Status string `json:"status"`
+47 -47
View File
@@ -908,8 +908,8 @@ func matchesPublicQuery(item ListingDTO, query PublicListQuery) bool {
return false return false
} }
price := item.Price price := float64(item.PriceCent) / 100
deposit := item.DepositAmount deposit := float64(item.DepositAmountCent) / 100
total := price + deposit total := price + deposit
coinM := coinMFromListing(item) coinM := coinMFromListing(item)
if !numberInRange(coinM, NumberRange{Min: query.MinCoin, Max: query.MaxCoin}) { if !numberInRange(coinM, NumberRange{Min: query.MinCoin, Max: query.MaxCoin}) {
@@ -944,9 +944,9 @@ func sortPublicListings(items []ListingDTO, sortKey string) {
b := items[j] b := items[j]
switch sortKey { switch sortKey {
case "priceAsc": case "priceAsc":
return a.Price < b.Price return a.PriceCent < b.PriceCent
case "priceDesc": case "priceDesc":
return a.Price > b.Price return a.PriceCent > b.PriceCent
case "coinDesc": case "coinDesc":
return a.HafCoinAmount > b.HafCoinAmount return a.HafCoinAmount > b.HafCoinAmount
case "awmDesc": case "awmDesc":
@@ -1421,7 +1421,7 @@ func applySellerListingPrice(item *ListingDTO) {
} }
sellerPrice := readSummaryNumber(breakdown["seller_total_price"]) sellerPrice := readSummaryNumber(breakdown["seller_total_price"])
if sellerPrice > 0 { if sellerPrice > 0 {
item.Price = sellerPrice item.PriceCent = int64(math.Round(sellerPrice * 100))
} }
sellerRatio := readSummaryNumber(breakdown["seller_ratio"]) sellerRatio := readSummaryNumber(breakdown["seller_ratio"])
if sellerRatio > 0 { if sellerRatio > 0 {
@@ -1447,24 +1447,24 @@ func (row listingRow) toDTO() ListingDTO {
OwnerNickname: row.OwnerNickname, OwnerNickname: row.OwnerNickname,
Title: row.Title, Title: row.Title,
Description: row.Description, Description: row.Description,
GameName: row.GameName, GameName: row.GameName,
ServerRegion: row.ServerRegion, ServerRegion: row.ServerRegion,
LoginPlatform: row.LoginPlatform, LoginPlatform: row.LoginPlatform,
RankLevel: row.RankLevel, RankLevel: row.RankLevel,
HafCoinAmount: row.HafCoinAmount, HafCoinAmount: row.HafCoinAmount,
AssetSummary: assetSummary, AssetSummary: assetSummary,
ScreenshotURLS: screenshotURLS, ScreenshotURLS: screenshotURLS,
CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus), CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus),
Price: row.Price, PriceCent: row.PriceCent,
DepositAmount: row.DepositAmount, DepositAmountCent: row.DepositAmountCent,
IsAccelerated: isAcceleratedSale(assetSummary), IsAccelerated: isAcceleratedSale(assetSummary),
InTransaction: row.InTransaction, InTransaction: row.InTransaction,
Status: row.Status, Status: row.Status,
ReviewStatus: reviewStatus, ReviewStatus: reviewStatus,
ReviewReason: reviewReason, ReviewReason: reviewReason,
PublishedAt: row.PublishedAt, PublishedAt: row.PublishedAt,
CreatedAt: row.CreatedAt, CreatedAt: row.CreatedAt,
UpdatedAt: row.UpdatedAt, UpdatedAt: row.UpdatedAt,
} }
} }
@@ -1473,30 +1473,30 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
screenshotURLS := cleanScreenshotURLs(decodeScreenshots(account.ScreenshotURLS)) screenshotURLS := cleanScreenshotURLs(decodeScreenshots(account.ScreenshotURLS))
reviewStatus, reviewReason := normalizedReviewState(listing.Status, listing.ReviewStatus, listing.ReviewReason) reviewStatus, reviewReason := normalizedReviewState(listing.Status, listing.ReviewStatus, listing.ReviewReason)
return &ListingDTO{ return &ListingDTO{
ID: listing.ID, ID: listing.ID,
ListingNo: listing.ListingNo, ListingNo: listing.ListingNo,
AccountID: account.ID, AccountID: account.ID,
OwnerID: listing.OwnerID, OwnerID: listing.OwnerID,
Title: account.Title, Title: account.Title,
Description: account.Description, Description: account.Description,
GameName: account.GameName, GameName: account.GameName,
ServerRegion: account.ServerRegion, ServerRegion: account.ServerRegion,
LoginPlatform: account.LoginPlatform, LoginPlatform: account.LoginPlatform,
RankLevel: account.RankLevel, RankLevel: account.RankLevel,
HafCoinAmount: account.HafCoinAmount, HafCoinAmount: account.HafCoinAmount,
AssetSummary: assetSummary, AssetSummary: assetSummary,
ScreenshotURLS: screenshotURLS, ScreenshotURLS: screenshotURLS,
CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus), CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus),
Price: listing.Price, PriceCent: listing.PriceCent,
DepositAmount: listing.DepositAmount, DepositAmountCent: listing.DepositAmountCent,
IsAccelerated: isAcceleratedSale(assetSummary), IsAccelerated: isAcceleratedSale(assetSummary),
InTransaction: listing.InTransaction, InTransaction: listing.InTransaction,
Status: listing.Status, Status: listing.Status,
ReviewStatus: reviewStatus, ReviewStatus: reviewStatus,
ReviewReason: reviewReason, ReviewReason: reviewReason,
PublishedAt: listing.PublishedAt, PublishedAt: listing.PublishedAt,
CreatedAt: listing.CreatedAt, CreatedAt: listing.CreatedAt,
UpdatedAt: listing.UpdatedAt, UpdatedAt: listing.UpdatedAt,
} }
} }