2934b1d0bc
- 移除预检查算力点步骤,改为请求前预扣算力点 - 添加请求失败时自动返还算力点的功能 - 修改copyAIResponse函数参数以支持失败回调处理 - 在响应状态异常时也执行算力点返还操作 - 从auth服务中移除EnsureUserCredits方法 - 新增RefundUserCredits方法用于返还用户算力点 - 添加AI_REFUND算力点日志类型常量 - 更新算力点日志类型说明及展示标签
103 lines
2.8 KiB
Go
103 lines
2.8 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"
|
|
CreditLogTypeAIConsume CreditLogType = "ai_consume"
|
|
CreditLogTypeAIRefund CreditLogType = "ai_refund"
|
|
)
|
|
|
|
// 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"`
|
|
}
|