gift_plan.go 983 B

123456789101112131415161718192021222324252627282930313233
  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 _getOnlinePlan = "SELECT id,list,silver_list,scene_key,scene_value,mtime,platform FROM gift_plan WHERE online_time <= ? AND offline_time >= ? ORDER BY scene_key DESC,mtime DESC"
  10. // GetOnlinePlan GetOnlinePlan
  11. func (d *Dao) GetOnlinePlan(ctx context.Context) (plans []*model.GiftPlan, err error) {
  12. log.Info("GetOnlinePlan")
  13. var rows *sql.Rows
  14. var curTime = time.Now().Format("2006-01-02 15:04:05")
  15. if rows, err = d.db.Query(ctx, _getOnlinePlan, curTime, curTime); err != nil {
  16. log.Error("query getOnlinePlan error,err %v", err)
  17. return
  18. }
  19. defer rows.Close()
  20. for rows.Next() {
  21. p := &model.GiftPlan{}
  22. if err = rows.Scan(&p.Id, &p.List, &p.SilverList, &p.SceneKey, &p.SceneValue, &p.Mtime, &p.Platform); err != nil {
  23. log.Error("getOnlinePlan scan error,err %v", err)
  24. return
  25. }
  26. plans = append(plans, p)
  27. }
  28. return
  29. }