table_admin.go 825 B

12345678910111213141516171819202122232425262728293031323334
  1. package models
  2. import "passport/client/mysql"
  3. type TAdmin struct {
  4. UserId string `gorm:"column:user_id;type:varchar(20)"`
  5. Phone string `gorm:"column:phone;type:varchar(20)"`
  6. Password string `gorm:"column:password;type:varchar(64)"`
  7. Role int `gorm:"column:role"`
  8. CommonField
  9. }
  10. func (t *TAdmin) TableName() string {
  11. return "admin"
  12. }
  13. func (t *TAdmin) Show() (*TAdmin, error) {
  14. db := mysql.Client.Slave()
  15. var result = new(TAdmin)
  16. err := db.Table("admin").Where("user_id = ?", t.UserId).Scan(&result).Error
  17. if err != nil {
  18. return nil, err
  19. }
  20. return result, nil
  21. }
  22. func (t *TAdmin) ShowByPhone() (*TAdmin, error) {
  23. db := mysql.Client.Slave()
  24. var result = new(TAdmin)
  25. err := db.Table("admin").Where("phone = ?", t.Phone).Scan(&result).Error
  26. if err != nil {
  27. return nil, err
  28. }
  29. return result, nil
  30. }