bgm.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. package income
  2. import (
  3. "context"
  4. "fmt"
  5. model "go-common/app/admin/main/growup/model/income"
  6. "go-common/library/log"
  7. )
  8. const (
  9. // select
  10. _getAvByBgmIncome = "SELECT aid FROM bgm_income WHERE sid = ? AND date >= ? AND date <= ?"
  11. _bgmIncomeSQL = "SELECT id,sid,mid,join_at,total_income,income,tax_money,date FROM bgm_income WHERE id > ? AND date >= ? AND date <= ? AND %s is_deleted = 0 ORDER BY id LIMIT ?"
  12. )
  13. // GetAvByBgm get av_id by bgm id
  14. func (d *Dao) GetAvByBgm(c context.Context, sid int64, from, to string) (avs map[int64]struct{}, err error) {
  15. avs = make(map[int64]struct{})
  16. rows, err := d.db.Query(c, _getAvByBgmIncome, sid, from, to)
  17. if err != nil {
  18. log.Error("GetAvByBgm d.db.Query error(%v)", err)
  19. return
  20. }
  21. defer rows.Close()
  22. for rows.Next() {
  23. var avID int64
  24. err = rows.Scan(&avID)
  25. if err != nil {
  26. log.Error("GetAvByBgm rows scan error(%v)", err)
  27. return
  28. }
  29. avs[avID] = struct{}{}
  30. }
  31. err = rows.Err()
  32. return
  33. }
  34. // GetBgmIncome get bgm income by query
  35. func (d *Dao) GetBgmIncome(c context.Context, id int64, query string, from, to string, limit int, typ int) (bgms []*model.ArchiveIncome, err error) {
  36. bgms = make([]*model.ArchiveIncome, 0)
  37. if query != "" {
  38. query += " AND"
  39. }
  40. rows, err := d.db.Query(c, fmt.Sprintf(_bgmIncomeSQL, query), id, from, to, limit)
  41. if err != nil {
  42. log.Error("GetBgmIncome d.db.Query error(%v)", err)
  43. return
  44. }
  45. defer rows.Close()
  46. for rows.Next() {
  47. list := &model.ArchiveIncome{}
  48. err = rows.Scan(&list.ID, &list.AvID, &list.MID, &list.UploadTime, &list.TotalIncome, &list.Income, &list.TaxMoney, &list.Date)
  49. if err != nil {
  50. log.Error("GetBgmIncome rows scan error(%v)", err)
  51. return
  52. }
  53. list.Type = typ
  54. bgms = append(bgms, list)
  55. }
  56. err = rows.Err()
  57. return
  58. }