up_income.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/job/main/growup/model/income"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _inUpIncomeSQL = "INSERT INTO up_income(mid,av_count,play_count,av_income,audio_income,column_count,column_income,tax_money,income,total_income,av_base_income,av_tax,column_base_income,column_tax,bgm_base_income,bgm_tax,date,base_income,bgm_income,bgm_count,av_total_income,column_total_income,bgm_total_income) VALUES %s ON DUPLICATE KEY UPDATE mid=VALUES(mid),av_count=VALUES(av_count),play_count=VALUES(play_count),av_income=VALUES(av_income),audio_income=VALUES(audio_income),column_count=VALUES(column_count),column_income=VALUES(column_income),tax_money=VALUES(tax_money),income=VALUES(income),total_income=VALUES(total_income),av_base_income=VALUES(av_base_income),av_tax=VALUES(av_tax),column_base_income=VALUES(column_base_income),column_tax=VALUES(column_tax),bgm_base_income=VALUES(bgm_base_income),bgm_tax=VALUES(bgm_tax),date=VALUES(date),base_income=VALUES(base_income),bgm_income=VALUES(bgm_income),bgm_count=VALUES(bgm_count),av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
  10. _upIncomeSQL = "SELECT id,mid,av_income,audio_income,column_income,bgm_income,date FROM up_income WHERE id > ? ORDER BY id LIMIT ?"
  11. _fixInUpIncomeSQL = "INSERT INTO up_income(mid,av_total_income,column_total_income,bgm_total_income,date) VALUES %s ON DUPLICATE KEY UPDATE av_total_income=VALUES(av_total_income),column_total_income=VALUES(column_total_income),bgm_total_income=VALUES(bgm_total_income)"
  12. )
  13. // UpIncomes up incomes
  14. func (d *Dao) UpIncomes(c context.Context, id int64, limit int64) (last int64, us []*model.UpIncome, err error) {
  15. rows, err := d.db.Query(c, _upIncomeSQL, id, limit)
  16. if err != nil {
  17. log.Error("d.db.Query UpIncomes error (%v)", err)
  18. return
  19. }
  20. defer rows.Close()
  21. for rows.Next() {
  22. u := &model.UpIncome{}
  23. err = rows.Scan(&last, &u.MID, &u.AvIncome, &u.AudioIncome, &u.ColumnIncome, &u.BgmIncome, &u.Date)
  24. if err != nil {
  25. log.Error("rows scan error(%v)", err)
  26. return
  27. }
  28. us = append(us, u)
  29. }
  30. return
  31. }
  32. // InsertUpIncome batch insert up income
  33. func (d *Dao) InsertUpIncome(c context.Context, values string) (rows int64, err error) {
  34. res, err := d.db.Exec(c, fmt.Sprintf(_inUpIncomeSQL, values))
  35. if err != nil {
  36. log.Error("d.db.Exec InsertUpIncome error (%v)", err)
  37. return
  38. }
  39. return res.RowsAffected()
  40. }
  41. // FixInsertUpIncome batch insert up income
  42. func (d *Dao) FixInsertUpIncome(c context.Context, values string) (rows int64, err error) {
  43. res, err := d.db.Exec(c, fmt.Sprintf(_fixInUpIncomeSQL, values))
  44. if err != nil {
  45. log.Error("d.db.Exec InsertUpIncome error (%v)", err)
  46. return
  47. }
  48. return res.RowsAffected()
  49. }