package session import ( "hongze/hongze_yb_en_api/global" "time" ) type EnglishYbSession struct { SessionId int `gorm:"primaryKey;column:session_id" json:"session_id"` UserId int `gorm:"column:user_id" json:"user_id"` AccessToken string `gorm:"column:access_token" json:"access_token"` ExpireTime time.Time CreatedTime time.Time LastUpdatedTime time.Time } type EnglishYbSessionItem struct { SessionId int `gorm:"primaryKey;column:session_id" json:"session_id"` UserId int `gorm:"column:user_id" json:"user_id"` AccessToken string `gorm:"column:access_token" json:"access_token"` ExpireTime string CreatedTime string LastUpdatedTime string } // TableName get sql table name.获取数据库表名 func (e *EnglishYbSession) TableName() string { return "english_yb_session" } // 新增用户登录session信息 func (e *EnglishYbSession) AddSession() (err error) { err = global.MYSQL["rddp"].Create(e).Error return } func GetSessionByUserId(userId int) (item *EnglishYbSession, err error) { sql := `SELECT * FROM english_yb_session WHERE user_id=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 ` err = global.MYSQL["rddp"].Exec(sql, userId).Error return } func GetSessionByToken(token string) (item *EnglishYbSession, err error) { sql := `SELECT * FROM english_yb_session WHERE access_token=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 ` err = global.MYSQL["rddp"].Exec(sql, token).Error return } type LoginResp struct { Mobile string Email string CountryCode string `description:"区号"` Name string `description:"客户名称"` *EnglishYbSession }