feat(adminuser): 优化用户管理筛选并展示筛选人数
- 免押额度与号主类型改为下拉筛选,支持有/无和优质/普通 - 新增用户成长等级筛选 - 列表上方固定展示筛选结果人数,补充组合筛选测试
This commit is contained in:
@@ -52,6 +52,11 @@ func (r *Repository) List(ctx context.Context, page, pageSize int, query ListQue
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if query.GrowthLevel != "" {
|
||||
if _, ok := rentergrowth.LevelForCode(growthConfig, query.GrowthLevel); !ok {
|
||||
return nil, ErrInvalidGrowthLevel
|
||||
}
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
var rows []userRow
|
||||
listTx := r.db.WithContext(ctx).Table("users AS u").
|
||||
@@ -99,25 +104,30 @@ func applyUserFilter(tx *gorm.DB, query ListQuery, growthConfig rentergrowth.Con
|
||||
if query.Status != "" {
|
||||
tx = tx.Where("u.status = ?", query.Status)
|
||||
}
|
||||
if query.HasDepositFreeQuota {
|
||||
quotaLevelCodes := growthQuotaLevelCodes(growthConfig)
|
||||
if minPoints, ok := minimumGrowthQuotaPoints(growthConfig); ok {
|
||||
tx = tx.Where(
|
||||
"u.deposit_free_quota_cent > 0 OR u.renter_growth_points >= ? OR u.renter_growth_level_override IN ?",
|
||||
minPoints,
|
||||
quotaLevelCodes,
|
||||
)
|
||||
} else if len(quotaLevelCodes) > 0 {
|
||||
tx = tx.Where(
|
||||
"u.deposit_free_quota_cent > 0 OR u.renter_growth_level_override IN ?",
|
||||
quotaLevelCodes,
|
||||
)
|
||||
depositFreeQuota := query.DepositFreeQuota
|
||||
if depositFreeQuota == "" && query.HasDepositFreeQuota {
|
||||
depositFreeQuota = "has"
|
||||
}
|
||||
if depositFreeQuota != "" {
|
||||
condition, args := depositFreeQuotaCondition(growthConfig)
|
||||
if depositFreeQuota == "none" {
|
||||
tx = tx.Where("NOT ("+condition+")", args...)
|
||||
} else {
|
||||
tx = tx.Where("u.deposit_free_quota_cent > 0")
|
||||
tx = tx.Where(condition, args...)
|
||||
}
|
||||
}
|
||||
if query.QualityOwnerOnly {
|
||||
ownerType := query.OwnerType
|
||||
if ownerType == "" && query.QualityOwnerOnly {
|
||||
ownerType = "quality"
|
||||
}
|
||||
switch ownerType {
|
||||
case "quality":
|
||||
tx = tx.Where("u.quality_owner_status = ?", "active")
|
||||
case "normal":
|
||||
tx = tx.Where("u.quality_owner_status <> ?", "active")
|
||||
}
|
||||
if query.GrowthLevel != "" {
|
||||
tx = tx.Where("u.renter_growth_level = ?", query.GrowthLevel)
|
||||
}
|
||||
if keyword := strings.TrimSpace(query.Keyword); keyword != "" {
|
||||
if len(keyword) == 11 && keyword[0] == '1' && isAllDigits(keyword) {
|
||||
@@ -135,6 +145,21 @@ func applyUserFilter(tx *gorm.DB, query ListQuery, growthConfig rentergrowth.Con
|
||||
return tx
|
||||
}
|
||||
|
||||
// depositFreeQuotaCondition 返回“有免押额度”的 SQL 条件:
|
||||
// 人工额度 > 0,或当前成长等级自带免押额度。
|
||||
func depositFreeQuotaCondition(cfg rentergrowth.Config) (string, []any) {
|
||||
quotaLevelCodes := growthQuotaLevelCodes(cfg)
|
||||
if minPoints, ok := minimumGrowthQuotaPoints(cfg); ok {
|
||||
return "u.deposit_free_quota_cent > 0 OR u.renter_growth_points >= ? OR u.renter_growth_level_override IN ?",
|
||||
[]any{minPoints, quotaLevelCodes}
|
||||
}
|
||||
if len(quotaLevelCodes) > 0 {
|
||||
return "u.deposit_free_quota_cent > 0 OR u.renter_growth_level_override IN ?",
|
||||
[]any{quotaLevelCodes}
|
||||
}
|
||||
return "u.deposit_free_quota_cent > 0", nil
|
||||
}
|
||||
|
||||
func growthQuotaLevelCodes(cfg rentergrowth.Config) []string {
|
||||
codes := make([]string, 0, len(cfg.Levels))
|
||||
for _, level := range cfg.Levels {
|
||||
|
||||
Reference in New Issue
Block a user