sys_third_session.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. package eta
  2. import (
  3. "eta/eta_bridge/global"
  4. "time"
  5. )
  6. // SysThirdSession
  7. // @Description: 第三方登录会话session
  8. type SysThirdSession struct {
  9. ID uint64 `gorm:"primaryKey;column:id"`
  10. SysUserID uint64 `gorm:"column:sys_user_id"`
  11. UserName string `gorm:"column:user_name"`
  12. AccessToken string `gorm:"index:access_token;column:access_token"`
  13. ThirdAccessToken string `gorm:"index:third_access_token;column:third_access_token"`
  14. //ThirdRefreshToken string `gorm:"column:third_refresh_token"`
  15. ThirdExpiredTime time.Time `gorm:"column:third_expired_time"`
  16. CreatedTime time.Time `gorm:"index:created_time;column:created_time"`
  17. LastUpdatedTime time.Time `gorm:"index:last_updated_time;column:last_updated_time"`
  18. }
  19. func (m *SysThirdSession) TableName() string {
  20. return "sys_third_session"
  21. }
  22. // AddSysThirdSession 新增第三方的session
  23. func AddSysThirdSession(item *SysThirdSession) (err error) {
  24. err = global.MYSQL["hz_eta"].Create(item).Error
  25. return
  26. }
  27. // GetSysThirdSessionByToken 根据Token获取第三方session
  28. func GetSysThirdSessionByToken(token string) (item *SysThirdSession, err error) {
  29. err = global.MYSQL["hz_eta"].Where("access_token = ? AND expired_time > NOW()", token).Order("expired_time DESC").First(&item).Error
  30. return
  31. }