fix(wallet): 保留历史分销用户零租户归属
This commit is contained in:
@@ -277,9 +277,10 @@ func resolveTenantID(db *gorm.DB, explicitTenantID uint64, userID uint64) uint64
|
|||||||
return explicitTenantID
|
return explicitTenantID
|
||||||
}
|
}
|
||||||
if userID > 0 {
|
if userID > 0 {
|
||||||
var tenantID uint64
|
var user model.User
|
||||||
if err := db.Model(&model.User{}).Select("tenant_id").Where("id = ?", userID).Scan(&tenantID).Error; err == nil && tenantID > 0 {
|
if err := db.Select("tenant_id").Where("id = ?", userID).Take(&user).Error; err == nil {
|
||||||
return tenantID
|
// 历史分销用户明确属于 tenant_id=0,不能再用当前后台租户覆盖。
|
||||||
|
return user.TenantID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if tenantID := tenantIDFromDB(db); tenantID > 0 {
|
if tenantID := tenantIDFromDB(db); tenantID > 0 {
|
||||||
|
|||||||
@@ -538,6 +538,15 @@ func TestWithdrawalAdminAllTenantScopeIncludesLegacyDistribution(t *testing.T) {
|
|||||||
if err := db.Create(&users).Error; err != nil {
|
if err := db.Create(&users).Error; err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
if err := db.Create(&model.WalletAccount{
|
||||||
|
TenantID: 0,
|
||||||
|
UserID: users[0].ID,
|
||||||
|
DistributionSiteID: site.ID,
|
||||||
|
FrozenBalanceCent: 1000,
|
||||||
|
Status: "active",
|
||||||
|
}).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
withdrawals := []model.WithdrawalRequest{
|
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-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-DACHUI", TenantID: 101, UserID: users[1].ID, AmountCent: 2000, ActualAmountCent: 2000, AccountType: "bank", AccountName: "张三", AccountNo: "****0002", Status: "pending"},
|
||||||
@@ -599,4 +608,21 @@ func TestWithdrawalAdminAllTenantScopeIncludesLegacyDistribution(t *testing.T) {
|
|||||||
if reviewed.Status != "processing" {
|
if reviewed.Status != "processing" {
|
||||||
t.Fatalf("legacy withdrawal review status = %q, want processing", reviewed.Status)
|
t.Fatalf("legacy withdrawal review status = %q, want processing", reviewed.Status)
|
||||||
}
|
}
|
||||||
|
paid, err := repo.ConfirmPayment(dachuiFinanceCtx, 5, withdrawals[0].ID, ConfirmPaymentRequest{
|
||||||
|
Remark: "已通过微信转账",
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("dachui legacy confirm payment: %v", err)
|
||||||
|
}
|
||||||
|
if paid.Status != "completed" {
|
||||||
|
t.Fatalf("legacy withdrawal paid status = %q, want completed", paid.Status)
|
||||||
|
}
|
||||||
|
var walletAccount model.WalletAccount
|
||||||
|
if err := db.Where("user_id = ? AND distribution_site_id = ?", users[0].ID, site.ID).
|
||||||
|
First(&walletAccount).Error; err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if walletAccount.FrozenBalanceCent != 0 {
|
||||||
|
t.Fatalf("legacy wallet frozen balance = %d, want 0", walletAccount.FrozenBalanceCent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user