update.go 806 B

12345678910111213141516171819202122232425262728293031
  1. package session
  2. import (
  3. "fmt"
  4. "time"
  5. )
  6. // Update 更新对应字段数据
  7. func (session *Session) Update(updateCols []string) (err error) {
  8. err = getDb().Model(session).Select(updateCols).Updates(*session).Error
  9. return
  10. }
  11. // UpdateSession 更新session
  12. func (session *Session) UpdateSession(userId int64, expireTime time.Time) (err error) {
  13. session.UserID = userId
  14. session.ExpireTime = expireTime
  15. var updateCols = []string{"UserID", "ExpireTime"}
  16. err = session.Update(updateCols)
  17. return
  18. }
  19. // ClearRepeatBindAccountToken 清除重复绑定账号的token
  20. func ClearRepeatBindAccountToken(openIds []string) (err error) {
  21. if len(openIds) == 0 {
  22. return
  23. }
  24. sql := fmt.Sprintf(` DELETE FROM session WHERE open_id IN ? AND expire_time >= NOW() `)
  25. err = getDb().Exec(sql, openIds).Error
  26. return
  27. }