banner.go 647 B

1234567891011121314151617181920212223242526272829
  1. package dao
  2. import (
  3. "context"
  4. "database/sql"
  5. "go-common/library/log"
  6. "go-common/library/time"
  7. "go-common/app/interface/main/growup/model"
  8. )
  9. const (
  10. _bannerSQL = "SELECT id,image,link,start_at,end_at FROM banner WHERE start_at <= ? AND end_at >= ? LIMIT 1"
  11. )
  12. // Banner get banner
  13. func (d *Dao) Banner(c context.Context, t int64) (b *model.Banner, err error) {
  14. b = &model.Banner{}
  15. row := d.db.QueryRow(c, _bannerSQL, time.Time(t), time.Time(t))
  16. if err = row.Scan(&b.ID, &b.Image, &b.Link, &b.StartAt, &b.EndAt); err != nil {
  17. if err == sql.ErrNoRows {
  18. err = nil
  19. } else {
  20. log.Error("row scan error(%v)", err)
  21. }
  22. }
  23. return
  24. }