stat.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package model
  2. import "go-common/app/service/main/archive/api"
  3. // is
  4. const (
  5. TypeForView = "view"
  6. TypeForDm = "dm"
  7. TypeForReply = "reply"
  8. TypeForFav = "fav"
  9. TypeForCoin = "coin"
  10. TypeForShare = "share"
  11. TypeForRank = "rank"
  12. TypeForLike = "like"
  13. )
  14. // StatMsg stat info.
  15. type StatMsg struct {
  16. Aid int64 `json:"aid"`
  17. Click int32 `json:"click"`
  18. DM int32 `json:"dm"`
  19. Reply int32 `json:"reply"`
  20. Fav int32 `json:"fav"`
  21. Coin int32 `json:"coin"`
  22. Share int32 `json:"share"`
  23. NowRank int32 `json:"now_rank"`
  24. HisRank int32 `json:"his_rank"`
  25. Like int32 `json:"like"`
  26. Type string `json:"-"`
  27. Ts int64 `json:"-"`
  28. }
  29. // StatCount is
  30. type StatCount struct {
  31. Type string `json:"type"`
  32. Aid int64 `json:"id"`
  33. Count int32 `json:"count"`
  34. TimeStamp int64 `json:"timestamp"`
  35. }
  36. // Merge merge message and stat from db.
  37. func Merge(m *StatMsg, s *api.Stat) {
  38. if m.Click >= 0 && m.Type == TypeForView {
  39. s.View = m.Click
  40. }
  41. if m.Coin >= 0 && m.Type == TypeForCoin {
  42. s.Coin = m.Coin
  43. }
  44. if m.DM >= 0 && m.Type == TypeForDm {
  45. s.Danmaku = m.DM
  46. }
  47. if m.Fav >= 0 && m.Type == TypeForFav {
  48. s.Fav = m.Fav
  49. }
  50. if m.Reply >= 0 && m.Type == TypeForReply {
  51. s.Reply = m.Reply
  52. }
  53. if m.Share >= 0 && m.Type == TypeForShare && m.Share > s.Share {
  54. s.Share = m.Share
  55. }
  56. if m.NowRank >= 0 && m.Type == TypeForRank {
  57. s.NowRank = m.NowRank
  58. }
  59. if m.HisRank >= 0 && m.Type == TypeForRank {
  60. s.HisRank = m.HisRank
  61. }
  62. if m.Like >= 0 && m.Type == TypeForLike {
  63. s.Like = m.Like
  64. }
  65. }