package model import ( "admin/apps/user/model/dto" "admin/internal/db" "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 }