cheat.go 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. package service
  2. import (
  3. "bytes"
  4. "context"
  5. "fmt"
  6. "strconv"
  7. "time"
  8. "go-common/library/log"
  9. xtime "go-common/library/time"
  10. "go-common/app/admin/main/growup/model"
  11. )
  12. // CheatUps get cheat ups
  13. func (s *Service) CheatUps(c context.Context, mid int64, nickname string, from, limit int) (total int, spies []*model.UpSpy, err error) {
  14. total, err = s.dao.UpSpyCount(c)
  15. if err != nil {
  16. return
  17. }
  18. var query string
  19. if mid > 0 {
  20. query = fmt.Sprintf("WHERE mid=%d", mid)
  21. }
  22. if nickname != "" {
  23. query = fmt.Sprintf("WHERE nickname='%s'", nickname)
  24. }
  25. spies, err = s.dao.UpSpies(c, query, from, limit)
  26. if err != nil {
  27. return
  28. }
  29. if spies == nil {
  30. spies = make([]*model.UpSpy, 0)
  31. }
  32. return
  33. }
  34. // CheatArchives get cheat avs
  35. func (s *Service) CheatArchives(c context.Context, mid, avID int64, nickname string, from, limit int) (total int, spies []*model.ArchiveSpy, err error) {
  36. var query string
  37. if mid > 0 {
  38. query = fmt.Sprintf("WHERE mid=%d", mid)
  39. }
  40. if nickname != "" {
  41. query = fmt.Sprintf("WHERE nickname='%s'", nickname)
  42. }
  43. if avID > 0 {
  44. if len(query) > 0 {
  45. query += fmt.Sprintf(" AND archive_id=%d", avID)
  46. } else {
  47. query = fmt.Sprintf("WHERE archive_id=%d", avID)
  48. }
  49. }
  50. total, err = s.dao.ArchiveSpyCount(c, query)
  51. if err != nil {
  52. return
  53. }
  54. spies, err = s.dao.ArchiveSpies(c, query, from, limit)
  55. if err != nil {
  56. return
  57. }
  58. return
  59. }
  60. // ExportCheatUps export up.
  61. func (s *Service) ExportCheatUps(c context.Context, mid int64, nickname string, from, limit int) (res []byte, err error) {
  62. _, spies, err := s.CheatUps(c, mid, nickname, from, limit)
  63. if err != nil {
  64. log.Error("s.ExportSpyUp QuerySpyUp error(%v)", err)
  65. return
  66. }
  67. data := formatSpyUp(spies)
  68. res, err = FormatCSV(data)
  69. if err != nil {
  70. log.Error("s.ExportSpyUp FormatCSV error(%v)", err)
  71. }
  72. return
  73. }
  74. func formatSpyUp(infos []*model.UpSpy) (data [][]string) {
  75. str := []string{"序号", "UID", "昵称", "签约时间", "粉丝数", "作弊粉丝量", "播放量", "作弊播放量"}
  76. data = append(data, str)
  77. count := 0
  78. for _, info := range infos {
  79. count++
  80. v := []string{strconv.Itoa(count), strconv.FormatInt(info.MID, 10), info.Nickname, time.Unix(int64(info.SignedAt), 0).Format("2006-01-02 15:04:05"), strconv.Itoa(info.Fans), strconv.Itoa(info.CheatFans), strconv.Itoa(info.PlayCount), strconv.Itoa(info.CheatPlayCount)}
  81. data = append(data, v)
  82. }
  83. return
  84. }
  85. // ExportCheatAvs export cheat avs
  86. func (s *Service) ExportCheatAvs(c context.Context, mid, avID int64, nickname string, from, limit int) (res []byte, err error) {
  87. _, infos, err := s.CheatArchives(c, mid, avID, nickname, from, limit)
  88. if err != nil {
  89. log.Error("s.ExportSpyAV QuerySpyArchive error(%v)", err)
  90. return
  91. }
  92. data := fromatSpyAV(infos)
  93. res, err = FormatCSV(data)
  94. if err != nil {
  95. log.Error("s.ExportSpyAV FormatCSV error(%v)", err)
  96. }
  97. return
  98. }
  99. func fromatSpyAV(infos []*model.ArchiveSpy) (data [][]string) {
  100. str := []string{"序号", "稿件ID", "UP昵称", "投稿时间", "累计收入", "作弊播放量", "作弊收藏量", "作弊硬币量"}
  101. data = append(data, str)
  102. count := 0
  103. for _, info := range infos {
  104. count++
  105. v := []string{strconv.Itoa(count), strconv.FormatInt(info.ArchiveID, 10), info.Nickname, time.Unix(int64(info.UploadTime), 0).Format("2006-01-02 15:04:05"), strconv.FormatFloat(float64(info.TotalIncome)/100, 'f', 2, 32), strconv.Itoa(info.CheatPlayCount), strconv.Itoa(info.CheatFavorite), strconv.Itoa(info.CheatCoin)}
  106. data = append(data, v)
  107. }
  108. return
  109. }
  110. // QueryCheatFans query cheat fans.
  111. func (s *Service) QueryCheatFans(c context.Context, from, limit int64) (total int64, fans []*model.CheatFans, err error) {
  112. total, err = s.dao.CheatFansCount(c)
  113. if err != nil {
  114. return
  115. }
  116. fans, err = s.dao.CheatFans(c, from, limit)
  117. return
  118. }
  119. // CheatFans handle checkfans mid.
  120. func (s *Service) CheatFans(c context.Context, mid int64) (err error) {
  121. cu, err := s.cheatFans(c, mid)
  122. if err != nil {
  123. return
  124. }
  125. if cu.RealFans >= 1000 {
  126. return
  127. }
  128. _, err = s.dao.InsertCheatFansInfo(c, cheatFansValues(cu))
  129. return
  130. }
  131. func (s *Service) cheatFans(c context.Context, mid int64) (up *model.CheatFans, err error) {
  132. up = &model.CheatFans{}
  133. v, err := s.dao.UpInfo(c, mid, 3)
  134. if err != nil {
  135. return
  136. }
  137. if v.MID == 0 {
  138. return
  139. }
  140. up.MID = v.MID
  141. up.Nickname = v.Nickname
  142. up.SignedAt = v.SignedAt
  143. up.DeductAt = xtime.Time(time.Now().Unix())
  144. up.RealFans, err = s.dao.GetUpRealFansCount(c, s.conf.Host.Common, v.MID)
  145. if err != nil {
  146. return
  147. }
  148. up.CheatFans, err = s.dao.GetUpCheatFansCount(c, s.conf.Host.Common, v.MID)
  149. if err != nil {
  150. return
  151. }
  152. return
  153. }
  154. func cheatFansValues(cu *model.CheatFans) (values string) {
  155. var buf bytes.Buffer
  156. buf.WriteString("(")
  157. buf.WriteString(strconv.FormatInt(cu.MID, 10))
  158. buf.WriteByte(',')
  159. buf.WriteString(fmt.Sprintf("'%s'", cu.Nickname))
  160. buf.WriteByte(',')
  161. buf.WriteString(fmt.Sprintf("'%s'", cu.SignedAt.Time().Format("2006-01-02 15:04:05")))
  162. buf.WriteByte(',')
  163. buf.WriteString(strconv.Itoa(cu.RealFans))
  164. buf.WriteByte(',')
  165. buf.WriteString(strconv.Itoa(cu.CheatFans))
  166. buf.WriteByte(',')
  167. buf.WriteString(fmt.Sprintf("'%s'", cu.DeductAt.Time().Format("2006-01-02 15:04-05")))
  168. buf.WriteString(")")
  169. buf.WriteByte(',')
  170. if buf.Len() > 0 {
  171. buf.Truncate(buf.Len() - 1)
  172. }
  173. values = buf.String()
  174. buf.Reset()
  175. return
  176. }