fix(withdrawal): 允许平台超管审核历史分销提现
This commit is contained in:
@@ -520,3 +520,67 @@ func TestWithdrawalRequestsAreScopedByTenant(t *testing.T) {
|
||||
t.Fatalf("jieyou withdrawal list = %+v", list)
|
||||
}
|
||||
}
|
||||
|
||||
func TestWithdrawalAdminAllTenantScopeIncludesLegacyDistribution(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
site := model.DistributionSite{
|
||||
SiteCode: "legacy_tianyu", SiteName: "天域商行",
|
||||
Domain: "legacy-tianyu.example.com", Status: "active",
|
||||
}
|
||||
if err := db.Create(&site).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
users := []model.User{
|
||||
{TenantID: 0, DistributionSiteID: site.ID, Phone: "13300000101", Status: "active"},
|
||||
{TenantID: 101, Phone: "13300000102", Status: "active"},
|
||||
{TenantID: 202, Phone: "13300000103", Status: "active"},
|
||||
}
|
||||
if err := db.Create(&users).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
withdrawals := []model.WithdrawalRequest{
|
||||
{WithdrawNo: "WD-LEGACY-SITE", TenantID: 0, UserID: users[0].ID, DistributionSiteID: site.ID, AmountCent: 1000, ActualAmountCent: 1000, AccountType: "bank", AccountName: "张三", AccountNo: "****0001", Status: "pending"},
|
||||
{WithdrawNo: "WD-DACHUI", TenantID: 101, UserID: users[1].ID, AmountCent: 2000, ActualAmountCent: 2000, AccountType: "bank", AccountName: "张三", AccountNo: "****0002", Status: "pending"},
|
||||
{WithdrawNo: "WD-JIEYOU", TenantID: 202, UserID: users[2].ID, AmountCent: 3000, ActualAmountCent: 3000, AccountType: "bank", AccountName: "张三", AccountNo: "****0003", Status: "pending"},
|
||||
}
|
||||
if err := db.Create(&withdrawals).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
repo := NewRepository(db, wallet.NewRepository(db), &crypto.MockEncryptor{})
|
||||
dachuiCtx := withdrawalTenantContext(101)
|
||||
dachuiList, err := repo.AdminList(dachuiCtx, AdminListQuery{Page: 1, Size: 20})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if dachuiList.Total != 1 || dachuiList.Items[0].ID != withdrawals[1].ID {
|
||||
t.Fatalf("dachui withdrawal list = %+v, want only dachui tenant", dachuiList)
|
||||
}
|
||||
if _, err := repo.AdminFindByID(dachuiCtx, withdrawals[0].ID); !errors.Is(err, ErrWithdrawalNotFound) {
|
||||
t.Fatalf("dachui admin legacy detail error = %v, want not found", err)
|
||||
}
|
||||
|
||||
superCtx := tenancy.WithAdminAllTenantScope(dachuiCtx)
|
||||
superList, err := repo.AdminList(superCtx, AdminListQuery{Page: 1, Size: 20})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if superList.Total != 3 || len(superList.Items) != 3 {
|
||||
t.Fatalf("platform super admin withdrawal list = %+v, want all 3", superList)
|
||||
}
|
||||
detail, err := repo.AdminFindByID(superCtx, withdrawals[0].ID)
|
||||
if err != nil {
|
||||
t.Fatalf("platform super admin legacy detail: %v", err)
|
||||
}
|
||||
if detail.DistributionSiteID != site.ID || detail.DistributionSiteName != site.SiteName {
|
||||
t.Fatalf("legacy withdrawal detail = %+v", detail)
|
||||
}
|
||||
approved := true
|
||||
reviewed, err := repo.Review(superCtx, 1, withdrawals[0].ID, ReviewWithdrawalRequest{Approved: &approved})
|
||||
if err != nil {
|
||||
t.Fatalf("platform super admin legacy review: %v", err)
|
||||
}
|
||||
if reviewed.Status != "processing" {
|
||||
t.Fatalf("legacy withdrawal review status = %q, want processing", reviewed.Status)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user