Files
infinite-canvas/model/user.go
T
HouYunFei fff7074218 feat(admin): 添加管理员用户算力点管理和日志功能
- 在管理员API中新增用户算力点调整功能和信用日志相关接口
- 实现后端用户算力点调整逻辑和信用日志的增删改查操作
- 在管理员界面用户管理页面添加算力点调整功能
- 新增独立的算力点日志管理页面,支持日志查看和编辑
- 添加算力点日志相关的数据模型和服务函数
- 更新数据库文档说明第三方资料存储结构
- 添加dayjs依赖用于时间格式化显示
2026-05-25 12:57:27 +08:00

101 lines
2.7 KiB
Go

package model
type UserRole string
const (
UserRoleGuest UserRole = "guest"
UserRoleUser UserRole = "user"
UserRoleAdmin UserRole = "admin"
)
type UserStatus string
const (
UserStatusActive UserStatus = "active"
UserStatusBan UserStatus = "ban"
)
// User 系统用户。
type User struct {
ID string `json:"id" gorm:"primaryKey"`
Username string `json:"username" gorm:"uniqueIndex"`
Password string `json:"password,omitempty"`
Email string `json:"email"`
DisplayName string `json:"displayName"`
AvatarURL string `json:"avatarUrl"`
Role UserRole `json:"role"`
Credits int `json:"credits"`
AffCode string `json:"affCode" gorm:"uniqueIndex"`
AffCount int `json:"affCount"`
InviterID string `json:"inviterId"`
GithubID string `json:"githubId"`
LinuxDoID string `json:"linuxDoId" gorm:"index"`
WechatID string `json:"wechatId"`
Status UserStatus `json:"status"`
LastLoginAt string `json:"lastLoginAt"`
Extra string `json:"extra" gorm:"type:text"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// UserList 用户分页结果。
type UserList struct {
Items []User `json:"items"`
Total int `json:"total"`
}
// AuthUser 用户公开信息。
type AuthUser struct {
ID string `json:"id"`
Username string `json:"username"`
DisplayName string `json:"displayName"`
AvatarURL string `json:"avatarUrl"`
Role UserRole `json:"role"`
Credits int `json:"credits"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
// AuthSession 登录会话信息。
type AuthSession struct {
Token string `json:"token"`
User AuthUser `json:"user"`
}
func PublicUser(user User) AuthUser {
return AuthUser{
ID: user.ID,
Username: user.Username,
DisplayName: user.DisplayName,
AvatarURL: user.AvatarURL,
Role: user.Role,
Credits: user.Credits,
CreatedAt: user.CreatedAt,
UpdatedAt: user.UpdatedAt,
}
}
type CreditLogType string
const (
CreditLogTypeAdminAdjust CreditLogType = "admin_adjust"
)
// CreditLog 用户算力点变更流水。
type CreditLog struct {
ID string `json:"id" gorm:"primaryKey"`
UserID string `json:"userId" gorm:"index"`
Type CreditLogType `json:"type"`
Amount int `json:"amount"`
Balance int `json:"balance"`
RelatedID string `json:"relatedId"`
Remark string `json:"remark"`
Extra string `json:"extra" gorm:"type:text"`
CreatedAt string `json:"createdAt"`
}
type CreditLogList struct {
Items []CreditLog `json:"items"`
Total int `json:"total"`
}