mysql.go 957 B

12345678910111213141516171819202122232425262728293031323334
  1. package ad
  2. import (
  3. "context"
  4. "time"
  5. "go-common/app/interface/main/web-show/model/resource"
  6. "go-common/library/log"
  7. )
  8. const (
  9. _selAds = `SELECT sch.id,sch.resource_id,so.title,so.pic,so.spic,so.url,so.atype FROM schedule as sch INNER JOIN order_applied as o ON sch.applied_id = o.id
  10. INNER JOIN material as so ON so.id= o.material_id WHERE sch.stime<? AND sch.etime>? AND o.state =3`
  11. )
  12. // Ads return ads info
  13. func (dao *Dao) Ads(c context.Context) (ads []*resource.Assignment, err error) {
  14. rows, err := dao.selAdsStmt.Query(c, time.Now(), time.Now())
  15. if err != nil {
  16. log.Error("dao.selAdsStmt() err(%v)", err)
  17. return
  18. }
  19. defer rows.Close()
  20. ads = make([]*resource.Assignment, 0)
  21. for rows.Next() {
  22. ad := &resource.Assignment{}
  23. if err = rows.Scan(&ad.ID, &ad.ResID, &ad.Name, &ad.Pic, &ad.LitPic, &ad.URL, &ad.Atype); err != nil {
  24. PromError("mysql.Ads", "rows.scan err(%v)", err)
  25. return
  26. }
  27. ads = append(ads, ad)
  28. }
  29. return
  30. }