point.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/main/vip/model"
  5. "go-common/library/database/sql"
  6. "github.com/pkg/errors"
  7. )
  8. const (
  9. _allPointExchangePriceSQL = "SELECT origin_point,current_point,month,promotion_tip,promotion_color FROM vip_point_exchange_price"
  10. _pointExchangePriceSQL = "SELECT origin_point,current_point,month,promotion_tip,promotion_color FROM vip_point_exchange_price WHERE month = ?"
  11. )
  12. //AllPointExchangePrice .
  13. func (d *Dao) AllPointExchangePrice(c context.Context) (pe []*model.PointExchangePrice, err error) {
  14. var rows *sql.Rows
  15. if rows, err = d.db.Query(c, _allPointExchangePriceSQL); err != nil {
  16. err = errors.WithStack(err)
  17. return
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. r := new(model.PointExchangePrice)
  22. if err = rows.Scan(&r.OriginPoint, &r.CurrentPoint, &r.Month, &r.PromotionTip, &r.PromotionColor); err != nil {
  23. pe = nil
  24. err = errors.WithStack(err)
  25. d.errProm.Incr("row_scan_db")
  26. }
  27. pe = append(pe, r)
  28. }
  29. return
  30. }
  31. //PointExchangePrice def.
  32. func (d *Dao) PointExchangePrice(c context.Context, month int16) (pe *model.PointExchangePrice, err error) {
  33. row := d.db.QueryRow(c, _pointExchangePriceSQL, month)
  34. pe = new(model.PointExchangePrice)
  35. if err = row.Scan(&pe.OriginPoint, &pe.CurrentPoint, &pe.Month, &pe.PromotionTip, &pe.PromotionColor); err != nil {
  36. if err == sql.ErrNoRows {
  37. pe = nil
  38. err = nil
  39. } else {
  40. err = errors.Wrapf(err, "scan error")
  41. }
  42. }
  43. return
  44. }