优化后台列表搜索

This commit is contained in:
yml2213
2026-06-21 13:17:10 +08:00
parent a0145e6b18
commit 23dbe9af22
11 changed files with 166 additions and 21 deletions
+1
View File
@@ -73,6 +73,7 @@ type TransferOwnerRequest struct {
type AdminListQuery struct {
OwnerID uint64
Keyword string
Status string
ReviewStatus string
Limit int
@@ -71,6 +71,7 @@ func parseAdminListQuery(c *gin.Context) (AdminListQuery, bool) {
}
query.PageSize = value
}
query.Keyword = strings.TrimSpace(c.Query("keyword"))
query.Status = c.Query("status")
query.ReviewStatus = c.Query("review_status")
return query, true
+20
View File
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strconv"
"strings"
"time"
"hfb_sys/backend/internal/model"
@@ -56,6 +57,25 @@ func (r *Repository) applyAdminListFilters(db *gorm.DB, query AdminListQuery) *g
if query.OwnerID > 0 {
db = db.Where("l.owner_id = ?", query.OwnerID)
}
if keyword := strings.TrimSpace(query.Keyword); keyword != "" {
like := "%" + keyword + "%"
if id, err := strconv.ParseUint(keyword, 10, 64); err == nil {
db = db.Where(
`(l.listing_no LIKE ? OR EXISTS (SELECT 1 FROM rental_orders AS o WHERE o.listing_id = l.id AND o.order_no LIKE ?) OR l.id = ? OR l.account_id = ? OR l.owner_id = ?)`,
like,
like,
id,
id,
id,
)
} else {
db = db.Where(
`(l.listing_no LIKE ? OR EXISTS (SELECT 1 FROM rental_orders AS o WHERE o.listing_id = l.id AND o.order_no LIKE ?))`,
like,
like,
)
}
}
if query.Status != "" {
db = db.Where("l.status = ?", query.Status)
}