feat(orders): 号主可从自己的列表隐藏已结束订单

只写入隐藏时间,订单和款项仍保留给租客与后台。详情按钮固定对齐,删除跟在后面。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
yml2213
2026-10-01 16:22:55 +08:00
co-authored by Cursor
parent a1008f7e6a
commit e5cd7b5c34
15 changed files with 499 additions and 15 deletions
+24 -5
View File
@@ -14,8 +14,9 @@ import (
func (r *Repository) ListForUser(ctx context.Context, userID uint64, page, pageSize int, siteCode ...string) (*UserPaginatedResult, error) {
page, pageSize = normalizePagination(page, pageSize)
base := r.baseQuery(ctx).Where("o.renter_id = ? OR o.owner_id = ?", userID, userID)
countBase := r.db.WithContext(ctx).Table("rental_orders AS o").Where("o.renter_id = ? OR o.owner_id = ?", userID, userID)
ownerVisible := "NOT (o.owner_id = ? AND o.owner_hidden_at IS NOT NULL)"
base := r.baseQuery(ctx).Where("o.renter_id = ? OR o.owner_id = ?", userID, userID).Where(ownerVisible, userID)
countBase := r.db.WithContext(ctx).Table("rental_orders AS o").Where("o.renter_id = ? OR o.owner_id = ?", userID, userID).Where(ownerVisible, userID)
var code string
if len(siteCode) > 0 {
@@ -46,6 +47,16 @@ func (r *Repository) ListForUser(ctx context.Context, userID uint64, page, pageS
if err != nil {
return nil, err
}
ownerOrderIDs := make([]uint64, 0, len(rows))
for _, row := range rows {
if row.OwnerID == userID {
ownerOrderIDs = append(ownerOrderIDs, row.ID)
}
}
signals, err := loadOwnerHideSignals(db, ownerOrderIDs)
if err != nil {
return nil, err
}
items := make([]UserOrderListItemDTO, 0, len(rows))
paymentTimeoutMinutes := pendingPaymentTimeoutMinutes(db)
for _, row := range rows {
@@ -54,7 +65,12 @@ func (r *Repository) ListForUser(ctx context.Context, userID uint64, page, pageS
value := row.CreatedAt.Add(time.Duration(paymentTimeoutMinutes) * time.Minute)
deadline = &value
}
items = append(items, row.toUserListItem(userID, deadline))
item := row.toUserListItem(userID, deadline)
if item.Role == "owner" {
_, disputed := signals.disputed[row.ID]
item.CanHide = ownerMayHideOrder(row.RentalOrder, disputed, signals.dist[row.ID])
}
items = append(items, item)
}
return &UserPaginatedResult{Items: items, Total: total, Page: page, PageSize: pageSize}, nil
}
@@ -63,6 +79,7 @@ func (r *Repository) ListSellerHandoffs(ctx context.Context, userID uint64, quer
page, pageSize := normalizePagination(query.Page, query.PageSize)
base := r.baseQuery(ctx).
Where("o.owner_id = ?", userID).
Where("o.owner_hidden_at IS NULL").
Where("o.status IN ?", sellerHandoffStatuses())
if query.Status != "" {
base = base.Where("o.status = ?", query.Status)
@@ -98,7 +115,7 @@ func (r *Repository) ListSellerHandoffs(ctx context.Context, userID uint64, quer
}
func (r *Repository) sellerHandoffMetrics(ctx context.Context, userID uint64, siteCode ...string) (SellerHandoffMetrics, error) {
base := r.db.WithContext(ctx).Table("rental_orders AS o").Where("o.owner_id = ?", userID)
base := r.db.WithContext(ctx).Table("rental_orders AS o").Where("o.owner_id = ? AND o.owner_hidden_at IS NULL", userID)
if len(siteCode) > 0 && siteCode[0] != "" {
base = base.Joins("INNER JOIN distribution_sites AS ds ON ds.id = o.distribution_site_id AND ds.site_code = ?", siteCode[0])
}
@@ -372,7 +389,9 @@ func (r *Repository) FindLatestAdminByListing(ctx context.Context, listingID uin
func (r *Repository) FindForUser(ctx context.Context, userID uint64, orderID uint64, siteCode ...string) (*OrderDTO, error) {
var row orderRow
db := r.db.WithContext(ctx)
query := r.baseQuery(ctx).Where("o.id = ? AND (o.renter_id = ? OR o.owner_id = ?)", orderID, userID, userID)
query := r.baseQuery(ctx).
Where("o.id = ? AND (o.renter_id = ? OR o.owner_id = ?)", orderID, userID, userID).
Where("NOT (o.owner_id = ? AND o.owner_hidden_at IS NOT NULL)", userID)
var code string
if len(siteCode) > 0 {