growup.go 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package growup
  2. import (
  3. "context"
  4. "go-common/app/interface/main/creative/model/growup"
  5. "go-common/library/log"
  6. "time"
  7. )
  8. // UpStatus get up status. 前提:必须当前用户线上有可以观看的视频(0/-6) TODO deprecated
  9. func (s *Service) UpStatus(c context.Context, mid int64, ip string) (us *growup.UpStatus, err error) {
  10. if us, err = s.growup.UpStatus(c, mid, ip); err != nil {
  11. log.Error("s.growup.UpStatus(%d) error(%v)", mid, err)
  12. return
  13. }
  14. return
  15. }
  16. // UpInfo get up info.
  17. func (s *Service) UpInfo(c context.Context, mid int64, ip string) (ui *growup.UpInfo, err error) {
  18. if ui, err = s.growup.UpInfo(c, mid, ip); err != nil {
  19. log.Error("s.growup.UpInfo(%d) error(%v)", mid, err)
  20. }
  21. return
  22. }
  23. // Join join growup.
  24. func (s *Service) Join(c context.Context, mid int64, accTy, signTy int, ip string) (err error) {
  25. if err = s.growup.Join(c, mid, accTy, signTy, ip); err != nil {
  26. log.Error("s.growup.Join(%d) error(%v)", mid, err)
  27. }
  28. return
  29. }
  30. // Quit quit growup.
  31. func (s *Service) Quit(c context.Context, mid int64, ip string) (err error) {
  32. if err = s.growup.Quit(c, mid, ip); err != nil {
  33. log.Error("s.growup.Quit(%d) error(%v)", mid, err)
  34. }
  35. return
  36. }
  37. // Summary get up status.
  38. func (s *Service) Summary(c context.Context, mid int64, ip string) (us *growup.Summary, err error) {
  39. if us, err = s.growup.Summary(c, mid, ip); err != nil {
  40. log.Error("s.growup.Summary(%d) error(%v)", mid, err)
  41. }
  42. return
  43. }
  44. // Stat get up info.
  45. func (s *Service) Stat(c context.Context, mid int64, ip string) (ui *growup.Stat, err error) {
  46. if ui, err = s.growup.Stat(c, mid, ip); err != nil {
  47. log.Error("s.growup.Stat(%d) error(%v)", mid, err)
  48. }
  49. if ui == nil || len(ui.Tops) == 0 {
  50. log.Error("s.growup.Stat mid(%d) data(%v)", mid, ui)
  51. return
  52. }
  53. dt := time.Now().AddDate(0, 0, -2)
  54. year := dt.Format("2006")
  55. month := dt.Format("01")
  56. ui.Desc = "收入数据统计日期:" + year + "年" + month + "月"
  57. aids := make([]int64, 0, len(ui.Tops))
  58. for _, v := range ui.Tops {
  59. if v != nil {
  60. aids = append(aids, v.AID)
  61. }
  62. }
  63. avm, err := s.p.BatchArchives(c, mid, aids, ip)
  64. if err != nil {
  65. log.Error("s.p.BatchArchives aids (%v), ip(%s) err(%v)", aids, ip, err)
  66. return
  67. }
  68. if len(avm) == 0 {
  69. return
  70. }
  71. for _, v := range ui.Tops {
  72. if v != nil {
  73. if av, ok := avm[v.AID]; ok {
  74. v.Title = av.Archive.Title
  75. }
  76. }
  77. }
  78. return
  79. }
  80. // IncomeList get up status.
  81. func (s *Service) IncomeList(c context.Context, mid int64, ty, pn, ps int, ip string) (l *growup.IncomeList, err error) {
  82. if l, err = s.growup.IncomeList(c, mid, ty, pn, ps, ip); err != nil {
  83. log.Error("s.growup.IncomeList(%d) error(%v)", mid, err)
  84. return
  85. }
  86. if l == nil || len(l.Data) == 0 {
  87. log.Error("s.growup.IncomeList mid(%d) type(%d) data(%v)", mid, ty, l)
  88. return
  89. }
  90. aids := make([]int64, 0, len(l.Data))
  91. for _, v := range l.Data {
  92. if v != nil {
  93. aids = append(aids, v.AID)
  94. }
  95. }
  96. avm, err := s.p.BatchArchives(c, mid, aids, ip)
  97. if err != nil {
  98. log.Error("s.p.BatchArchives aids (%v), ip(%s) err(%v)", aids, ip, err)
  99. return
  100. }
  101. if len(avm) == 0 {
  102. return
  103. }
  104. for _, v := range l.Data {
  105. if v != nil {
  106. if av, ok := avm[v.AID]; ok {
  107. v.Title = av.Archive.Title
  108. }
  109. }
  110. }
  111. return
  112. }
  113. // BreachList get up info.
  114. func (s *Service) BreachList(c context.Context, mid int64, pn, ps int, ip string) (ui *growup.BreachList, err error) {
  115. if ui, err = s.growup.BreachList(c, mid, pn, ps, ip); err != nil {
  116. log.Error("s.growup.BreachList(%d) error(%v)", mid, err)
  117. }
  118. return
  119. }