feat(tenant): 按租户隔离用户身份与后台权限
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
"strings"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
)
|
||||
|
||||
// 转换为用户DTO
|
||||
@@ -58,7 +59,11 @@ func (r *Repository) toAdminListItems(ctx context.Context, withdrawals []model.W
|
||||
|
||||
usersByID := make(map[uint64]model.User, len(userIDs))
|
||||
var users []model.User
|
||||
if err := r.db.WithContext(ctx).Select("id, nickname, phone").Where("id IN ?", userIDs).Find(&users).Error; err != nil {
|
||||
userQuery := r.db.WithContext(ctx).Select("id, nickname, phone").Where("id IN ?", userIDs)
|
||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||
userQuery = userQuery.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := userQuery.Find(&users).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, user := range users {
|
||||
@@ -106,9 +111,14 @@ func (r *Repository) toAdminListItems(ctx context.Context, withdrawals []model.W
|
||||
// 转换为管理员详细DTO
|
||||
func (r *Repository) toDetailDTO(ctx context.Context, w model.WithdrawalRequest) (*WithdrawalDetailDTO, error) {
|
||||
db := r.db.WithContext(ctx)
|
||||
tenantID := tenancy.IDFromContext(ctx)
|
||||
// 查询用户信息
|
||||
var user model.User
|
||||
db.Select("nickname, phone").First(&user, w.UserID)
|
||||
userQuery := db.Select("nickname, phone").Where("id = ?", w.UserID)
|
||||
if tenantID > 0 {
|
||||
userQuery = userQuery.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
userQuery.First(&user)
|
||||
|
||||
// 查询审核人信息
|
||||
var reviewedByName string
|
||||
@@ -133,7 +143,11 @@ func (r *Repository) toDetailDTO(ctx context.Context, w model.WithdrawalRequest)
|
||||
var certificateURLs []string
|
||||
if w.PaymentAccountID != nil {
|
||||
var paymentAccount model.UserPaymentAccount
|
||||
if err := db.First(&paymentAccount, *w.PaymentAccountID).Error; err == nil {
|
||||
accountQuery := db.Where("id = ?", *w.PaymentAccountID)
|
||||
if tenantID > 0 {
|
||||
accountQuery = accountQuery.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := accountQuery.First(&paymentAccount).Error; err == nil {
|
||||
// 解密账号
|
||||
decrypted, err := r.encryptor.Decrypt(paymentAccount.AccountNo)
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user