user.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package model
  2. import (
  3. "os"
  4. "time"
  5. "gorm.io/gorm"
  6. )
  7. const (
  8. UserStatusEnable = 1 // 用户状态正常
  9. UserStatusDisable = 2 // 用户状态禁用
  10. UserIsSuperTrue = 1 // 用户是超级管理员
  11. UserIsSuperFalse = 2 // 用户不是超级管理员
  12. )
  13. type User struct {
  14. ID int64 `gorm:"type:int(20);autoIncrement;comment:ID;" json:"id"`
  15. Account string `gorm:"type:varchar(255);comment:账号;" json:"account"`
  16. Password string `gorm:"type:varchar(255);comment:密码;" json:"password"`
  17. Nickname string `gorm:"type:varchar(255);comment:昵称;default:'';" json:"nickname"`
  18. Status int `gorm:"type:int(1);comment:状态;default:2;" json:"status"`
  19. IsSuper int `gorm:"type:int(1);comment:是否超级管理员;default:2;" json:"isSuper"`
  20. Remark string `gorm:"type:varchar(255);comment:备注;default:'';" json:"remark"`
  21. Roles []Role `gorm:"many2many:user_role;" json:"roles"`
  22. DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"`
  23. CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
  24. UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
  25. }
  26. func (u *User) AfterFind(tx *gorm.DB) (err error) {
  27. return
  28. }
  29. func (u *User) TableName() string {
  30. dbPrefix := os.Getenv("DB_PREFIX")
  31. return dbPrefix + "user"
  32. }