ad.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package ad
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/app-show/model/banner"
  5. "go-common/library/log"
  6. )
  7. type ADRequest struct {
  8. RequestID string `json:"request_id"`
  9. ADIndexs map[string]map[string]*ADIndex `json:"ads_info"`
  10. }
  11. type ADIndex struct {
  12. Index int `json:"index"`
  13. Info *ADInfo `json:"ad_info"`
  14. IsAd bool `json:"is_ad"`
  15. CmMark int `json:"cm_mark"`
  16. }
  17. type ADInfo struct {
  18. CreativeID int `json:"creative_id"`
  19. CreativeType int `json:"creative_type"`
  20. CreativeContent struct {
  21. Title string `json:"title"`
  22. Desc string `json:"description"`
  23. VideoID int64 `json:"video_id"`
  24. UserName string `json:"username"`
  25. ImageURL string `json:"image_url"`
  26. ImageMD5 string `json:"image_md5"`
  27. LogURL string `json:"log_url"`
  28. LogMD5 string `json:"log_md5"`
  29. URL string `json:"url"`
  30. ClickURL string `json:"click_url"`
  31. ShowURL string `json:"show_url"`
  32. } `json:"creative_content"`
  33. AdCb string `json:"ad_cb"`
  34. }
  35. // RecoverBanner
  36. func (adr *ADRequest) ConvertBanner(ip, mobiApp string, build int) (banners map[int]map[int]*banner.Banner) {
  37. banners = map[int]map[int]*banner.Banner{}
  38. for resIdStr, sAdis := range adr.ADIndexs {
  39. resId, _ := strconv.Atoi(resIdStr)
  40. if len(sAdis) == 0 {
  41. log.Info("mobi_app:%v-build:%v-resource:%v-is_ad_loc:%v", mobiApp, build, resId, false)
  42. continue
  43. }
  44. for sidStr, adi := range sAdis {
  45. sid, _ := strconv.Atoi(sidStr)
  46. var bnnr = &banner.Banner{
  47. IsAdLoc: true,
  48. IsAd: adi.IsAd,
  49. IsAdReplace: false,
  50. CmMark: adi.CmMark,
  51. Rank: adi.Index,
  52. SrcId: sid,
  53. RequestId: adr.RequestID,
  54. ClientIp: ip,
  55. }
  56. if adInfo := adi.Info; adInfo != nil {
  57. bnnr.IsAdReplace = true
  58. bnnr.CreativeId = adInfo.CreativeID
  59. bnnr.AdCb = adInfo.AdCb
  60. bnnr.ShowUrl = adInfo.CreativeContent.ShowURL
  61. bnnr.ClickUrl = adInfo.CreativeContent.ClickURL
  62. bnnr.Title = adInfo.CreativeContent.Title
  63. bnnr.Image = adInfo.CreativeContent.ImageURL
  64. bnnr.Hash = adInfo.CreativeContent.ImageMD5
  65. bnnr.URI = adInfo.CreativeContent.URL
  66. bnnr.Channel = "*"
  67. }
  68. if _, ok := banners[resId]; ok {
  69. banners[resId][bnnr.Rank] = bnnr
  70. } else {
  71. banners[resId] = map[int]*banner.Banner{
  72. bnnr.Rank: bnnr,
  73. }
  74. }
  75. log.Info("mobi_app:%v-build:%v-source:%v-resource:%v-is_ad_loc:%v", mobiApp, build, sid, resId, true)
  76. }
  77. }
  78. return
  79. }