audit.go 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  1. package show
  2. import (
  3. "context"
  4. "strconv"
  5. cdm "go-common/app/interface/main/app-card/model"
  6. cardm "go-common/app/interface/main/app-card/model/card"
  7. "go-common/app/interface/main/app-card/model/card/ai"
  8. operate "go-common/app/interface/main/app-card/model/card/operate"
  9. "go-common/app/interface/main/app-show/model"
  10. "go-common/app/interface/main/app-show/model/banner"
  11. "go-common/app/interface/main/app-show/model/feed"
  12. "go-common/app/interface/main/app-show/model/show"
  13. "go-common/app/service/main/archive/api"
  14. "go-common/app/service/main/archive/model/archive"
  15. "go-common/library/log"
  16. )
  17. var (
  18. _auditBanner = &banner.Banner{
  19. Title: "充电",
  20. Image: "http://i0.hdslb.com/bfs/archive/9ce8f6cdf76e6cbd50ce7db76262d5a35e594c79.png",
  21. Hash: "3c4990d06c46de0080e3821fca6bedca",
  22. URI: "bilibili://video/813060",
  23. }
  24. _auditRids = map[int8]map[string]struct{}{
  25. model.PlatIPhone: map[string]struct{}{
  26. "13": struct{}{},
  27. "167": struct{}{},
  28. "177": struct{}{},
  29. "23": struct{}{},
  30. "11": struct{}{},
  31. },
  32. }
  33. )
  34. // GetAudit check audit plat and ip, then return audit data.
  35. func (s *Service) Audit(c context.Context, mobiApp string, plat int8, build int) (ss []*show.Show, ok bool) {
  36. if plats, ok := s.auditCache[mobiApp]; ok {
  37. if _, ok = plats[build]; ok {
  38. return s.auditData(c, plat), true
  39. }
  40. }
  41. return nil, false
  42. }
  43. func (s *Service) AuditChild(c context.Context, mobiApp string, plat int8, build int) (res []*show.Item, ok bool) {
  44. if plats, ok := s.auditCache[mobiApp]; ok {
  45. if _, ok = plats[build]; ok {
  46. res = s.auditList(c)
  47. return res, true
  48. }
  49. }
  50. return nil, false
  51. }
  52. // AuditFeed check audit plat and ip, then return audit data.
  53. func (s *Service) AuditFeed(c context.Context, mobiApp string, plat int8, build int) (res []*feed.Item, ok bool) {
  54. if plats, ok := s.auditCache[mobiApp]; ok {
  55. if _, ok = plats[build]; ok {
  56. return s.auditFeed(c), true
  57. }
  58. }
  59. return nil, false
  60. }
  61. // AuditFeed check audit plat and ip, then return audit data.
  62. func (s *Service) AuditFeed2(c context.Context, mobiApp string, plat int8, build int) (res []cardm.Handler, ok bool) {
  63. if plats, ok := s.auditCache[mobiApp]; ok {
  64. if _, ok = plats[build]; ok {
  65. return s.auditFeed2(c, plat), true
  66. }
  67. }
  68. return nil, false
  69. }
  70. // Audit region data list.
  71. func (s *Service) auditRegion(mobiApp string, plat int8, build int, rid string) (isAudit bool) {
  72. if plats, ok := s.auditCache[mobiApp]; ok {
  73. if _, ok = plats[build]; ok {
  74. if params, ok := _auditRids[plat]; ok {
  75. if _, ok = params[rid]; ok {
  76. return true
  77. }
  78. }
  79. }
  80. }
  81. return false
  82. }
  83. func (s *Service) loadAuditCache() {
  84. as, err := s.adt.Audits(context.TODO())
  85. if err != nil {
  86. log.Error("s.adt.Audits error(%v)", err)
  87. return
  88. }
  89. s.auditCache = as
  90. }
  91. // auditData some data for audit.
  92. func (s *Service) auditData(c context.Context, p int8) (ss []*show.Show) {
  93. ss = []*show.Show{
  94. &show.Show{
  95. Head: &show.Head{
  96. Param: "",
  97. Type: "recommend",
  98. Style: "medium",
  99. Title: "热门推荐",
  100. },
  101. },
  102. &show.Show{
  103. Head: &show.Head{
  104. Param: "3",
  105. Type: "region",
  106. Style: "medium",
  107. Title: "音乐区",
  108. },
  109. },
  110. &show.Show{
  111. Head: &show.Head{
  112. Param: "129",
  113. Type: "region",
  114. Style: "medium",
  115. Title: "舞蹈区",
  116. },
  117. },
  118. &show.Show{
  119. Head: &show.Head{
  120. Param: "4",
  121. Type: "region",
  122. Style: "medium",
  123. Title: "游戏区",
  124. },
  125. },
  126. &show.Show{
  127. Head: &show.Head{
  128. Param: "36",
  129. Type: "region",
  130. Style: "medium",
  131. Title: "游戏区",
  132. },
  133. },
  134. }
  135. aids := []int64{308040, 2431658, 2432648, 2427553, 539600, 1968681, 850424, 887861, 1960912, 1935680, 1406019, 1985297, 1977493, 2312184, 2316891, 864845, 1986932, 2314237, 880857, 875624}
  136. n := 4
  137. if p == model.PlatIPad {
  138. aids = []int64{2455179, 2473608, 1711253, 2476389, 0, 0, 0, 0, 308040, 360940, 482844, 221107, 539600, 1968681, 850424, 887861, 936016, 1773160, 886841, 1958897, 1960912, 1935680,
  139. 1406019, 1985297, 1635344, 572952, 2316655, 2317928, 1977493, 2312184, 2316891, 864845, 2313588, 875076, 2312249, 842756, 1986932, 2314237, 880857, 875624}
  140. n = 8
  141. // ss[0].Head.Type = ""
  142. // banner
  143. ss[0].Banner = map[string][]*banner.Banner{
  144. "top": []*banner.Banner{_auditBanner, _auditBanner},
  145. }
  146. } else if p == model.PlatIPhone {
  147. aids = []int64{308040, 2431658, 2432648, 2427553, 2455179, 2473608, 539600, 1968681, 850424, 887861, 0, 0, 1960912, 1935680, 1406019, 1985297, 0, 0, 1977493, 2312184, 2316891, 864845, 0, 0,
  148. 1986932, 2314237, 880857, 875624, 0, 0}
  149. n = 6
  150. // banner
  151. ss[0].Banner = map[string][]*banner.Banner{
  152. "top": []*banner.Banner{_auditBanner},
  153. }
  154. }
  155. as, err := s.arc.ArchivesPB(c, aids)
  156. if err != nil {
  157. log.Error("s.arc.ArchivesPB error(%v)", err)
  158. as = map[int64]*api.Arc{}
  159. }
  160. for i, aid := range aids {
  161. if aid == 0 {
  162. continue
  163. }
  164. item := &show.Item{}
  165. item.Goto = model.GotoAv
  166. item.Param = strconv.FormatInt(aid, 10)
  167. item.URI = model.FillURI(item.Goto, item.Param, nil)
  168. if a, ok := as[aid]; ok {
  169. item.Title = a.Title
  170. item.Cover = a.Pic
  171. item.Play = int(a.Stat.View)
  172. item.Danmaku = int(a.Stat.Danmaku)
  173. }
  174. ss[i/n].Body = append(ss[i/n].Body, item)
  175. }
  176. return
  177. }
  178. func (s *Service) auditList(c context.Context) (ss []*show.Item) {
  179. aids := []int64{308040, 2431658, 2432648, 2427553, 2455179, 2473608, 539600, 1968681, 850424, 887861, 1960912, 1935680, 1406019, 1985297, 1977493, 2312184, 2316891, 864845,
  180. 1986932, 2314237, 880857, 875624}
  181. as, err := s.arc.ArchivesPB(c, aids)
  182. if err != nil {
  183. log.Error("s.arc.ArchivesPB error(%v)", err)
  184. as = map[int64]*api.Arc{}
  185. }
  186. for _, aid := range aids {
  187. if aid == 0 {
  188. continue
  189. }
  190. item := &show.Item{}
  191. item.Goto = model.GotoAv
  192. item.Param = strconv.FormatInt(aid, 10)
  193. item.URI = model.FillURI(item.Goto, item.Param, nil)
  194. if a, ok := as[aid]; ok {
  195. item.Title = a.Title
  196. item.Cover = a.Pic
  197. item.Play = int(a.Stat.View)
  198. item.Danmaku = int(a.Stat.Danmaku)
  199. }
  200. ss = append(ss, item)
  201. }
  202. return
  203. }
  204. func (s *Service) auditFeed(c context.Context) (res []*feed.Item) {
  205. var (
  206. aids = []int64{2455179, 2473608, 1711253, 2476389, 0, 0, 0, 0, 308040, 360940, 482844, 221107, 539600, 1968681, 850424, 887861, 936016, 1773160, 886841, 1958897, 1960912, 1935680,
  207. 1406019, 1985297, 1635344, 572952, 2316655, 2317928, 1977493, 2312184, 2316891, 864845, 2313588, 875076, 2312249, 842756, 1986932, 2314237, 880857, 875624}
  208. as map[int64]*api.Arc
  209. err error
  210. )
  211. if as, err = s.arc.ArchivesPB(c, aids); err != nil {
  212. log.Error("hottab s.arc.ArchivesPB aids(%v) error(%v)", aids, err)
  213. return
  214. }
  215. if len(as) == 0 {
  216. log.Warn("hottab s.arc.ArchivesPB(%v) length is 0", aids)
  217. return
  218. }
  219. for i, aid := range aids {
  220. item := &feed.Item{}
  221. item.Idx = int64(i + 1)
  222. item.Pos = i + 1
  223. if aid == 0 {
  224. continue
  225. }
  226. if a, ok := as[aid]; ok {
  227. item.FromPlayerAv(a, "")
  228. // if tag, ok := s.hotArcTag[a.Aid]; ok {
  229. // item.Tag = &feed.Tag{TagID: tag.ID, TagName: tag.Name}
  230. // }
  231. item.Goto = model.GotoAv
  232. res = append(res, item)
  233. }
  234. }
  235. if len(res) == 0 {
  236. res = _emptyList
  237. return
  238. }
  239. return
  240. }
  241. func (s *Service) auditFeed2(c context.Context, plat int8) (res []cardm.Handler) {
  242. var (
  243. aids = []int64{2455179, 2473608, 1711253, 2476389, 0, 0, 0, 0, 308040, 360940, 482844, 221107, 539600, 1968681, 850424, 887861, 936016, 1773160, 886841, 1958897, 1960912, 1935680,
  244. 1406019, 1985297, 1635344, 572952, 2316655, 2317928, 1977493, 2312184, 2316891, 864845, 2313588, 875076, 2312249, 842756, 1986932, 2314237, 880857, 875624}
  245. as map[int64]*api.Arc
  246. err error
  247. )
  248. if as, err = s.arc.ArchivesPB(c, aids); err != nil {
  249. log.Error("hottab s.arc.ArchivesPB aids(%v) error(%v)", aids, err)
  250. return
  251. }
  252. if len(as) == 0 {
  253. log.Warn("hottab s.arc.ArchivesPB(%v) length is 0", aids)
  254. return
  255. }
  256. for i, aid := range aids {
  257. if aid == 0 {
  258. continue
  259. }
  260. var (
  261. r = &ai.Item{Goto: model.GotoAv, ID: aid}
  262. h = cardm.Handle(plat, cdm.CardGt(r.Goto), "", 1, r, nil, nil, nil, nil)
  263. main interface{}
  264. )
  265. if h == nil {
  266. continue
  267. }
  268. op := &operate.Card{}
  269. op.From(cdm.CardGt(r.Goto), r.ID, 0, model.PlatIPhone, 0)
  270. if a, ok := as[aid]; ok && (a.AttrVal(archive.AttrBitOverseaLock) == 0) {
  271. main = map[int64]*archive.ArchiveWithPlayer{a.Aid: &archive.ArchiveWithPlayer{Archive3: archive.BuildArchive3(a)}}
  272. }
  273. if main != nil {
  274. h.From(main, op)
  275. }
  276. h.Get().Idx = int64(i + 1)
  277. if h.Get().Right {
  278. res = append(res, h)
  279. }
  280. }
  281. if len(res) == 0 {
  282. res = _emptyList2
  283. return
  284. }
  285. return
  286. }