operation.go 836 B

12345678910111213141516171819202122232425262728293031323334
  1. package operation
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/web-show/model/operation"
  6. "go-common/library/log"
  7. xtime "go-common/library/time"
  8. )
  9. const (
  10. _selNoticeSQL = "SELECT id,type,content,link,ads,pic,rank FROM operations where stime <= ? AND etime > ? ORDER BY stime DESC"
  11. )
  12. //Operation dao
  13. func (dao *Dao) Operation(c context.Context) (ns []*operation.Operation, err error) {
  14. now := xtime.Time(time.Now().Unix())
  15. rows, err := dao.db.Query(c, _selNoticeSQL, now, now)
  16. if err != nil {
  17. log.Error("notice.Query error(%v)", err)
  18. return
  19. }
  20. defer rows.Close()
  21. for rows.Next() {
  22. n := &operation.Operation{}
  23. if err = rows.Scan(&n.ID, &n.Type, &n.Message, &n.Link, &n.Ads, &n.Pic, &n.Rank); err != nil {
  24. PromError("Operation", "rows.scan err(%v)", err)
  25. return
  26. }
  27. ns = append(ns, n)
  28. }
  29. return
  30. }