up_bill.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/app/interface/main/growup/model"
  7. "go-common/library/database/sql"
  8. "go-common/library/log"
  9. xtime "go-common/library/time"
  10. )
  11. // UpBill get up bill
  12. func (s *Service) UpBill(c context.Context, mid int64) (data interface{}, err error) {
  13. redisKey := fmt.Sprintf("growup-up-bill-v1:%d", mid)
  14. res, err := s.dao.GetIncomeCache(c, redisKey)
  15. if err != nil {
  16. log.Error("s.dao.GetIncomeCache error(%v)", err)
  17. return
  18. }
  19. if res != nil {
  20. data = res["data"]
  21. return
  22. }
  23. data, err = s.upBill(c, mid)
  24. if err != nil {
  25. log.Error("s.upBill error(%v)", err)
  26. return
  27. }
  28. err = s.dao.SetIncomeCache(c, redisKey, map[string]interface{}{"data": data})
  29. if err != nil {
  30. log.Error("s.dao.SetIncomeCache error(%v)", err)
  31. }
  32. return
  33. }
  34. func (s *Service) upBill(c context.Context, mid int64) (data interface{}, err error) {
  35. up := &model.UpBill{}
  36. // 判断up主是否在创作激励
  37. signedAt, err := s.dao.GetUpSignedAt(c, "up_info_video", mid)
  38. if err != nil {
  39. log.Error("s.dao.GetUpSignedAt error(%v)", err)
  40. return
  41. }
  42. if signedAt == 0 {
  43. up.Join = false
  44. data = up
  45. return
  46. }
  47. up.Join = true
  48. endAt := time.Date(2018, 10, 31, 0, 0, 0, 0, time.Local)
  49. if signedAt >= xtime.Time(endAt.AddDate(0, 0, 1).Unix()) {
  50. up.SignedAt = signedAt
  51. up.EndAt = xtime.Time(endAt.Unix())
  52. data = up
  53. return
  54. }
  55. up, err = s.dao.GetUpBill(c, mid)
  56. up.Join = true
  57. if err == sql.ErrNoRows {
  58. err = nil
  59. up.SignedAt = signedAt
  60. up.EndAt = xtime.Time(endAt.Unix())
  61. data = up
  62. return
  63. }
  64. if err != nil {
  65. log.Error("s.dao.GetUpBill error(%v)", err)
  66. return
  67. }
  68. title, err := s.getAvTitle(c, []int64{up.AvID})
  69. if err != nil {
  70. log.Error("s.getAvTitle error(%v)", err)
  71. return
  72. }
  73. up.AvTitle = title[up.AvID]
  74. upsMap, err := s.dao.AccountInfos(c, []int64{mid})
  75. if err != nil {
  76. log.Error("s.dao.AccountInfos error(%v)", err)
  77. return
  78. }
  79. if up.Title == "流量王" {
  80. up.Title = "激励101"
  81. }
  82. if info, ok := upsMap[mid]; ok {
  83. up.Nickname = info.Nickname
  84. up.Face = info.Face
  85. }
  86. data = up
  87. return
  88. }