dialog.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package dao
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/service/main/vip/model"
  6. xsql "go-common/library/database/sql"
  7. "github.com/pkg/errors"
  8. )
  9. const (
  10. _dialogAll = "SELECT id,app_id,platform,start_time,end_time,title,content,follow,left_button,left_link,right_button,right_link FROM vip_conf_dialog WHERE stage=true AND start_time<=? AND (end_time='1970-01-01 08:00:00' OR end_time >?)"
  11. )
  12. // DialogAll .
  13. func (d *Dao) DialogAll(c context.Context) (res []*model.ConfDialog, err error) {
  14. var (
  15. rows *xsql.Rows
  16. curr = time.Now().Format("2006-01-02 15:04:05")
  17. )
  18. if rows, err = d.db.Query(c, _dialogAll, curr, curr); err != nil {
  19. err = errors.WithStack(err)
  20. return
  21. }
  22. defer rows.Close()
  23. for rows.Next() {
  24. r := new(model.ConfDialog)
  25. if err = rows.Scan(&r.ID, &r.AppID, &r.Platform, &r.StartTime, &r.EndTime, &r.Title, &r.Content, &r.Follow, &r.LeftButton, &r.LeftLink, &r.RightButton, &r.RightLink); err != nil {
  26. err = errors.WithStack(err)
  27. res = nil
  28. return
  29. }
  30. res = append(res, r)
  31. }
  32. err = rows.Err()
  33. return
  34. }