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:
@@ -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"`
|
||||
|
||||
@@ -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 {
|
||||
@@ -1455,8 +1455,8 @@ func (row listingRow) toDTO() ListingDTO {
|
||||
AssetSummary: assetSummary,
|
||||
ScreenshotURLS: screenshotURLS,
|
||||
CoverURL: publicCoverURL(row.ID, screenshotURLS, row.Status, row.ReviewStatus),
|
||||
Price: row.Price,
|
||||
DepositAmount: row.DepositAmount,
|
||||
PriceCent: row.PriceCent,
|
||||
DepositAmountCent: row.DepositAmountCent,
|
||||
IsAccelerated: isAcceleratedSale(assetSummary),
|
||||
InTransaction: row.InTransaction,
|
||||
Status: row.Status,
|
||||
@@ -1487,8 +1487,8 @@ func toDTO(account model.GameAccount, listing model.RentalListing) *ListingDTO {
|
||||
AssetSummary: assetSummary,
|
||||
ScreenshotURLS: screenshotURLS,
|
||||
CoverURL: publicCoverURL(listing.ID, screenshotURLS, listing.Status, listing.ReviewStatus),
|
||||
Price: listing.Price,
|
||||
DepositAmount: listing.DepositAmount,
|
||||
PriceCent: listing.PriceCent,
|
||||
DepositAmountCent: listing.DepositAmountCent,
|
||||
IsAccelerated: isAcceleratedSale(assetSummary),
|
||||
InTransaction: listing.InTransaction,
|
||||
Status: listing.Status,
|
||||
|
||||
Reference in New Issue
Block a user