2025-04-30 15:46:14 +08:00
|
|
|
package model
|
|
|
|
|
|
|
|
import (
|
|
|
|
"admin/internal/db"
|
2025-05-16 15:17:10 +08:00
|
|
|
"admin/internal/model/dto"
|
2025-04-30 15:46:14 +08:00
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
db.RegisterTableModels(User{})
|
|
|
|
}
|
|
|
|
|
|
|
|
// User 用户表
|
|
|
|
type User struct {
|
|
|
|
ID int `gorm:"primarykey" readonly:"true"`
|
|
|
|
UserName string `name:"账号名" gorm:"type:varchar(255);unique" required:"true" uneditable:"true"`
|
|
|
|
NickName string `name:"昵称" gorm:"type:varchar(255);unique" required:"true"`
|
|
|
|
UserPass string `gorm:"type:varchar(255)" name:"密码" required:"true"` // 用户密码hash后的值
|
|
|
|
CharacterName string `gorm:"type:varchar(255);" name:"角色组" choices:"GetCharChoices"`
|
|
|
|
Status int `gorm:"type:int(1);default:0;" choices:"GetStatusChoices"`
|
|
|
|
CreatedAt time.Time `readonly:"true"`
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *User) TableName() string {
|
|
|
|
return "user"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *User) GetId() int {
|
|
|
|
return m.ID
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *User) GetStatusChoices() []*dto.CommonDtoFieldChoice {
|
|
|
|
return []*dto.CommonDtoFieldChoice{
|
|
|
|
{Desc: "正常", Value: 0},
|
|
|
|
{Desc: "停用", Value: 1},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (u *User) GetCharChoices() []*dto.CommonDtoFieldChoice {
|
|
|
|
choices := make([]*dto.CommonDtoFieldChoice, 0)
|
|
|
|
choices = append(choices, &dto.CommonDtoFieldChoice{
|
|
|
|
Desc: "空",
|
|
|
|
Value: "",
|
|
|
|
})
|
|
|
|
for _, v := range new(Character).List() {
|
|
|
|
choices = append(choices, &dto.CommonDtoFieldChoice{
|
|
|
|
Desc: v.Name,
|
|
|
|
Value: v.Name,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
return choices
|
|
|
|
}
|