feat(listings): 订单和账号详情展示可租时长与每日消耗

租客在订单列表和详情标题能看到每个号的租期、消耗。账号详情把这两项拆成独立格子。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-10-05 16:32:08 +08:00
co-authored by Cursor
parent c559287ee4
commit f2060c19cf
18 changed files with 393 additions and 71 deletions
@@ -7,6 +7,8 @@ import (
"time"
"hfb_sys/backend/internal/model"
"gorm.io/datatypes"
)
func TestOrderDTOForUserHidesDepositHoldFields(t *testing.T) {
@@ -72,6 +74,44 @@ func TestUserOrderListItemDoesNotSerializeDetailFields(t *testing.T) {
}
}
func TestUserOrderListItemIncludesRentalTerms(t *testing.T) {
row := orderRow{
RentalOrder: model.RentalOrder{
AccountSnapshot: datatypes.JSON([]byte(`{"haf_coin_amount":100000000,"asset_summary":{"daily_loss_m":10}}`)),
},
Title: "微信 三角洲巅峰 100M哈夫币",
}
item := row.toUserListItem(20, nil)
if item.RentalDays != 10 {
t.Fatalf("rental days = %d, want 10", item.RentalDays)
}
if item.DailyLossM != 10 {
t.Fatalf("daily loss = %v, want 10", item.DailyLossM)
}
raw, err := json.Marshal(item)
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
text := string(raw)
if !strings.Contains(text, `"rental_days":10`) || !strings.Contains(text, `"daily_loss_m":10`) {
t.Fatalf("list response missing rental terms: %s", text)
}
}
func TestUserOrderListItemOmitsRentalTermsWithoutSnapshot(t *testing.T) {
item := orderRow{Title: "测试账号"}.toUserListItem(20, nil)
raw, err := json.Marshal(item)
if err != nil {
t.Fatalf("Marshal() error = %v", err)
}
text := string(raw)
if strings.Contains(text, "rental_days") || strings.Contains(text, "daily_loss_m") {
t.Fatalf("empty snapshot should omit rental terms: %s", text)
}
}
func TestAdminOrderListItemShowsPhonesAndOmitsSnapshot(t *testing.T) {
row := orderRow{
RentalOrder: model.RentalOrder{ID: 1, OrderNo: "ORD-001", Status: orderStatusPendingPayment},