修复预计 截止时间
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/pkg/money"
|
||||
@@ -35,6 +36,38 @@ func orderDurationHours(order model.RentalOrder) int {
|
||||
return internalOrderHours
|
||||
}
|
||||
|
||||
func orderEstimatedEndAt(order model.RentalOrder) *time.Time {
|
||||
if order.RentedAt == nil {
|
||||
return nil
|
||||
}
|
||||
durationHours := orderDurationHours(order)
|
||||
if durationHours <= 0 {
|
||||
return nil
|
||||
}
|
||||
endAt := order.RentedAt.Add(time.Duration(durationHours) * time.Hour)
|
||||
return &endAt
|
||||
}
|
||||
|
||||
func estimateOrderDurationHours(snapshot datatypes.JSON) int {
|
||||
hafCoinM := readOrderSnapshotCoinM(snapshot)
|
||||
if hafCoinM <= 0 {
|
||||
return internalOrderHours
|
||||
}
|
||||
dailyLossM := readOrderSnapshotAssetNumber(snapshot, "daily_loss_m")
|
||||
if dailyLossM <= 0 {
|
||||
return internalOrderHours
|
||||
}
|
||||
days := hafCoinM / dailyLossM
|
||||
if days <= 0 {
|
||||
return internalOrderHours
|
||||
}
|
||||
hours := int(math.Round(days * 24))
|
||||
if hours <= 0 {
|
||||
return internalOrderHours
|
||||
}
|
||||
return hours
|
||||
}
|
||||
|
||||
func buildOrderPricing(listing model.RentalListing, account model.GameAccount) orderPricing {
|
||||
rentAmountCent := listing.PriceCent
|
||||
ownerRentAmountCent := int64(math.Round(readSnapshotPrice(account.AssetSummary, "seller_total_price") * 100))
|
||||
@@ -203,6 +236,24 @@ func readOrderSnapshotCoinM(raw datatypes.JSON) float64 {
|
||||
return roundQuantity(readJSONNumber(snapshot["haf_coin_amount"]) / 1000000)
|
||||
}
|
||||
|
||||
func readOrderSnapshotAssetNumber(raw datatypes.JSON, key string) float64 {
|
||||
if len(raw) == 0 {
|
||||
return 0
|
||||
}
|
||||
var snapshot map[string]any
|
||||
if err := json.Unmarshal(raw, &snapshot); err != nil {
|
||||
return 0
|
||||
}
|
||||
assetSummary, ok := snapshot["asset_summary"].(map[string]any)
|
||||
if !ok {
|
||||
return readJSONNumber(snapshot[key])
|
||||
}
|
||||
if value, ok := assetSummary[key]; ok {
|
||||
return readJSONNumber(value)
|
||||
}
|
||||
return readJSONNumber(snapshot[key])
|
||||
}
|
||||
|
||||
// roundMoney 使用统一的角精度(0.1元)
|
||||
func roundMoney(value float64) float64 {
|
||||
return money.Round(value)
|
||||
|
||||
Reference in New Issue
Block a user