feat: add tenant admin invite management, ledger overview, order details, and order management features
- Implemented Invite management with creation, searching, and disabling functionalities. - Added Ledger overview for financial transactions with filtering options. - Developed Order Detail view for individual order insights and refund capabilities. - Created Orders management page with search, reset, and pagination features. - Enhanced user experience with toast notifications for actions and error handling.
This commit is contained in:
@@ -7,6 +7,7 @@ import (
|
||||
|
||||
superdto "quyun/v2/app/http/super/dto"
|
||||
tenantdto "quyun/v2/app/http/tenant/dto"
|
||||
web_dto "quyun/v2/app/http/web/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database"
|
||||
"quyun/v2/database/models"
|
||||
@@ -26,6 +27,72 @@ import (
|
||||
// @provider
|
||||
type tenant struct{}
|
||||
|
||||
// UserTenants 查询“当前用户可进入的租户列表”(平台通用域 /v1)。
|
||||
// - 返回 tenant_users 维度的角色与加入时间,便于前端做“选择租户进入后台”的交互。
|
||||
// - 不做租户状态过滤:前端可以根据 TenantStatusDescription 做提示或禁用进入按钮。
|
||||
func (t *tenant) UserTenants(ctx context.Context, userID int64) ([]*web_dto.MyTenantItem, error) {
|
||||
if userID <= 0 {
|
||||
return nil, errors.New("user_id must be > 0")
|
||||
}
|
||||
|
||||
// 先查 tenant_users,拿到用户加入的租户ID与角色信息(避免 join scan 冲突/字段覆盖问题)。
|
||||
tuTbl, tuQuery := models.TenantUserQuery.QueryContext(ctx)
|
||||
tenantUsers, err := tuQuery.Where(tuTbl.UserID.Eq(userID)).Order(tuTbl.ID.Desc()).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(tenantUsers) == 0 {
|
||||
return []*web_dto.MyTenantItem{}, nil
|
||||
}
|
||||
|
||||
tenantIDs := lo.Uniq(lo.FilterMap(tenantUsers, func(tu *models.TenantUser, _ int) (int64, bool) {
|
||||
if tu == nil || tu.TenantID <= 0 {
|
||||
return 0, false
|
||||
}
|
||||
return tu.TenantID, true
|
||||
}))
|
||||
if len(tenantIDs) == 0 {
|
||||
return []*web_dto.MyTenantItem{}, nil
|
||||
}
|
||||
|
||||
// 再查 tenants(批量),并构建映射,保持输出顺序以 tenant_users 为准。
|
||||
teTbl, teQuery := models.TenantQuery.QueryContext(ctx)
|
||||
tenants, err := teQuery.Where(teTbl.ID.In(tenantIDs...)).Find()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tenantMap := make(map[int64]*models.Tenant, len(tenants))
|
||||
for _, te := range tenants {
|
||||
if te == nil {
|
||||
continue
|
||||
}
|
||||
tenantMap[te.ID] = te
|
||||
}
|
||||
|
||||
items := make([]*web_dto.MyTenantItem, 0, len(tenantUsers))
|
||||
for _, tu := range tenantUsers {
|
||||
if tu == nil {
|
||||
continue
|
||||
}
|
||||
te := tenantMap[tu.TenantID]
|
||||
if te == nil {
|
||||
continue
|
||||
}
|
||||
items = append(items, &web_dto.MyTenantItem{
|
||||
TenantID: te.ID,
|
||||
TenantCode: te.Code,
|
||||
TenantName: te.Name,
|
||||
TenantStatus: te.Status,
|
||||
TenantStatusDescription: te.Status.Description(),
|
||||
IsOwner: te.UserID == userID,
|
||||
MemberRoles: tu.Role,
|
||||
MemberStatus: tu.Status,
|
||||
JoinedAt: tu.CreatedAt,
|
||||
})
|
||||
}
|
||||
return items, nil
|
||||
}
|
||||
|
||||
// SuperDetail 查询单个租户详情(平台侧)。
|
||||
func (t *tenant) SuperDetail(ctx context.Context, tenantID int64) (*superdto.TenantItem, error) {
|
||||
if tenantID <= 0 {
|
||||
|
||||
Reference in New Issue
Block a user