feat: add TenantDetail and UserDetail views with comprehensive functionality
- Implemented TenantDetail.vue to display tenant information, manage tenant status, and handle tenant renewals. - Added user management features in UserDetail.vue, including user status updates and role management. - Integrated data loading for tenant users and orders in TenantDetail.vue. - Included search and pagination functionalities for owned and joined tenants in UserDetail.vue. - Enhanced user experience with toast notifications for success and error messages.
This commit is contained in:
@@ -26,6 +26,49 @@ import (
|
||||
// @provider
|
||||
type tenant struct{}
|
||||
|
||||
// SuperDetail 查询单个租户详情(平台侧)。
|
||||
func (t *tenant) SuperDetail(ctx context.Context, tenantID int64) (*superdto.TenantItem, error) {
|
||||
if tenantID <= 0 {
|
||||
return nil, errors.New("tenant_id must be > 0")
|
||||
}
|
||||
|
||||
tbl, query := models.TenantQuery.QueryContext(ctx)
|
||||
m, err := query.Where(tbl.ID.Eq(tenantID)).First()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
userCountMapping, err := t.TenantUserCountMapping(ctx, []int64{m.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
incomeMapping, err := t.TenantIncomePaidMapping(ctx, []int64{m.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
item := &superdto.TenantItem{
|
||||
Tenant: m,
|
||||
UserCount: lo.ValueOr(userCountMapping, m.ID, 0),
|
||||
IncomeAmountPaidSum: lo.ValueOr(incomeMapping, m.ID, 0),
|
||||
StatusDescription: m.Status.Description(),
|
||||
}
|
||||
|
||||
ownerMapping, err := t.TenantOwnerUserMapping(ctx, []*models.Tenant{m})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item.Owner = ownerMapping[m.ID]
|
||||
|
||||
adminMapping, err := t.TenantAdminUsersMapping(ctx, []int64{m.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
item.AdminUsers = adminMapping[m.ID]
|
||||
|
||||
return item, nil
|
||||
}
|
||||
|
||||
// SuperCreateTenant 超级管理员创建租户,并将指定用户设为租户管理员。
|
||||
func (t *tenant) SuperCreateTenant(ctx context.Context, form *superdto.TenantCreateForm) (*models.Tenant, error) {
|
||||
if form == nil {
|
||||
|
||||
@@ -41,6 +41,42 @@ func (t *user) FindByUsername(ctx context.Context, username string) (*models.Use
|
||||
return model, nil
|
||||
}
|
||||
|
||||
// Detail 查询用户详情(超级管理员侧,返回脱敏后的 DTO)。
|
||||
func (t *user) Detail(ctx context.Context, userID int64) (*dto.UserItem, error) {
|
||||
if userID <= 0 {
|
||||
return nil, errors.New("user_id must be > 0")
|
||||
}
|
||||
|
||||
model, err := t.FindByID(ctx, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ownedTenantCounts, err := t.UserOwnedTenantCountMapping(ctx, []int64{model.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
joinedTenantCounts, err := t.UserJoinedTenantCountMapping(ctx, []int64{model.ID})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.UserItem{
|
||||
ID: model.ID,
|
||||
Username: model.Username,
|
||||
Roles: model.Roles,
|
||||
Status: model.Status,
|
||||
StatusDescription: model.Status.Description(),
|
||||
Balance: model.Balance,
|
||||
BalanceFrozen: model.BalanceFrozen,
|
||||
VerifiedAt: model.VerifiedAt,
|
||||
CreatedAt: model.CreatedAt,
|
||||
UpdatedAt: model.UpdatedAt,
|
||||
OwnedTenantCount: ownedTenantCounts[model.ID],
|
||||
JoinedTenantCount: joinedTenantCounts[model.ID],
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (t *user) Create(ctx context.Context, user *models.User) (*models.User, error) {
|
||||
if err := user.Create(ctx); err != nil {
|
||||
return nil, errors.Wrapf(err, "Create user failed, %s", user.Username)
|
||||
|
||||
Reference in New Issue
Block a user