lottery.go 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. _lotteryIncomeSQL = "SELECT id,av_id,mid,tag_id,upload_time,total_income,income,tax_money,date FROM lottery_av_income WHERE id > ? AND %s date >= ? AND date <= ? ORDER BY id LIMIT ?"
  11. )
  12. // GetLotteryIncome get lottery income by query
  13. func (d *Dao) GetLotteryIncome(c context.Context, id int64, query string, from, to string, limit int, typ int) (avs []*model.ArchiveIncome, err error) {
  14. avs = make([]*model.ArchiveIncome, 0)
  15. if query != "" {
  16. query += " AND"
  17. }
  18. rows, err := d.db.Query(c, fmt.Sprintf(_lotteryIncomeSQL, query), id, from, to, limit)
  19. if err != nil {
  20. log.Error("GetLotteryIncome d.db.Query error(%v)", err)
  21. return
  22. }
  23. defer rows.Close()
  24. for rows.Next() {
  25. list := &model.ArchiveIncome{}
  26. err = rows.Scan(&list.ID, &list.AvID, &list.MID, &list.TagID, &list.UploadTime, &list.TotalIncome, &list.Income, &list.TaxMoney, &list.Date)
  27. if err != nil {
  28. log.Error("GetLotteryIncome rows scan error(%v)", err)
  29. return
  30. }
  31. list.Type = typ
  32. avs = append(avs, list)
  33. }
  34. err = rows.Err()
  35. return
  36. }