vdoad.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package ads
  2. import (
  3. "context"
  4. "database/sql"
  5. "time"
  6. "go-common/app/service/main/resource/model"
  7. xsql "go-common/library/database/sql"
  8. "go-common/library/log"
  9. )
  10. const (
  11. _videoAdsSQL = `SELECT name,contract_id,aid,season_id,typeid,ad_cid,ad_strategy,ad_url,ad_order,skipable,note,agency_name,agency_country,
  12. agency_area,price,verified,state,front_aid,target,platform,type,user_set,play_count,mtime FROM video_ads WHERE state=0 AND verified=1 AND starttime<? AND endtime>? ORDER BY mtime,ctime ASC`
  13. )
  14. // VideoAds get video_ads
  15. func (dao *Dao) VideoAds(c context.Context) (ads []*model.VideoAD, err error) {
  16. var (
  17. rows *xsql.Rows
  18. now = time.Now()
  19. )
  20. if rows, err = dao.db.Query(c, _videoAdsSQL, now, now); err != nil {
  21. log.Error("dao.Exec(%v, %v), err (%v)", now, now, err)
  22. return
  23. }
  24. defer rows.Close()
  25. for rows.Next() {
  26. ad := &model.VideoAD{}
  27. var (
  28. agencyCountry sql.NullInt64
  29. agencyArea sql.NullInt64
  30. price sql.NullFloat64
  31. )
  32. if err = rows.Scan(&ad.Name, &ad.ContractID, &ad.Aids, &ad.SeasonID, &ad.TypeID, &ad.AdCid, &ad.AdStrategy,
  33. &ad.AdURL, &ad.AdOrder, &ad.Skipable, &ad.Note, &ad.AgencyName, &agencyCountry, &agencyArea,
  34. &price, &ad.Verified, &ad.State, &ad.FrontAid, &ad.Target, &ad.Platform, &ad.Type, &ad.UserSet, &ad.PlayCount, &ad.MTime); err != nil {
  35. log.Error("rows.Scan(), err (%v)", err)
  36. return
  37. }
  38. ad.AgencyCountry = int(agencyCountry.Int64)
  39. ad.AgencyArea = int(agencyArea.Int64)
  40. ad.Price = float32(price.Float64)
  41. ads = append(ads, ad)
  42. }
  43. err = rows.Err()
  44. return
  45. }