66 lines
2.5 KiB
Go
66 lines
2.5 KiB
Go
package models
|
||
|
||
import (
|
||
"time"
|
||
|
||
"gorm.io/gorm"
|
||
)
|
||
|
||
// InviteCode 简化版邀请码模型
|
||
type InviteCode struct {
|
||
ID uint `json:"id" gorm:"primaryKey;autoIncrement;comment:主键ID"`
|
||
Code string `json:"code" gorm:"not null;type:varchar(64);uniqueIndex;comment:邀请码"`
|
||
IsUsed bool `json:"is_used" gorm:"not null;default:0;type:tinyint(1);comment:是否已使用"`
|
||
ClientID string `json:"client_id" gorm:"type:varchar(64);comment:客户端ID"`
|
||
Email string `json:"email" gorm:"type:varchar(255);comment:关联邮箱"`
|
||
UserLevelID *uint `json:"user_level_id" gorm:"type:BIGINT;comment:用户等级ID"`
|
||
ExpiresAt *time.Time `json:"expires_at" gorm:"comment:过期时间"`
|
||
CreatedAt time.Time `json:"created_at" gorm:"not null;comment:创建时间"`
|
||
DeletedAt gorm.DeletedAt `json:"-" gorm:"index;comment:软删除时间"`
|
||
}
|
||
|
||
// TableName 指定数据库表名
|
||
func (InviteCode) TableName() string {
|
||
return "admin_invite_codes"
|
||
}
|
||
|
||
// 列表请求(简化)
|
||
type InviteCodeListRequest struct {
|
||
Code string `form:"code"`
|
||
IsUsed *bool `form:"is_used"`
|
||
StartTime string `form:"start_time"`
|
||
EndTime string `form:"end_time"`
|
||
Page int `form:"page,default=1"`
|
||
Size int `form:"size,default=20"`
|
||
}
|
||
|
||
// 创建请求(支持设置过期时间)
|
||
type InviteCodeCreateRequest struct {
|
||
Emails []string `json:"emails" form:"emails"` // 邮箱列表,可选
|
||
UserLevelID *uint `json:"user_level_id" form:"user_level_id"` // 用户等级ID,可选
|
||
ExpiresAt *time.Time `json:"expires_at" form:"expires_at"` // 过期时间,可选
|
||
ClientID string `json:"client_id" form:"client_id"` // 客户端ID,可选(保留向后兼容)
|
||
}
|
||
|
||
// 更新请求(支持更新过期时间)
|
||
type InviteCodeUpdateRequest struct {
|
||
ClientID string `json:"client_id" form:"client_id"` // 客户端ID,可选
|
||
Email string `json:"email" form:"email"` // 邮箱,可选
|
||
UserLevelID *uint `json:"user_level_id" form:"user_level_id"` // 用户等级ID,可选
|
||
ExpiresAt *time.Time `json:"expires_at" form:"expires_at"` // 过期时间,可选
|
||
}
|
||
|
||
// 统计响应(简化,可选)
|
||
type InviteCodeStatistics struct {
|
||
Total int `json:"total"`
|
||
Used int `json:"used"`
|
||
Unused int `json:"unused"`
|
||
TodayCreated int `json:"today_created"`
|
||
}
|
||
|
||
// 列表响应
|
||
type InviteCodeListResponse struct {
|
||
List []InviteCode `json:"list"`
|
||
Total int64 `json:"total"`
|
||
}
|