feat(user): 支持后台调整等级并限制极品专区可见性
This commit is contained in:
@@ -73,9 +73,16 @@ func TestApplyUserFilterHasDepositFreeQuota(t *testing.T) {
|
||||
if !strings.Contains(sql, "u.deposit_free_quota_cent > 0 OR u.renter_growth_points >=") {
|
||||
t.Fatalf("SQL 未包含免押额度过滤:%s", sql)
|
||||
}
|
||||
if len(stmt.Vars) != 2 || stmt.Vars[0] != "active" || stmt.Vars[1] != int64(300) {
|
||||
if len(stmt.Vars) != 5 || stmt.Vars[0] != "active" || stmt.Vars[1] != int64(300) {
|
||||
t.Fatalf("筛选变量不正确:%v", stmt.Vars)
|
||||
}
|
||||
overrideCodes := stmt.Vars[2:]
|
||||
if len(overrideCodes) != 3 ||
|
||||
overrideCodes[0] != "platinum" ||
|
||||
overrideCodes[1] != "diamond" ||
|
||||
overrideCodes[2] != "peak" {
|
||||
t.Fatalf("手动等级筛选变量不正确:%v", overrideCodes)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdjustGrowthPointsWritesRepeatableLedgers(t *testing.T) {
|
||||
@@ -120,6 +127,65 @@ func TestAdjustGrowthPointsWritesRepeatableLedgers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdjustGrowthLevelLocksLevelAndWritesAudit(t *testing.T) {
|
||||
db := setupAdminUserTestDB(t)
|
||||
user := model.User{
|
||||
Phone: "13900000006",
|
||||
Status: "active",
|
||||
RenterGrowthPoints: 100,
|
||||
RenterGrowthLevel: rentergrowth.DefaultLevelCode,
|
||||
}
|
||||
if err := db.Create(&user).Error; err != nil {
|
||||
t.Fatalf("创建用户失败:%v", err)
|
||||
}
|
||||
repo := NewRepository(db)
|
||||
|
||||
got, err := repo.AdjustGrowthLevel(t.Context(), 66, user.ID, GrowthLevelAdjustRequest{
|
||||
TargetLevel: "platinum",
|
||||
Reason: "客服核验后手动调整",
|
||||
}, AuditMeta{RequestID: "level-1"})
|
||||
if err != nil {
|
||||
t.Fatalf("手动调整等级失败:%v", err)
|
||||
}
|
||||
if got.RenterGrowthLevel != "platinum" || !got.RenterGrowthLevelManual ||
|
||||
got.RenterGrowthLevelOverride != "platinum" {
|
||||
t.Fatalf("手动等级结果不正确:%+v", got)
|
||||
}
|
||||
|
||||
got, err = repo.AdjustGrowthPoints(t.Context(), 66, user.ID, GrowthPointsAdjustRequest{
|
||||
TargetPoints: 1000,
|
||||
Reason: "补充成长积分",
|
||||
}, AuditMeta{RequestID: "points-after-level"})
|
||||
if err != nil {
|
||||
t.Fatalf("调整积分失败:%v", err)
|
||||
}
|
||||
if got.RenterGrowthLevel != "platinum" || got.RenterGrowthLevelOverride != "platinum" {
|
||||
t.Fatalf("积分调整不应覆盖手动等级:%+v", got)
|
||||
}
|
||||
|
||||
got, err = repo.AdjustGrowthLevel(t.Context(), 66, user.ID, GrowthLevelAdjustRequest{
|
||||
TargetLevel: "",
|
||||
Reason: "恢复积分自动计算",
|
||||
}, AuditMeta{RequestID: "level-auto"})
|
||||
if err != nil {
|
||||
t.Fatalf("恢复自动等级失败:%v", err)
|
||||
}
|
||||
if got.RenterGrowthLevel != "diamond" || got.RenterGrowthLevelManual ||
|
||||
got.RenterGrowthLevelOverride != "" {
|
||||
t.Fatalf("恢复自动等级结果不正确:%+v", got)
|
||||
}
|
||||
|
||||
var auditCount int64
|
||||
if err := db.Model(&model.AuditLog{}).
|
||||
Where("action = ? AND biz_id = ?", "admin_user.adjust_growth_level", user.ID).
|
||||
Count(&auditCount).Error; err != nil {
|
||||
t.Fatalf("查询审计日志失败:%v", err)
|
||||
}
|
||||
if auditCount != 2 {
|
||||
t.Fatalf("等级调整审计日志数量 = %d, want 2", auditCount)
|
||||
}
|
||||
}
|
||||
|
||||
func TestManualRealnameUpdatesUserRecordAndAudit(t *testing.T) {
|
||||
db := setupAdminUserTestDB(t)
|
||||
user := model.User{
|
||||
|
||||
Reference in New Issue
Block a user