user.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package userinfo
  2. import (
  3. "time"
  4. "bet24.com/log"
  5. badge "bet24.com/servers/micros/badge/proto"
  6. "bet24.com/servers/micros/userservices/handler/vip"
  7. pb "bet24.com/servers/micros/userservices/proto"
  8. )
  9. type userInfo struct {
  10. pb.UserHotInfo
  11. tick int64
  12. }
  13. func (u *userInfo) isTimeout() bool {
  14. return time.Now().Unix()-u.tick >= 600
  15. }
  16. func (u *userInfo) dump() {
  17. log.Release(" UserId[%d],Idle[%d]", u.UserId, time.Now().Unix()-u.tick)
  18. log.Release(" Vip[%d],Decorations%v,Charm[%d]", u.Vip, u.Decorations, u.Charm)
  19. log.Release(" Switches:%v", u.Switches)
  20. }
  21. func newUserHotInfo(userId int) *userInfo {
  22. if userId <= 0 {
  23. return nil
  24. }
  25. u := newUserBaseInfo(userId)
  26. if u == nil {
  27. return nil
  28. }
  29. u.Decorations = getDecorationList(userId)
  30. u.Switches = getSwitchInfo(userId)
  31. uv := vip.GetUserVip(userId)
  32. if uv == nil {
  33. u.Vip = 0
  34. } else {
  35. u.Vip = uv.Level
  36. u.VipPoint = uv.Point
  37. u.VipExpire = uv.Expire
  38. }
  39. u.Badges = badge.GetBadgeWearAndShow(userId)
  40. u.tick = time.Now().Unix()
  41. return u
  42. }
  43. func (u *userInfo) updateTick() {
  44. u.tick = time.Now().Unix()
  45. }
  46. func newUserBaseInfo(userId int) *userInfo {
  47. if userId < 0 {
  48. return nil
  49. }
  50. u := trans_getInfo(userId)
  51. if u == nil {
  52. log.Error("user.newUserHotInfo userId=%d is not exist", userId)
  53. return nil
  54. }
  55. return u
  56. }