up_bill.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/library/log"
  6. )
  7. const (
  8. _upSignedAvsSQL = "SELECT id, mid, avs FROM up_signed_avs WHERE id > ? ORDER BY id LIMIT ?"
  9. _inUpBillSQL = "INSERT INTO up_bill(mid,first_income,max_income,total_income,av_count,av_max_income,av_id,quality_value,defeat_num,title,share_items,first_time,max_time,signed_at,end_at) VALUES %s"
  10. )
  11. // InsertUpBillBatch insert up_bill
  12. func (d *Dao) InsertUpBillBatch(c context.Context, values string) (rows int64, err error) {
  13. res, err := d.db.Exec(c, fmt.Sprintf(_inUpBillSQL, values))
  14. if err != nil {
  15. log.Error("d.db.Exec InsertUpBill error (%v)", err)
  16. return
  17. }
  18. return res.RowsAffected()
  19. }
  20. // ListUpSignedAvs list up_signed_avs
  21. func (d *Dao) ListUpSignedAvs(c context.Context, id int64, limit int) (ups map[int64]int64, last int64, err error) {
  22. ups = make(map[int64]int64)
  23. rows, err := d.db.Query(c, _upSignedAvsSQL, id, limit)
  24. if err != nil {
  25. log.Error("ListUpSignedAvs d.db.Query error(%v)", err)
  26. return
  27. }
  28. defer rows.Close()
  29. for rows.Next() {
  30. var mid, avs int64
  31. err = rows.Scan(&last, &mid, &avs)
  32. if err != nil {
  33. log.Error("ListUpSignedAvs rows.Scan error(%v)", err)
  34. return
  35. }
  36. ups[mid] = avs
  37. }
  38. return
  39. }