cheat.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. "go-common/library/log"
  7. "go-common/library/xstr"
  8. "go-common/app/job/main/growup/model"
  9. )
  10. const (
  11. // select
  12. _upsSQL = "SELECT mid,nickname,fans,signed_at,is_deleted FROM up_info_video WHERE account_state = 3 AND mid IN (%s)"
  13. _avIncomeSQL = "SELECT mid,av_id,upload_time,total_income FROM av_income_statis WHERE av_id IN (%s) AND mtime > ?"
  14. _playCountSQL = "SELECT mid,play FROM up_base_statistics WHERE mid IN (%s)"
  15. _avBreachSQL = "SELECT id,av_id FROM av_breach_record WHERE id > ? ORDER BY id LIMIT ?"
  16. _deleteArchiveSpySQL = "DELETE FROM archive_spy_statistics LIMIT ?"
  17. _deleteUpSpySQL = "DELETE FROM up_spy_statistics LIMIT ?"
  18. // insert
  19. _inCheatUpsSQL = "INSERT INTO up_spy_statistics(mid,signed_at,nickname,fans,cheat_fans,play_count,cheat_play_count,account_state) VALUES %s ON DUPLICATE KEY UPDATE signed_at=VALUES(signed_at),nickname=VALUES(nickname),fans=VALUES(fans),cheat_fans=VALUES(cheat_fans),play_count=VALUES(play_count),cheat_play_count=VALUES(cheat_play_count),account_state=VALUES(account_state)"
  20. _inCheatArchiveSQL = "INSERT INTO archive_spy_statistics(archive_id,mid,nickname,upload_time,total_income,cheat_play_count,cheat_favorite,cheat_coin,deducted) VALUES %s ON DUPLICATE KEY UPDATE nickname=VALUES(nickname),total_income=VALUES(total_income),cheat_play_count=VALUES(cheat_play_count),cheat_favorite=VALUES(cheat_favorite),cheat_coin=VALUES(cheat_coin),deducted=VALUES(deducted)"
  21. )
  22. // DelArchiveSpy del archive spy
  23. func (d *Dao) DelArchiveSpy(c context.Context, limit int64) (rows int64, err error) {
  24. res, err := d.db.Exec(c, _deleteArchiveSpySQL, limit)
  25. if err != nil {
  26. return
  27. }
  28. return res.RowsAffected()
  29. }
  30. // DelUpSpy del up spy
  31. func (d *Dao) DelUpSpy(c context.Context, limit int64) (rows int64, err error) {
  32. res, err := d.db.Exec(c, _deleteUpSpySQL, limit)
  33. if err != nil {
  34. return
  35. }
  36. return res.RowsAffected()
  37. }
  38. // AvBreachRecord get av_ids deducted
  39. func (d *Dao) AvBreachRecord(c context.Context, id int64, limit int64) (last int64, ds map[int64]bool, err error) {
  40. rows, err := d.db.Query(c, _avBreachSQL, id, limit)
  41. if err != nil {
  42. return
  43. }
  44. ds = make(map[int64]bool)
  45. defer rows.Close()
  46. for rows.Next() {
  47. var avID int64
  48. err = rows.Scan(&last, &avID)
  49. if err != nil {
  50. return
  51. }
  52. ds[avID] = true
  53. }
  54. return
  55. }
  56. // Ups get ups in up_info_video
  57. func (d *Dao) Ups(c context.Context, mids []int64) (cs map[int64]*model.Cheating, err error) {
  58. rows, err := d.db.Query(c, fmt.Sprintf(_upsSQL, xstr.JoinInts(mids)))
  59. if err != nil {
  60. return
  61. }
  62. defer rows.Close()
  63. cs = make(map[int64]*model.Cheating)
  64. for rows.Next() {
  65. c := &model.Cheating{}
  66. err = rows.Scan(&c.MID, &c.Nickname, &c.Fans, &c.SignedAt, &c.IsDeleted)
  67. if err != nil {
  68. return
  69. }
  70. cs[c.MID] = c
  71. }
  72. return
  73. }
  74. // Avs get avs in av_income_statis
  75. func (d *Dao) Avs(c context.Context, date time.Time, aids []int64) (cs map[int64]*model.Cheating, err error) {
  76. rows, err := d.db.Query(c, fmt.Sprintf(_avIncomeSQL, xstr.JoinInts(aids)), date)
  77. if err != nil {
  78. return
  79. }
  80. defer rows.Close()
  81. cs = make(map[int64]*model.Cheating)
  82. for rows.Next() {
  83. c := &model.Cheating{}
  84. err = rows.Scan(&c.MID, &c.AvID, &c.UploadTime, &c.TotalIncome)
  85. if err != nil {
  86. log.Error("rows.Scan error(%v)", err)
  87. return
  88. }
  89. cs[c.AvID] = c
  90. }
  91. return
  92. }
  93. // PlayCount get play count in up_base_statistics
  94. func (d *Dao) PlayCount(c context.Context, mids []int64) (cs map[int64]int64, err error) {
  95. rows, err := d.db.Query(c, fmt.Sprintf(_playCountSQL, xstr.JoinInts(mids)))
  96. if err != nil {
  97. return
  98. }
  99. cs = make(map[int64]int64)
  100. defer rows.Close()
  101. for rows.Next() {
  102. var mid, count int64
  103. err = rows.Scan(&mid, &count)
  104. if err != nil {
  105. log.Error("rows.Scan error(%v)", err)
  106. return
  107. }
  108. cs[mid] = count
  109. }
  110. return
  111. }
  112. // InsertCheatUps insert cheat ups
  113. func (d *Dao) InsertCheatUps(c context.Context, values string) (rows int64, err error) {
  114. res, err := d.db.Exec(c, fmt.Sprintf(_inCheatUpsSQL, values))
  115. if err != nil {
  116. return
  117. }
  118. return res.RowsAffected()
  119. }
  120. // InsertCheatArchives insert cheat archives
  121. func (d *Dao) InsertCheatArchives(c context.Context, values string) (rows int64, err error) {
  122. res, err := d.db.Exec(c, fmt.Sprintf(_inCheatArchiveSQL, values))
  123. if err != nil {
  124. return
  125. }
  126. return res.RowsAffected()
  127. }