discount_plan.go 973 B

12345678910111213141516171819202122232425262728293031323334
  1. package dao
  2. import (
  3. "context"
  4. "go-common/app/service/live/gift/model"
  5. "go-common/library/database/sql"
  6. "go-common/library/log"
  7. "time"
  8. )
  9. var _getDiscountPlan = "SELECT id,scene_key,scene_value,platform FROM discount_plan WHERE online_time < ? AND offline_time > ? ORDER BY ctime"
  10. // GetDiscountPlan GetDiscountPlan
  11. func (d *Dao) GetDiscountPlan(ctx context.Context, now time.Time) (plans []*model.DiscountPlan, err error) {
  12. log.Info("GetDiscountPlan")
  13. var rows *sql.Rows
  14. var curTime = now.Format("2006-01-02 15:04:05")
  15. curTime = "2018-07-20 00:00:00"
  16. if rows, err = d.db.Query(ctx, _getDiscountPlan, curTime, curTime); err != nil {
  17. log.Error("query GetDiscountPlan error,err %v", err)
  18. return
  19. }
  20. defer rows.Close()
  21. for rows.Next() {
  22. d := &model.DiscountPlan{}
  23. if err = rows.Scan(&d.Id, &d.SceneKey, &d.SceneValue, &d.Platform); err != nil {
  24. log.Error("GetDiscountPlan scan error,err %v", err)
  25. return
  26. }
  27. plans = append(plans, d)
  28. }
  29. return
  30. }