coupon_old.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package dao
  2. import (
  3. "context"
  4. "fmt"
  5. "go-common/app/job/main/vip/model"
  6. "go-common/library/database/sql"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _selSalaryMaxID = "SELECT IFNULL(MAX(id),0) id FROM vip_view_coupon_salary_log_%s;"
  11. _selOldSalaryList = "SELECT `mid`,`coupon_count`,`state`,`type` FROM `vip_view_coupon_salary_log_%s` WHERE id>? AND id <=?;"
  12. )
  13. // SalaryLogMaxID select salary log max id.
  14. func (d *Dao) SalaryLogMaxID(c context.Context, dv string) (maxID int, err error) {
  15. var row = d.oldDb.QueryRow(c, fmt.Sprintf(_selSalaryMaxID, dv))
  16. if err = row.Scan(&maxID); err != nil {
  17. err = errors.WithStack(err)
  18. return
  19. }
  20. return
  21. }
  22. //SelOldSalaryList sel old salary list
  23. func (d *Dao) SelOldSalaryList(c context.Context, id, endID int, dv string) (res []*model.OldSalaryLog, err error) {
  24. var rows *sql.Rows
  25. if rows, err = d.oldDb.Query(c, fmt.Sprintf(_selOldSalaryList, dv), id, endID); err != nil {
  26. err = errors.WithStack(err)
  27. return
  28. }
  29. defer rows.Close()
  30. for rows.Next() {
  31. r := new(model.OldSalaryLog)
  32. if err = rows.Scan(&r.Mid, &r.CouponCount, &r.State, &r.Type); err != nil {
  33. err = errors.WithStack(err)
  34. res = nil
  35. return
  36. }
  37. res = append(res, r)
  38. }
  39. err = rows.Err()
  40. return
  41. }