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:
@@ -5,6 +5,7 @@ import (
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
@@ -28,6 +29,45 @@ func requireTenantAdmin(tenantUser *models.TenantUser) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// list
|
||||
//
|
||||
// @Summary 内容列表(租户管理)
|
||||
// @Tags Tenant
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param tenantCode path string true "Tenant Code"
|
||||
// @Param filter query dto.AdminContentListFilter true "Filter"
|
||||
// @Success 200 {object} requests.Pager{items=dto.AdminContentItem}
|
||||
//
|
||||
// @Router /t/:tenantCode/v1/admin/contents [get]
|
||||
// @Bind tenant local key(tenant)
|
||||
// @Bind tenantUser local key(tenant_user)
|
||||
// @Bind filter query
|
||||
func (*contentAdmin) list(ctx fiber.Ctx, tenant *models.Tenant, tenantUser *models.TenantUser, filter *dto.AdminContentListFilter) (*requests.Pager, error) {
|
||||
if err := requireTenantAdmin(tenantUser); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if filter == nil {
|
||||
filter = &dto.AdminContentListFilter{}
|
||||
}
|
||||
filter.Pagination.Format()
|
||||
|
||||
log.WithFields(log.Fields{
|
||||
"tenant_id": tenant.ID,
|
||||
"user_id": tenantUser.UserID,
|
||||
"query_user_id": filter.UserID,
|
||||
"keyword": filter.KeywordTrimmed(),
|
||||
"status": filter.Status,
|
||||
"visibility": filter.Visibility,
|
||||
"published_at_from": filter.PublishedAtFrom,
|
||||
"published_at_to": filter.PublishedAtTo,
|
||||
"created_at_from": filter.CreatedAtFrom,
|
||||
"created_at_to": filter.CreatedAtTo,
|
||||
}).Info("tenant.admin.contents.list")
|
||||
|
||||
return services.Content.AdminContentPage(ctx.Context(), tenant.ID, filter)
|
||||
}
|
||||
|
||||
// create
|
||||
//
|
||||
// @Summary 创建内容(草稿)
|
||||
|
||||
56
backend/app/http/tenant/dto/content_admin_list.go
Normal file
56
backend/app/http/tenant/dto/content_admin_list.go
Normal file
@@ -0,0 +1,56 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/requests"
|
||||
"quyun/v2/database/models"
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
// AdminContentListFilter 租户管理员查询“内容列表(含草稿/已发布/已下架等)”的过滤条件。
|
||||
type AdminContentListFilter struct {
|
||||
requests.Pagination `json:",inline" query:",inline"`
|
||||
requests.SortQueryFilter `json:",inline" query:",inline"`
|
||||
|
||||
ID *int64 `json:"id,omitempty" query:"id"`
|
||||
|
||||
UserID *int64 `json:"user_id,omitempty" query:"user_id"`
|
||||
|
||||
Keyword *string `json:"keyword,omitempty" query:"keyword"`
|
||||
|
||||
Status *consts.ContentStatus `json:"status,omitempty" query:"status"`
|
||||
Visibility *consts.ContentVisibility `json:"visibility,omitempty" query:"visibility"`
|
||||
|
||||
PublishedAtFrom *time.Time `json:"published_at_from,omitempty" query:"published_at_from"`
|
||||
PublishedAtTo *time.Time `json:"published_at_to,omitempty" query:"published_at_to"`
|
||||
|
||||
CreatedAtFrom *time.Time `json:"created_at_from,omitempty" query:"created_at_from"`
|
||||
CreatedAtTo *time.Time `json:"created_at_to,omitempty" query:"created_at_to"`
|
||||
}
|
||||
|
||||
func (f *AdminContentListFilter) KeywordTrimmed() string {
|
||||
if f == nil || f.Keyword == nil {
|
||||
return ""
|
||||
}
|
||||
return strings.TrimSpace(*f.Keyword)
|
||||
}
|
||||
|
||||
type AdminContentOwnerLite struct {
|
||||
ID int64 `json:"id"`
|
||||
Username string `json:"username"`
|
||||
Status consts.UserStatus `json:"status"`
|
||||
Roles types.Array[consts.Role] `json:"roles"`
|
||||
}
|
||||
|
||||
type AdminContentItem struct {
|
||||
Content *models.Content `json:"content,omitempty"`
|
||||
Price *models.ContentPrice `json:"price,omitempty"`
|
||||
Owner *AdminContentOwnerLite `json:"owner,omitempty"`
|
||||
|
||||
StatusDescription string `json:"status_description,omitempty"`
|
||||
VisibilityDescription string `json:"visibility_description,omitempty"`
|
||||
}
|
||||
@@ -82,6 +82,13 @@ func (r *Routes) Register(router fiber.Router) {
|
||||
PathParam[int64]("contentID"),
|
||||
))
|
||||
// Register routes for controller: contentAdmin
|
||||
r.log.Debugf("Registering route: Get /t/:tenantCode/v1/admin/contents -> contentAdmin.list")
|
||||
router.Get("/t/:tenantCode/v1/admin/contents"[len(r.Path()):], DataFunc3(
|
||||
r.contentAdmin.list,
|
||||
Local[*models.Tenant]("tenant"),
|
||||
Local[*models.TenantUser]("tenant_user"),
|
||||
Query[dto.AdminContentListFilter]("filter"),
|
||||
))
|
||||
r.log.Debugf("Registering route: Patch /t/:tenantCode/v1/admin/contents/:contentID -> contentAdmin.update")
|
||||
router.Patch("/t/:tenantCode/v1/admin/contents/:contentID"[len(r.Path()):], DataFunc4(
|
||||
r.contentAdmin.update,
|
||||
|
||||
69
backend/app/http/web/auth.go
Normal file
69
backend/app/http/web/auth.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/web/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type auth struct {
|
||||
jwt *jwt.JWT
|
||||
}
|
||||
|
||||
// Login 用户登录(平台侧,非超级管理员)。
|
||||
//
|
||||
// @Summary 用户登录
|
||||
// @Tags Web
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param form body dto.LoginForm true "form"
|
||||
// @Success 200 {object} dto.LoginResponse "成功"
|
||||
// @Router /v1/auth/login [post]
|
||||
// @Bind form body
|
||||
func (ctl *auth) login(ctx fiber.Ctx, form *dto.LoginForm) (*dto.LoginResponse, error) {
|
||||
m, err := services.User.FindByUsername(ctx, form.Username)
|
||||
if err != nil {
|
||||
return nil, errorx.Wrap(err).WithMsg("用户名或密码错误")
|
||||
}
|
||||
if ok := m.ComparePassword(ctx, form.Password); !ok {
|
||||
return nil, errorx.Wrap(errorx.ErrInvalidCredentials).WithMsg("用户名或密码错误")
|
||||
}
|
||||
|
||||
token, err := ctl.jwt.CreateToken(ctl.jwt.CreateClaims(jwt.BaseClaims{
|
||||
UserID: m.ID,
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, errorx.Wrap(err).WithMsg("登录凭证生成失败")
|
||||
}
|
||||
|
||||
return &dto.LoginResponse{Token: token}, nil
|
||||
}
|
||||
|
||||
// Token 刷新登录凭证。
|
||||
//
|
||||
// @Summary 刷新 Token
|
||||
// @Tags Web
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.LoginResponse "成功"
|
||||
// @Router /v1/auth/token [get]
|
||||
func (ctl *auth) token(ctx fiber.Ctx) (*dto.LoginResponse, error) {
|
||||
claims, ok := ctx.Locals(consts.CtxKeyClaims).(*jwt.Claims)
|
||||
if !ok || claims == nil || claims.UserID <= 0 {
|
||||
return nil, errorx.ErrTokenInvalid
|
||||
}
|
||||
|
||||
token, err := ctl.jwt.CreateToken(ctl.jwt.CreateClaims(jwt.BaseClaims{
|
||||
UserID: claims.UserID,
|
||||
}))
|
||||
if err != nil {
|
||||
return nil, errorx.Wrap(err).WithMsg("登录凭证生成失败")
|
||||
}
|
||||
|
||||
return &dto.LoginResponse{Token: token}, nil
|
||||
}
|
||||
16
backend/app/http/web/dto/auth.go
Normal file
16
backend/app/http/web/dto/auth.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package dto
|
||||
|
||||
// LoginForm 平台侧用户登录表单(用于获取 JWT 访问凭证)。
|
||||
// 注意:此登录是“用户身份”登录(非超级管理员),用于进入租户管理后台前的身份校验与租户列表查询。
|
||||
type LoginForm struct {
|
||||
// Username 用户名;必须与数据库 users.username 精确匹配。
|
||||
Username string `json:"username,omitempty"`
|
||||
// Password 明文密码;后端会与 users.password 的 bcrypt hash 做比对。
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
// LoginResponse 登录响应。
|
||||
type LoginResponse struct {
|
||||
// Token JWT 访问令牌;前端应以 `Authorization: Bearer <token>` 方式携带。
|
||||
Token string `json:"token"`
|
||||
}
|
||||
51
backend/app/http/web/dto/me.go
Normal file
51
backend/app/http/web/dto/me.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"quyun/v2/pkg/consts"
|
||||
|
||||
"go.ipao.vip/gen/types"
|
||||
)
|
||||
|
||||
// MeResponse 当前登录用户信息(脱敏)。
|
||||
type MeResponse struct {
|
||||
// ID 用户ID(全局唯一)。
|
||||
ID int64 `json:"id"`
|
||||
// Username 用户名。
|
||||
Username string `json:"username"`
|
||||
// Roles 用户全局角色数组(如 user/super_admin 等)。
|
||||
Roles types.Array[consts.Role] `json:"roles"`
|
||||
// Status 用户状态(active/verified/banned 等)。
|
||||
Status consts.UserStatus `json:"status"`
|
||||
// StatusDescription 用户状态描述(便于前端展示)。
|
||||
StatusDescription string `json:"status_description"`
|
||||
// CreatedAt 用户创建时间。
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
// UpdatedAt 用户更新时间。
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
}
|
||||
|
||||
// MyTenantItem 当前用户可进入的租户条目(用于“选择租户进入后台”页面)。
|
||||
type MyTenantItem struct {
|
||||
// TenantID 租户ID(数值型主键)。
|
||||
TenantID int64 `json:"tenant_id"`
|
||||
// TenantCode 租户Code(路由使用:/t/:tenantCode/...)。
|
||||
TenantCode string `json:"tenant_code"`
|
||||
// TenantName 租户名称。
|
||||
TenantName string `json:"tenant_name"`
|
||||
// TenantStatus 租户状态(pending/verified/expired 等)。
|
||||
TenantStatus consts.TenantStatus `json:"tenant_status"`
|
||||
// TenantStatusDescription 租户状态描述(便于前端展示)。
|
||||
TenantStatusDescription string `json:"tenant_status_description"`
|
||||
|
||||
// IsOwner 是否为租户Owner(tenants.user_id == 当前用户)。
|
||||
// 说明:Owner 通常也在 tenant_users 里具备 tenant_admin 角色,但此字段更直观。
|
||||
IsOwner bool `json:"is_owner"`
|
||||
// MemberRoles 当前用户在该租户下的角色(tenant_admin/member 等)。
|
||||
MemberRoles types.Array[consts.TenantUserRole] `json:"member_roles"`
|
||||
// MemberStatus 当前用户在该租户下的成员状态。
|
||||
MemberStatus consts.UserStatus `json:"member_status"`
|
||||
// JoinedAt 加入租户时间(tenant_users.created_at)。
|
||||
JoinedAt time.Time `json:"joined_at"`
|
||||
}
|
||||
61
backend/app/http/web/me.go
Normal file
61
backend/app/http/web/me.go
Normal file
@@ -0,0 +1,61 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/web/dto"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/pkg/consts"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
)
|
||||
|
||||
// @provider
|
||||
type me struct{}
|
||||
|
||||
// Me 获取当前登录用户信息(脱敏)。
|
||||
//
|
||||
// @Summary 当前用户信息
|
||||
// @Tags Web
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {object} dto.MeResponse "成功"
|
||||
// @Router /v1/me [get]
|
||||
func (ctl *me) me(ctx fiber.Ctx) (*dto.MeResponse, error) {
|
||||
claims, ok := ctx.Locals(consts.CtxKeyClaims).(*jwt.Claims)
|
||||
if !ok || claims == nil || claims.UserID <= 0 {
|
||||
return nil, errorx.ErrTokenInvalid
|
||||
}
|
||||
|
||||
m, err := services.User.FindByID(ctx, claims.UserID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &dto.MeResponse{
|
||||
ID: m.ID,
|
||||
Username: m.Username,
|
||||
Roles: m.Roles,
|
||||
Status: m.Status,
|
||||
StatusDescription: m.Status.Description(),
|
||||
CreatedAt: m.CreatedAt,
|
||||
UpdatedAt: m.UpdatedAt,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// MyTenants 获取当前用户可进入的租户列表。
|
||||
//
|
||||
// @Summary 我的租户列表
|
||||
// @Tags Web
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 200 {array} dto.MyTenantItem "成功"
|
||||
// @Router /v1/me/tenants [get]
|
||||
func (ctl *me) myTenants(ctx fiber.Ctx) ([]*dto.MyTenantItem, error) {
|
||||
claims, ok := ctx.Locals(consts.CtxKeyClaims).(*jwt.Claims)
|
||||
if !ok || claims == nil || claims.UserID <= 0 {
|
||||
return nil, errorx.ErrTokenInvalid
|
||||
}
|
||||
|
||||
return services.Tenant.UserTenants(ctx, claims.UserID)
|
||||
}
|
||||
51
backend/app/http/web/provider.gen.go
Executable file
51
backend/app/http/web/provider.gen.go
Executable file
@@ -0,0 +1,51 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"quyun/v2/app/middlewares"
|
||||
"quyun/v2/providers/jwt"
|
||||
|
||||
"go.ipao.vip/atom"
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
"go.ipao.vip/atom/opt"
|
||||
)
|
||||
|
||||
func Provide(opts ...opt.Option) error {
|
||||
if err := container.Container.Provide(func(
|
||||
jwt *jwt.JWT,
|
||||
) (*auth, error) {
|
||||
obj := &auth{
|
||||
jwt: jwt,
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func() (*me, error) {
|
||||
obj := &me{}
|
||||
|
||||
return obj, nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := container.Container.Provide(func(
|
||||
auth *auth,
|
||||
me *me,
|
||||
middlewares *middlewares.Middlewares,
|
||||
) (contracts.HttpRoute, error) {
|
||||
obj := &Routes{
|
||||
auth: auth,
|
||||
me: me,
|
||||
middlewares: middlewares,
|
||||
}
|
||||
if err := obj.Prepare(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return obj, nil
|
||||
}, atom.GroupRoutes); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
66
backend/app/http/web/routes.gen.go
Normal file
66
backend/app/http/web/routes.gen.go
Normal file
@@ -0,0 +1,66 @@
|
||||
// Code generated by atomctl. DO NOT EDIT.
|
||||
|
||||
// Package web provides HTTP route definitions and registration
|
||||
// for the quyun/v2 application.
|
||||
package web
|
||||
|
||||
import (
|
||||
"quyun/v2/app/http/web/dto"
|
||||
"quyun/v2/app/middlewares"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
log "github.com/sirupsen/logrus"
|
||||
_ "go.ipao.vip/atom"
|
||||
_ "go.ipao.vip/atom/contracts"
|
||||
. "go.ipao.vip/atom/fen"
|
||||
)
|
||||
|
||||
// Routes implements the HttpRoute contract and provides route registration
|
||||
// for all controllers in the web module.
|
||||
//
|
||||
// @provider contracts.HttpRoute atom.GroupRoutes
|
||||
type Routes struct {
|
||||
log *log.Entry `inject:"false"`
|
||||
middlewares *middlewares.Middlewares
|
||||
// Controller instances
|
||||
auth *auth
|
||||
me *me
|
||||
}
|
||||
|
||||
// Prepare initializes the routes provider with logging configuration.
|
||||
func (r *Routes) Prepare() error {
|
||||
r.log = log.WithField("module", "routes.web")
|
||||
r.log.Info("Initializing routes module")
|
||||
return nil
|
||||
}
|
||||
|
||||
// Name returns the unique identifier for this routes provider.
|
||||
func (r *Routes) Name() string {
|
||||
return "web"
|
||||
}
|
||||
|
||||
// Register registers all HTTP routes with the provided fiber router.
|
||||
// Each route is registered with its corresponding controller action and parameter bindings.
|
||||
func (r *Routes) Register(router fiber.Router) {
|
||||
// Register routes for controller: auth
|
||||
r.log.Debugf("Registering route: Get /v1/auth/token -> auth.token")
|
||||
router.Get("/v1/auth/token"[len(r.Path()):], DataFunc0(
|
||||
r.auth.token,
|
||||
))
|
||||
r.log.Debugf("Registering route: Post /v1/auth/login -> auth.login")
|
||||
router.Post("/v1/auth/login"[len(r.Path()):], DataFunc1(
|
||||
r.auth.login,
|
||||
Body[dto.LoginForm]("form"),
|
||||
))
|
||||
// Register routes for controller: me
|
||||
r.log.Debugf("Registering route: Get /v1/me -> me.me")
|
||||
router.Get("/v1/me"[len(r.Path()):], DataFunc0(
|
||||
r.me.me,
|
||||
))
|
||||
r.log.Debugf("Registering route: Get /v1/me/tenants -> me.myTenants")
|
||||
router.Get("/v1/me/tenants"[len(r.Path()):], DataFunc0(
|
||||
r.me.myTenants,
|
||||
))
|
||||
|
||||
r.log.Info("Successfully registered all routes")
|
||||
}
|
||||
11
backend/app/http/web/routes.manual.go
Normal file
11
backend/app/http/web/routes.manual.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package web
|
||||
|
||||
func (r *Routes) Path() string {
|
||||
return "/v1"
|
||||
}
|
||||
|
||||
func (r *Routes) Middlewares() []any {
|
||||
return []any{
|
||||
r.middlewares.UserAuth,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user