feat: 添加订单详情和退款功能,更新用户角色管理,增强超级管理员鉴权

This commit is contained in:
2025-12-24 09:48:31 +08:00
parent fcbc6bd394
commit 1e1132718c
17 changed files with 586 additions and 6 deletions

View File

@@ -276,6 +276,35 @@ func (t *user) UpdateStatus(ctx context.Context, userID int64, status consts.Use
return nil
}
// UpdateRoles 更新用户角色(超级管理员侧)。
func (t *user) UpdateRoles(ctx context.Context, userID int64, roles []consts.Role) error {
if userID <= 0 {
return errors.New("user_id must be > 0")
}
roles = lo.Uniq(lo.Filter(roles, func(r consts.Role, _ int) bool {
return r != ""
}))
if len(roles) == 0 {
return errors.New("roles is empty")
}
// 约定:系统用户至少包含 user 角色。
if !lo.Contains(roles, consts.RoleUser) {
roles = append(roles, consts.RoleUser)
}
roles = lo.Uniq(roles)
m, err := t.FindByID(ctx, userID)
if err != nil {
return err
}
m.Roles = types.NewArray(roles)
_, err = m.Update(ctx)
return err
}
// Statistics 按状态统计用户数量(超级管理员侧)。
func (t *user) Statistics(ctx context.Context) ([]*dto.UserStatistics, error) {
tbl, query := models.UserQuery.QueryContext(ctx)