修复完成订单自动回显
This commit is contained in:
@@ -973,9 +973,7 @@ func (r *Repository) finalizeCheckout(tx *gorm.DB, order *model.RentalOrder, che
|
||||
order.SettlementStatus = "settled"
|
||||
order.SettledAt = &now
|
||||
order.OwnerSettledAt = &now
|
||||
listing.Status = "published"
|
||||
listing.InTransaction = false
|
||||
account.Status = "published"
|
||||
archiveListingAfterCheckout(&listing, &account)
|
||||
orderID := order.ID
|
||||
settlement := buildCheckoutSettlement(*order, checkout)
|
||||
|
||||
@@ -1062,6 +1060,14 @@ func (r *Repository) finalizeCheckout(tx *gorm.DB, order *model.RentalOrder, che
|
||||
return refund, nil
|
||||
}
|
||||
|
||||
// 完成后的账号先下架,避免已完成订单对应的账号重新出现在公开首页。
|
||||
func archiveListingAfterCheckout(listing *model.RentalListing, account *model.GameAccount) {
|
||||
listing.Status = "offline"
|
||||
listing.InTransaction = false
|
||||
listing.PublishedAt = nil
|
||||
account.Status = "offline"
|
||||
}
|
||||
|
||||
func (r *Repository) prepareRefund(order *model.RentalOrder, amountCent int64, bizType string, remark string) (*refundAction, error) {
|
||||
if amountCent <= 0 {
|
||||
return nil, nil
|
||||
|
||||
@@ -2,6 +2,7 @@ package order
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
@@ -112,3 +113,30 @@ func TestCalculateCheckoutSettlementAddsDepositCompensation(t *testing.T) {
|
||||
t.Fatalf("RenterRefund = %.2f, want 120.00", settlement.RenterRefund)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArchiveListingAfterCheckoutMovesListingOffline(t *testing.T) {
|
||||
now := time.Now()
|
||||
listing := model.RentalListing{
|
||||
Status: "published",
|
||||
InTransaction: true,
|
||||
PublishedAt: &now,
|
||||
}
|
||||
account := model.GameAccount{
|
||||
Status: "published",
|
||||
}
|
||||
|
||||
archiveListingAfterCheckout(&listing, &account)
|
||||
|
||||
if listing.Status != "offline" {
|
||||
t.Fatalf("listing status = %q, want offline", listing.Status)
|
||||
}
|
||||
if listing.InTransaction {
|
||||
t.Fatal("listing in_transaction should be false")
|
||||
}
|
||||
if listing.PublishedAt != nil {
|
||||
t.Fatal("listing published_at should be nil")
|
||||
}
|
||||
if account.Status != "offline" {
|
||||
t.Fatalf("account status = %q, want offline", account.Status)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user