role.go 792 B

12345678910111213141516171819202122232425262728
  1. package model
  2. import (
  3. "os"
  4. "time"
  5. "gorm.io/gorm"
  6. )
  7. type Role struct {
  8. ID int64 `gorm:"type:int(20);autoIncrement;comment:ID;" json:"id"`
  9. Name string `gorm:"type:varchar(255);comment:名称;" json:"account"`
  10. Permissions string `gorm:"type:text;comment:权限列表;nullable;" json:"permissions"`
  11. Users []User `gorm:"many2many:user_role;" json:"users"`
  12. DeletedAt gorm.DeletedAt `gorm:"column:deleted_at" json:"-"`
  13. CreatedAt time.Time `gorm:"column:created_at" json:"createdAt"`
  14. UpdatedAt time.Time `gorm:"column:updated_at" json:"updatedAt"`
  15. }
  16. func (u *Role) AfterFind(tx *gorm.DB) (err error) {
  17. return
  18. }
  19. func (u *Role) TableName() string {
  20. dbPrefix := os.Getenv("DB_PREFIX")
  21. return dbPrefix + "role"
  22. }