package models import "shopperthree_manage_v2/client/mysql" type TAdmin struct { UserId string `gorm:"column:user_id;type:varchar(20)"` Phone string `gorm:"column:phone;type:varchar(20)"` Password string `gorm:"column:password;type:varchar(64)"` Role int `gorm:"column:role"` CommonField } func (t *TAdmin) TableName() string { return "admin" } func (t *TAdmin) Show() (*TAdmin, error) { db := mysql.Client.Slave() var result = new(TAdmin) err := db.Table("admin").Where("user_id = ?", t.UserId).Scan(&result).Error if err != nil { return nil, err } return result, nil } func (t *TAdmin) ShowByPhone() (*TAdmin, error) { db := mysql.Client.Slave() var result = new(TAdmin) err := db.Table("admin").Where("phone = ?", t.Phone).Scan(&result).Error if err != nil { return nil, err } return result, nil }