金额使用整数, 不再扣押金, 价格每个人看到自己的-1
This commit is contained in:
@@ -61,11 +61,12 @@ func (r *Repository) Create(ownerID uint64, req CreateRequest, reviewRequired bo
|
||||
return err
|
||||
}
|
||||
price := normalizedListingPrice(req)
|
||||
depositAmount := roundMoney(req.DepositAmount)
|
||||
listing := model.RentalListing{
|
||||
AccountID: account.ID,
|
||||
OwnerID: ownerID,
|
||||
Price: price,
|
||||
DepositAmount: req.DepositAmount,
|
||||
DepositAmount: depositAmount,
|
||||
Status: listingStatus,
|
||||
ReviewStatus: reviewStatus,
|
||||
PublishedAt: publishedAt,
|
||||
@@ -109,7 +110,7 @@ func (r *Repository) Update(ownerID uint64, listingID uint64, req UpdateRequest,
|
||||
|
||||
price := normalizedListingPrice(req)
|
||||
listing.Price = price
|
||||
listing.DepositAmount = req.DepositAmount
|
||||
listing.DepositAmount = roundMoney(req.DepositAmount)
|
||||
listingStatus, reviewStatus, publishedAt := initialPublishState(reviewRequired)
|
||||
listing.Status = listingStatus
|
||||
listing.ReviewStatus = reviewStatus
|
||||
@@ -488,7 +489,15 @@ func rowsToDTO(rows []listingRow) []ListingDTO {
|
||||
}
|
||||
|
||||
func normalizedListingPrice(req CreateRequest) float64 {
|
||||
return req.Price
|
||||
if req.AssetSummary != nil {
|
||||
if breakdown, ok := req.AssetSummary["price_breakdown"].(map[string]any); ok {
|
||||
buyerPrice := readSummaryNumber(breakdown["buyer_total_price"])
|
||||
if buyerPrice > 0 {
|
||||
return roundMoney(buyerPrice)
|
||||
}
|
||||
}
|
||||
}
|
||||
return roundMoney(req.Price)
|
||||
}
|
||||
|
||||
func publicListings(items []ListingDTO) []ListingDTO {
|
||||
@@ -524,6 +533,15 @@ func applySellerListingPrice(item *ListingDTO) {
|
||||
if sellerPrice > 0 {
|
||||
item.Price = sellerPrice
|
||||
}
|
||||
sellerRatio := readSummaryNumber(breakdown["seller_ratio"])
|
||||
if sellerRatio > 0 {
|
||||
item.AssetSummary["publish_ratio"] = sellerRatio
|
||||
}
|
||||
delete(breakdown, "buyer_coin_base_price")
|
||||
delete(breakdown, "buyer_total_price")
|
||||
delete(breakdown, "buyer_ratio")
|
||||
delete(breakdown, "platform_markup_amount")
|
||||
delete(breakdown, "platform_rule_type")
|
||||
}
|
||||
|
||||
func (row listingRow) toDTO() ListingDTO {
|
||||
|
||||
@@ -313,7 +313,7 @@ func readUnitPrice(priceText string) float64 {
|
||||
}
|
||||
|
||||
func roundMoney(value float64) float64 {
|
||||
return math.Round(value*100) / 100
|
||||
return math.Round(value)
|
||||
}
|
||||
|
||||
func readFireLevel(summary map[string]any) (int, bool) {
|
||||
|
||||
@@ -11,8 +11,8 @@ func TestConsumableValueOnlyCountsChargedResources(t *testing.T) {
|
||||
},
|
||||
})
|
||||
|
||||
if value != 1.5 {
|
||||
t.Fatalf("expected 1.5, got %.2f", value)
|
||||
if value != 2 {
|
||||
t.Fatalf("expected 2, got %.2f", value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ func TestValidateRequestRequiresDepositAboveConsumables(t *testing.T) {
|
||||
Title: "测试账号",
|
||||
ServerRegion: "烽火地带",
|
||||
Price: 100,
|
||||
DepositAmount: 1.5,
|
||||
DepositAmount: 2,
|
||||
HafCoinAmount: 1000000,
|
||||
ScreenshotURLS: []string{"https://example.com/a.png"},
|
||||
AssetSummary: map[string]any{
|
||||
@@ -35,7 +35,7 @@ func TestValidateRequestRequiresDepositAboveConsumables(t *testing.T) {
|
||||
t.Fatalf("expected ErrDepositTooLow, got %v", err)
|
||||
}
|
||||
|
||||
req.DepositAmount = 2.01
|
||||
req.DepositAmount = 3
|
||||
if err := validateRequest(req, publishRules{}); err != nil {
|
||||
t.Fatalf("expected valid request, got %v", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user