english_yb_session.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package session
  2. import (
  3. "hongze/hongze_yb_en_api/global"
  4. "time"
  5. )
  6. type EnglishYbSession struct {
  7. SessionId int `gorm:"primaryKey;column:session_id" json:"session_id"`
  8. UserId int `gorm:"column:user_id" json:"user_id"`
  9. AccessToken string `gorm:"column:access_token" json:"access_token"`
  10. ExpireTime time.Time
  11. CreatedTime time.Time
  12. LastUpdatedTime time.Time
  13. }
  14. type EnglishYbSessionItem struct {
  15. SessionId int `gorm:"primaryKey;column:session_id" json:"session_id"`
  16. UserId int `gorm:"column:user_id" json:"user_id"`
  17. AccessToken string `gorm:"column:access_token" json:"access_token"`
  18. ExpireTime string
  19. CreatedTime string
  20. LastUpdatedTime string
  21. }
  22. // TableName get sql table name.获取数据库表名
  23. func (e *EnglishYbSession) TableName() string {
  24. return "english_yb_session"
  25. }
  26. // 新增用户登录session信息
  27. func (e *EnglishYbSession) AddSession() (err error) {
  28. err = global.MYSQL["rddp"].Create(e).Error
  29. return
  30. }
  31. func GetSessionByUserId(userId int) (item *EnglishYbSession, err error) {
  32. sql := `SELECT * FROM english_yb_session WHERE user_id=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 `
  33. err = global.MYSQL["rddp"].Exec(sql, userId).Error
  34. return
  35. }
  36. func GetSessionByToken(token string) (item *EnglishYbSession, err error) {
  37. sql := `SELECT * FROM english_yb_session WHERE access_token=? AND expired_time> NOW() ORDER BY expired_time DESC LIMIT 1 `
  38. err = global.MYSQL["rddp"].Exec(sql, token).Error
  39. return
  40. }
  41. type LoginResp struct {
  42. Mobile string
  43. Email string
  44. CountryCode string `description:"区号"`
  45. Name string `description:"客户名称"`
  46. *EnglishYbSession
  47. }