coupon.go 1.4 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. _SelSalaryVideoCoupon = "SELECT `id`,`mid`,`coupon_count`,`coupon_type`,`state`,`type`,`ver` FROM `vip_view_coupon_salary_log_%s` WHERE `mid` = ?;"
  11. _addSalaryLogSQL = "INSERT INTO `vip_view_coupon_salary_log_%s`(`mid`,`coupon_count`,`coupon_type`,`state`,`type`)VALUES(?,?,?,?,?);"
  12. )
  13. //SalaryVideoCouponList select salary video coupon list.
  14. func (d *Dao) SalaryVideoCouponList(c context.Context, mid int64, dv string) (res []*model.VideoCouponSalaryLog, err error) {
  15. var rows *sql.Rows
  16. if rows, err = d.db.Query(c, fmt.Sprintf(_SelSalaryVideoCoupon, dv), mid); err != nil {
  17. err = errors.WithStack(err)
  18. return
  19. }
  20. defer rows.Close()
  21. for rows.Next() {
  22. r := new(model.VideoCouponSalaryLog)
  23. if err = rows.Scan(&r.ID, &r.Mid, &r.CouponCount, &r.CouponType, &r.State, &r.Type, &r.Ver); err != nil {
  24. err = errors.WithStack(err)
  25. res = nil
  26. return
  27. }
  28. res = append(res, r)
  29. }
  30. err = rows.Err()
  31. return
  32. }
  33. //AddSalaryLog add salary log.
  34. func (d *Dao) AddSalaryLog(c context.Context, l *model.VideoCouponSalaryLog, dv string) (err error) {
  35. if _, err = d.db.Exec(c, fmt.Sprintf(_addSalaryLogSQL, dv), l.Mid, l.CouponCount, l.CouponType, l.State, l.Type); err != nil {
  36. err = errors.WithStack(err)
  37. return
  38. }
  39. return
  40. }