banner.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. package region
  2. import (
  3. "context"
  4. "strconv"
  5. "time"
  6. "go-common/app/interface/main/app-show/model"
  7. "go-common/app/interface/main/app-show/model/banner"
  8. resource "go-common/app/service/main/resource/model"
  9. "go-common/library/log"
  10. )
  11. var (
  12. _banners = map[int]map[int8]int{
  13. 13: map[int8]int{
  14. model.PlatIPhone: 454,
  15. model.PlatIPad: 788,
  16. model.PlatAndroid: 617,
  17. model.PlatIPhoneI: 1022,
  18. model.PlatAndroidG: 1360,
  19. model.PlatAndroidI: 1791,
  20. model.PlatIPadI: 1192,
  21. },
  22. 1: map[int8]int{
  23. model.PlatIPhone: 453,
  24. model.PlatIPad: 787,
  25. model.PlatAndroid: 616,
  26. model.PlatIPhoneI: 1017,
  27. model.PlatAndroidG: 1355,
  28. model.PlatAndroidI: 1785,
  29. model.PlatIPadI: 1187,
  30. },
  31. 3: map[int8]int{
  32. model.PlatIPhone: 455,
  33. model.PlatIPad: 789,
  34. model.PlatAndroid: 618,
  35. model.PlatIPhoneI: 1028,
  36. model.PlatAndroidG: 1366,
  37. model.PlatAndroidI: 1798,
  38. model.PlatIPadI: 1198,
  39. },
  40. 129: map[int8]int{
  41. model.PlatIPhone: 456,
  42. model.PlatIPad: 790,
  43. model.PlatAndroid: 619,
  44. model.PlatIPhoneI: 1033,
  45. model.PlatAndroidG: 1371,
  46. model.PlatAndroidI: 1804,
  47. model.PlatIPadI: 1203,
  48. },
  49. 4: map[int8]int{
  50. model.PlatIPhone: 457,
  51. model.PlatIPad: 791,
  52. model.PlatAndroid: 620,
  53. model.PlatIPhoneI: 1038,
  54. model.PlatAndroidG: 1376,
  55. model.PlatAndroidI: 1810,
  56. model.PlatIPadI: 1208,
  57. },
  58. 36: map[int8]int{
  59. model.PlatIPhone: 458,
  60. model.PlatIPad: 792,
  61. model.PlatAndroid: 621,
  62. model.PlatIPhoneI: 1043,
  63. model.PlatAndroidG: 1381,
  64. model.PlatAndroidI: 1816,
  65. model.PlatIPadI: 1213,
  66. },
  67. 160: map[int8]int{
  68. model.PlatIPhone: 459,
  69. model.PlatIPad: 793,
  70. model.PlatAndroid: 622,
  71. model.PlatIPhoneI: 1048,
  72. model.PlatAndroidG: 1386,
  73. model.PlatAndroidI: 1822,
  74. model.PlatIPadI: 1218,
  75. },
  76. 119: map[int8]int{
  77. model.PlatIPhone: 460,
  78. model.PlatIPad: 794,
  79. model.PlatAndroid: 623,
  80. model.PlatIPhoneI: 1053,
  81. model.PlatAndroidG: 1391,
  82. model.PlatAndroidI: 1828,
  83. model.PlatIPadI: 1223,
  84. },
  85. 155: map[int8]int{
  86. model.PlatIPhone: 462,
  87. model.PlatIPad: 795,
  88. model.PlatAndroid: 624,
  89. model.PlatIPhoneI: 1058,
  90. model.PlatAndroidG: 1396,
  91. model.PlatAndroidI: 1834,
  92. model.PlatIPadI: 1228,
  93. },
  94. 5: map[int8]int{
  95. model.PlatIPhone: 463,
  96. model.PlatIPad: 796,
  97. model.PlatAndroid: 625,
  98. model.PlatIPhoneI: 1063,
  99. model.PlatAndroidG: 1401,
  100. model.PlatAndroidI: 1840,
  101. model.PlatIPadI: 1233,
  102. },
  103. 23: map[int8]int{
  104. model.PlatIPhone: 464,
  105. model.PlatIPad: 797,
  106. model.PlatAndroid: 626,
  107. model.PlatIPhoneI: 1068,
  108. model.PlatAndroidG: 1406,
  109. model.PlatAndroidI: 1846,
  110. model.PlatIPadI: 1238,
  111. },
  112. 11: map[int8]int{
  113. model.PlatIPhone: 465,
  114. model.PlatIPad: 798,
  115. model.PlatAndroid: 627,
  116. model.PlatIPhoneI: 1073,
  117. model.PlatAndroidG: 1411,
  118. model.PlatAndroidI: 1852,
  119. model.PlatIPadI: 1243,
  120. },
  121. 655: map[int8]int{
  122. model.PlatIPhone: 466,
  123. model.PlatIPad: 799,
  124. model.PlatAndroid: 628,
  125. model.PlatIPhoneI: 1079,
  126. model.PlatAndroidG: 1417,
  127. model.PlatAndroidI: 1859,
  128. model.PlatIPadI: 1249,
  129. },
  130. 165: map[int8]int{
  131. model.PlatIPhone: 1473,
  132. model.PlatIPad: 1485,
  133. model.PlatAndroid: 1479,
  134. model.PlatIPhoneI: 1491,
  135. model.PlatAndroidG: 1497,
  136. model.PlatAndroidI: 1873,
  137. model.PlatIPadI: 1503,
  138. },
  139. 167: map[int8]int{
  140. model.PlatIPhone: 1934,
  141. model.PlatIPad: 1932,
  142. model.PlatAndroid: 1933,
  143. },
  144. 181: map[int8]int{
  145. model.PlatIPhone: 2225,
  146. model.PlatIPad: 2239,
  147. model.PlatAndroid: 2232,
  148. },
  149. 177: map[int8]int{
  150. model.PlatIPhone: 2275,
  151. model.PlatIPad: 2289,
  152. model.PlatAndroid: 2282,
  153. },
  154. 188: map[int8]int{
  155. model.PlatIPhone: 2996,
  156. model.PlatIPad: 3008,
  157. model.PlatAndroid: 3002,
  158. model.PlatIPhoneI: 3014,
  159. model.PlatAndroidG: 3020,
  160. model.PlatAndroidI: 3032,
  161. model.PlatIPadI: 3026,
  162. },
  163. }
  164. _bannersPlat = map[int8]string{
  165. model.PlatIPhone: "454,453,455,456,457,458,459,460,462,463,464,465,466,1473,1934,2225,2275",
  166. model.PlatIPad: "788,787,789,790,791,792,793,794,795,796,797,798,799,1485,1932,2239,2289",
  167. model.PlatAndroid: "617,616,618,619,620,621,622,623,624,625,626,627,628,1479,1933,2232,2282",
  168. model.PlatIPhoneI: "1022,1017,1028,1033,1038,1043,1048,1053,1058,1063,1068,1073,1079,1491",
  169. model.PlatAndroidG: "1360,1355,1366,1371,1376,1381,1386,1391,1396,1401,1406,1411,1417,1497",
  170. model.PlatAndroidI: "1791,1785,1798,1804,1810,1816,1822,1828,1834,1840,1846,1852,1859,1873",
  171. model.PlatIPadI: "1192,1187,1198,1203,1208,1213,1218,1223,1228,1233,1238,1243,1249,1503",
  172. }
  173. _bannersPGC = map[int8]map[int]int{
  174. model.PlatAndroid: map[int]int{
  175. 13: 83,
  176. 167: 85,
  177. 177: 232,
  178. 11: 220,
  179. 23: 49,
  180. },
  181. model.PlatIPhone: map[int]int{
  182. 13: 97,
  183. 167: 98,
  184. 177: 233,
  185. 11: 221,
  186. 23: 50,
  187. },
  188. model.PlatIPad: map[int]int{
  189. 13: 332,
  190. 167: 333,
  191. 177: 334,
  192. 11: 336,
  193. 23: 335,
  194. },
  195. }
  196. )
  197. // getBanners get banners by plat, build channel, ip.
  198. func (s *Service) getBanners(c context.Context, plat int8, build, rid int, mid int64, channel, ip, buvid, network, mobiApp, device, adExtra string) (res map[string][]*banner.Banner) {
  199. var (
  200. resID = _banners[rid][plat]
  201. bs []*banner.Banner
  202. )
  203. res = map[string][]*banner.Banner{}
  204. if bs = s.bgmBanners(c, plat, rid); len(bs) == 0 {
  205. bs = s.resBanners(c, plat, build, mid, resID, channel, ip, buvid, network, mobiApp, device, adExtra)
  206. }
  207. if len(bs) > 0 {
  208. res["top"] = bs
  209. }
  210. return
  211. }
  212. // resBannersplat
  213. func (s *Service) resBanners(c context.Context, plat int8, build int, mid int64, resID int, channel, ip, buvid, network, mobiApp, device, adExtra string) (res []*banner.Banner) {
  214. var (
  215. plm = s.bannerCache[plat] // operater banner
  216. err error
  217. resbs map[int][]*resource.Banner
  218. tmp []*resource.Banner
  219. )
  220. resIDStr := strconv.Itoa(resID)
  221. if resbs, err = s.res.ResBanner(c, plat, build, mid, resIDStr, channel, ip, buvid, network, mobiApp, device, adExtra, true); err != nil || len(resbs) == 0 {
  222. log.Error("s.res.ResBanner is null or err(%v)", err)
  223. resbs = plm
  224. }
  225. tmp = resbs[resID]
  226. for _, rb := range tmp {
  227. b := &banner.Banner{}
  228. b.ResChangeBanner(rb)
  229. res = append(res, b)
  230. }
  231. return
  232. }
  233. // bgmBanners bangumi banner
  234. func (s *Service) bgmBanners(c context.Context, plat int8, rid int) (bgmBanner []*banner.Banner) {
  235. var (
  236. bgmb = s.bannerBmgCache[plat][rid]
  237. resID = _banners[rid][plat]
  238. )
  239. for i, bb := range bgmb {
  240. b := &banner.Banner{}
  241. b.BgmChangeBanner(bb)
  242. b.RequestId = strconv.FormatInt(time.Now().UnixNano()/1000000, 10)
  243. b.Index = i + 1
  244. b.ResourceID = resID
  245. bgmBanner = append(bgmBanner, b)
  246. }
  247. return
  248. }