优化商品管理筛选功能
This commit is contained in:
@@ -81,6 +81,10 @@ type AdminListQuery struct {
|
||||
Load []string
|
||||
SkinGroup []string
|
||||
SkinName []string
|
||||
MinCoin *float64
|
||||
MaxCoin *float64
|
||||
MinDeposit *float64
|
||||
MaxDeposit *float64
|
||||
Limit int
|
||||
Page int
|
||||
PageSize int
|
||||
|
||||
@@ -79,6 +79,10 @@ func parseAdminListQuery(c *gin.Context) (AdminListQuery, bool) {
|
||||
query.Load = parseCSVQuery(c.Query("load"))
|
||||
query.SkinGroup = parseCSVQuery(c.Query("skin_group"))
|
||||
query.SkinName = parseCSVQuery(firstNonEmpty(c.Query("skin_name"), c.Query("skin")))
|
||||
query.MinCoin = parseOptionalFloat(c.Query("min_coin"))
|
||||
query.MaxCoin = parseOptionalFloat(c.Query("max_coin"))
|
||||
query.MinDeposit = parseOptionalFloat(c.Query("min_deposit"))
|
||||
query.MaxDeposit = parseOptionalFloat(c.Query("max_deposit"))
|
||||
return query, true
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package listing
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
@@ -113,9 +114,41 @@ func (r *Repository) applyAdminListFilters(db *gorm.DB, query AdminListQuery) *g
|
||||
if query.ReviewStatus != "" {
|
||||
db = db.Where("l.review_status = ?", query.ReviewStatus)
|
||||
}
|
||||
if query.MinCoin != nil {
|
||||
db = db.Where(
|
||||
"EXISTS (SELECT 1 FROM game_accounts AS coin_account WHERE coin_account.id = l.account_id AND coin_account.haf_coin_amount >= ?)",
|
||||
coinMToAdminAmount(*query.MinCoin),
|
||||
)
|
||||
}
|
||||
if query.MaxCoin != nil {
|
||||
db = db.Where(
|
||||
"EXISTS (SELECT 1 FROM game_accounts AS coin_account WHERE coin_account.id = l.account_id AND coin_account.haf_coin_amount <= ?)",
|
||||
coinMToAdminAmount(*query.MaxCoin),
|
||||
)
|
||||
}
|
||||
if query.MinDeposit != nil {
|
||||
db = db.Where("l.deposit_amount_cent >= ?", yuanToAdminCent(*query.MinDeposit))
|
||||
}
|
||||
if query.MaxDeposit != nil {
|
||||
db = db.Where("l.deposit_amount_cent <= ?", yuanToAdminCent(*query.MaxDeposit))
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func coinMToAdminAmount(value float64) int64 {
|
||||
if value <= 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
}
|
||||
return int64(math.Round(value * 1000000))
|
||||
}
|
||||
|
||||
func yuanToAdminCent(value float64) int64 {
|
||||
if value <= 0 || math.IsNaN(value) || math.IsInf(value, 0) {
|
||||
return 0
|
||||
}
|
||||
return int64(math.Round(value * 100))
|
||||
}
|
||||
|
||||
func (r *Repository) FindAdmin(ctx context.Context, listingID uint64) (*ListingDTO, error) {
|
||||
return r.findDTO(ctx, "l.id = ?", listingID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user