线下提号 优化价格拆分

This commit is contained in:
yml2213
2026-07-09 23:31:44 +08:00
parent 8a5c9ab0be
commit 0a5448b3f5
5 changed files with 189 additions and 43 deletions
+70 -27
View File
@@ -452,19 +452,22 @@ func (row availableListingRow) toDTO() AvailableListingDTO {
model.GameAccount{HafCoinAmount: row.HafCoinAmount, AssetSummary: row.AssetSummary},
)
return AvailableListingDTO{
ID: row.ID,
ListingNo: row.ListingNo,
AccountID: row.AccountID,
AccountTitle: row.AccountTitle,
ServerRegion: row.ServerRegion,
LoginPlatform: row.LoginPlatform,
OwnerID: row.OwnerID,
OwnerPhone: row.OwnerPhone,
ListingPriceCent: snapshot.ListingPriceCent,
OwnerPriceCent: snapshot.OwnerPriceCent,
WebsiteProfitCent: snapshot.WebsiteProfitCent,
SellerRatio: snapshot.SellerRatio,
BuyerRatio: snapshot.BuyerRatio,
ID: row.ID,
ListingNo: row.ListingNo,
AccountID: row.AccountID,
AccountTitle: row.AccountTitle,
ServerRegion: row.ServerRegion,
LoginPlatform: row.LoginPlatform,
OwnerID: row.OwnerID,
OwnerPhone: row.OwnerPhone,
ListingPriceCent: snapshot.ListingPriceCent,
OwnerPriceCent: snapshot.OwnerPriceCent,
OwnerPurePriceCent: snapshot.OwnerPurePriceCent,
OwnerExtraItemPriceCent: snapshot.OwnerExtraItemPriceCent,
OwnerTotalPriceCent: snapshot.OwnerTotalPriceCent,
WebsiteProfitCent: snapshot.WebsiteProfitCent,
SellerRatio: snapshot.SellerRatio,
BuyerRatio: snapshot.BuyerRatio,
}
}
@@ -506,24 +509,37 @@ func isEmptyPickupAccountSnapshot(raw datatypes.JSON) bool {
}
type pickupPriceSnapshot struct {
ListingPriceCent int64
OwnerPriceCent int64
WebsiteProfitCent int64
SellerRatio float64
BuyerRatio float64
ListingPriceCent int64
OwnerPriceCent int64
OwnerPurePriceCent int64
OwnerExtraItemPriceCent int64
OwnerTotalPriceCent int64
WebsiteProfitCent int64
SellerRatio float64
BuyerRatio float64
}
func buildPickupPriceSnapshot(listing model.RentalListing, account model.GameAccount) pickupPriceSnapshot {
summary := decodePickupAssetSummary(account.AssetSummary)
breakdown := pickupPriceBreakdown(summary)
listingPriceCent := maxPickupCent(listing.PriceCent, 0)
ownerPriceCent := yuanToPickupCent(readPickupNumber(breakdown["seller_total_price"]))
if ownerPriceCent <= 0 || (listingPriceCent > 0 && ownerPriceCent > listingPriceCent) {
ownerPriceCent = listingPriceCent
ownerPurePriceCent := yuanToPickupCent(readPickupNumber(breakdown["seller_coin_base_price"]))
ownerExtraItemPriceCent := yuanToPickupCent(readPickupNumber(breakdown["consumable_price"]))
ownerTotalPriceCent := yuanToPickupCent(readPickupNumber(breakdown["seller_total_price"]))
if ownerTotalPriceCent <= 0 && (ownerPurePriceCent > 0 || ownerExtraItemPriceCent > 0) {
ownerTotalPriceCent = ownerPurePriceCent + ownerExtraItemPriceCent
}
if ownerTotalPriceCent <= 0 || (listingPriceCent > 0 && ownerTotalPriceCent > listingPriceCent) {
ownerTotalPriceCent = listingPriceCent
}
ownerPurePriceCent, ownerExtraItemPriceCent = normalizePickupOwnerPriceSplit(
ownerTotalPriceCent,
ownerPurePriceCent,
ownerExtraItemPriceCent,
)
websiteProfitCent := yuanToPickupCent(readPickupNumber(breakdown["platform_markup_amount"]))
if websiteProfitCent <= 0 {
websiteProfitCent = listingPriceCent - ownerPriceCent
websiteProfitCent = listingPriceCent - ownerTotalPriceCent
}
if websiteProfitCent < 0 {
websiteProfitCent = 0
@@ -540,14 +556,41 @@ func buildPickupPriceSnapshot(listing model.RentalListing, account model.GameAcc
buyerRatio = ratioFromCoin(account.HafCoinAmount, readPickupNumber(breakdown["buyer_coin_base_price"]))
}
return pickupPriceSnapshot{
ListingPriceCent: listingPriceCent,
OwnerPriceCent: ownerPriceCent,
WebsiteProfitCent: websiteProfitCent,
SellerRatio: roundPickupRatio(sellerRatio),
BuyerRatio: roundPickupRatio(buyerRatio),
ListingPriceCent: listingPriceCent,
OwnerPriceCent: ownerTotalPriceCent,
OwnerPurePriceCent: ownerPurePriceCent,
OwnerExtraItemPriceCent: ownerExtraItemPriceCent,
OwnerTotalPriceCent: ownerTotalPriceCent,
WebsiteProfitCent: websiteProfitCent,
SellerRatio: roundPickupRatio(sellerRatio),
BuyerRatio: roundPickupRatio(buyerRatio),
}
}
func normalizePickupOwnerPriceSplit(totalCent, pureCent, extraCent int64) (int64, int64) {
if totalCent <= 0 {
return 0, 0
}
pureCent = maxPickupCent(pureCent, 0)
extraCent = maxPickupCent(extraCent, 0)
switch {
case pureCent == 0 && extraCent == 0:
pureCent = totalCent
case pureCent == 0:
pureCent = maxPickupCent(totalCent-extraCent, 0)
case extraCent == 0:
extraCent = maxPickupCent(totalCent-pureCent, 0)
case pureCent+extraCent != totalCent:
if pureCent > totalCent {
pureCent = totalCent
extraCent = 0
} else {
extraCent = totalCent - pureCent
}
}
return pureCent, extraCent
}
func decodePickupAssetSummary(raw datatypes.JSON) map[string]any {
if len(raw) == 0 {
return map[string]any{}