lottery.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "net/url"
  6. "strconv"
  7. "go-common/app/job/main/growup/model"
  8. "go-common/library/ecode"
  9. "go-common/library/log"
  10. )
  11. const (
  12. // insert
  13. _inBubbleMetaSQL = "INSERT INTO lottery_av_info(av_id, date, b_type) VALUES %s ON DUPLICATE KEY UPDATE date=VALUES(date)"
  14. _inBubbleIncomeSQL = "INSERT INTO lottery_av_income(av_id,mid,tag_id,upload_time,total_income,income,tax_money,date,base_income,b_type) VALUES %s ON DUPLICATE KEY UPDATE av_id=VALUES(av_id),mid=VALUES(mid),tag_id=VALUES(tag_id),upload_time=VALUES(upload_time),total_income=VALUES(total_income),income=VALUES(income),tax_money=VALUES(tax_money),date=VALUES(date),base_income=VALUES(base_income)"
  15. )
  16. // InsertBubbleMeta insert lottery avs
  17. func (d *Dao) InsertBubbleMeta(c context.Context, values string) (rows int64, err error) {
  18. if values == "" {
  19. return
  20. }
  21. res, err := d.db.Exec(c, fmt.Sprintf(_inBubbleMetaSQL, values))
  22. if err != nil {
  23. log.Error("dao.InsertBubbleMeta exec error(%v)", err)
  24. return
  25. }
  26. return res.RowsAffected()
  27. }
  28. // InsertBubbleIncome insert lottery income
  29. func (d *Dao) InsertBubbleIncome(c context.Context, vals string) (rows int64, err error) {
  30. if vals == "" {
  31. return
  32. }
  33. res, err := d.db.Exec(c, fmt.Sprintf(_inBubbleIncomeSQL, vals))
  34. if err != nil {
  35. log.Error("dao.InsertBubbleIncome exec error(%v)", err)
  36. return
  37. }
  38. return res.RowsAffected()
  39. }
  40. // GetLotteryRIDs get lottery id
  41. func (d *Dao) GetLotteryRIDs(c context.Context, start, end, offset int64) (info *model.LotteryRes, err error) {
  42. info = &model.LotteryRes{}
  43. params := url.Values{}
  44. params.Set("begin", strconv.FormatInt(start, 10))
  45. params.Set("end", strconv.FormatInt(end, 10))
  46. params.Set("offset", strconv.FormatInt(offset, 10))
  47. var res struct {
  48. Code int `json:"code"`
  49. Message string `json:"message"`
  50. Data *model.LotteryRes `json:"data"`
  51. }
  52. uri := d.avLotteryURL
  53. if err = d.client.Get(c, uri, "", params, &res); err != nil {
  54. log.Error("d.client.Get uri(%s) error(%v)", uri+"?"+params.Encode(), err)
  55. return
  56. }
  57. if res.Code != 0 {
  58. log.Error("GetLotteryRIDs code != 0. res.Code(%d) | uri(%s) error(%v)", res.Code, uri+"?"+params.Encode(), err)
  59. err = ecode.GrowupGetActivityError
  60. return
  61. }
  62. info = res.Data
  63. return
  64. }
  65. // VoteBIZArchive fetch avs in vote biz
  66. func (d *Dao) VoteBIZArchive(c context.Context, start, end int64) (data []*model.VoteBIZArchive, err error) {
  67. var (
  68. uri = d.avVoteURL
  69. params = url.Values{}
  70. res struct {
  71. Code int `json:"code"`
  72. Message string `json:"message"`
  73. Data []*model.VoteBIZArchive `json:"data"`
  74. }
  75. )
  76. params.Set("start", strconv.FormatInt(start, 10))
  77. params.Set("end", strconv.FormatInt(end, 10))
  78. if err = d.client.Get(c, uri, "", params, &res); err != nil {
  79. log.Error("d.client.Get uri(%s) error(%v)", uri+"?"+params.Encode(), err)
  80. return
  81. }
  82. if res.Code != 0 {
  83. log.Error("VoteBIZArchive code != 0. res.Code(%d) | uri(%s) errorMsg(%s)", res.Code, uri+"?"+params.Encode(), res.Message)
  84. err = ecode.Errorf(ecode.ServerErr, "获取参与投票的视频失败")
  85. return
  86. }
  87. data = res.Data
  88. return
  89. }