region.go 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-show/model"
  6. "go-common/app/interface/main/app-show/model/region"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. var (
  12. _emptyShowItems = []*region.ShowItem{}
  13. )
  14. // regions get region data
  15. func regions(c *bm.Context) {
  16. params := c.Request.Form
  17. mobiApp := params.Get("mobi_app")
  18. mobiApp = model.MobiAPPBuleChange(mobiApp)
  19. buildStr := params.Get("build")
  20. language := params.Get("lang")
  21. ver := params.Get("ver")
  22. // check params
  23. build, err := strconv.Atoi(buildStr)
  24. if err != nil {
  25. log.Error("build(%s) error(%v)", buildStr, err)
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. device := params.Get("device")
  30. plat := model.Plat(mobiApp, device)
  31. data, version, err := regionSvc.Regions(c, plat, build, ver, mobiApp, device, language)
  32. if err == ecode.NotModified {
  33. c.JSON(nil, err)
  34. return
  35. }
  36. res := map[string]interface{}{
  37. "data": data,
  38. "ver": version,
  39. }
  40. returnDataJSON(c, res, 1, nil)
  41. }
  42. // regions get region data
  43. func regionsList(c *bm.Context) {
  44. params := c.Request.Form
  45. mobiApp := params.Get("mobi_app")
  46. mobiApp = model.MobiAPPBuleChange(mobiApp)
  47. buildStr := params.Get("build")
  48. language := params.Get("lang")
  49. entrance := params.Get("entrance")
  50. ver := params.Get("ver")
  51. // check params
  52. build, err := strconv.Atoi(buildStr)
  53. if err != nil {
  54. log.Error("build(%s) error(%v)", buildStr, err)
  55. c.JSON(nil, ecode.RequestErr)
  56. return
  57. }
  58. device := params.Get("device")
  59. plat := model.Plat(mobiApp, device)
  60. data, version, err := regionSvc.RegionsList(c, plat, build, ver, mobiApp, device, language, entrance)
  61. if err == ecode.NotModified {
  62. c.JSON(nil, err)
  63. return
  64. }
  65. res := map[string]interface{}{
  66. "data": data,
  67. "ver": version,
  68. }
  69. returnDataJSON(c, res, 1, nil)
  70. }
  71. // regions get region data
  72. func regionsIndex(c *bm.Context) {
  73. params := c.Request.Form
  74. mobiApp := params.Get("mobi_app")
  75. buildStr := params.Get("build")
  76. language := params.Get("lang")
  77. ver := params.Get("ver")
  78. // check params
  79. build, err := strconv.Atoi(buildStr)
  80. if err != nil {
  81. log.Error("build(%s) error(%v)", buildStr, err)
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. device := params.Get("device")
  86. plat := model.Plat(mobiApp, device)
  87. data, version, err := regionSvc.NewRegionList(c, plat, build, ver, mobiApp, device, language)
  88. if err == ecode.NotModified {
  89. c.JSON(nil, err)
  90. return
  91. }
  92. res := map[string]interface{}{
  93. "data": data,
  94. "ver": version,
  95. }
  96. returnDataJSON(c, res, 1, nil)
  97. }
  98. // regionShow region show
  99. func regionShow(c *bm.Context) {
  100. header := c.Request.Header
  101. params := c.Request.Form
  102. mobiApp := params.Get("mobi_app")
  103. ridStr := params.Get("rid")
  104. buildStr := params.Get("build")
  105. channel := params.Get("channel")
  106. network := params.Get("network")
  107. // check params
  108. build, err := strconv.Atoi(buildStr)
  109. if err != nil {
  110. log.Error("build(%s) error(%v)", buildStr, err)
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. rid, err := strconv.Atoi(ridStr)
  115. if err != nil {
  116. log.Error("ridStr(%s) error(%v)", ridStr, err)
  117. c.JSON(nil, ecode.RequestErr)
  118. return
  119. }
  120. var mid int64
  121. if midInter, ok := c.Get("mid"); ok {
  122. mid = midInter.(int64)
  123. }
  124. buvid := header.Get(_headerBuvid)
  125. device := params.Get("device")
  126. plat := model.Plat(mobiApp, device)
  127. adExtra := params.Get("ad_extra")
  128. // GetAudit
  129. if audit, ok := regionSvc.Audit(c, mobiApp, plat, build, rid, true); ok {
  130. returnJSON(c, audit, nil)
  131. } else {
  132. mobiApp = model.MobiAPPBuleChange(mobiApp)
  133. data := regionSvc.Show(c, plat, rid, build, mid, channel, buvid, network, mobiApp, device, adExtra)
  134. returnJSON(c, data, nil)
  135. }
  136. }
  137. // regionChildShow region childShow
  138. func regionChildShow(c *bm.Context) {
  139. params := c.Request.Form
  140. mobiApp := params.Get("mobi_app")
  141. ridStr := params.Get("rid")
  142. tagIDStr := params.Get("tag_id")
  143. buildStr := params.Get("build")
  144. channel := params.Get("channel")
  145. // check params
  146. build, err := strconv.Atoi(buildStr)
  147. if err != nil {
  148. log.Error("build(%s) error(%v)", buildStr, err)
  149. c.JSON(nil, ecode.RequestErr)
  150. return
  151. }
  152. rid, err := strconv.Atoi(ridStr)
  153. if err != nil {
  154. log.Error("ridStr(%s) error(%v)", ridStr, err)
  155. c.JSON(nil, ecode.RequestErr)
  156. return
  157. }
  158. var (
  159. mid int64
  160. tagID int
  161. )
  162. if midInter, ok := c.Get("mid"); ok {
  163. mid = midInter.(int64)
  164. }
  165. if tagIDStr != "" {
  166. if tagID, err = strconv.Atoi(tagIDStr); err != nil {
  167. log.Error("tagId(%s) error(%v)", tagID, err)
  168. c.JSON(nil, ecode.RequestErr)
  169. return
  170. }
  171. }
  172. device := params.Get("device")
  173. plat := model.Plat(mobiApp, device)
  174. // GetAudit
  175. if audit, ok := regionSvc.AuditChild(c, mobiApp, "default", plat, build, rid, tagID); ok {
  176. returnJSON(c, audit, nil)
  177. } else {
  178. mobiApp = model.MobiAPPBuleChange(mobiApp)
  179. data := regionSvc.ChildShow(c, plat, mid, rid, tagID, build, channel, mobiApp, time.Now())
  180. returnJSON(c, data, nil)
  181. }
  182. }
  183. // regionChildListShow region childlistShow
  184. func regionChildListShow(c *bm.Context) {
  185. params := c.Request.Form
  186. ridStr := params.Get("rid")
  187. tagIDStr := params.Get("tag_id")
  188. mobiApp := params.Get("mobi_app")
  189. pnStr := params.Get("pn")
  190. // psStr := params.Get("ps")
  191. orderStr := params.Get("order")
  192. buildStr := params.Get("build")
  193. build, err := strconv.Atoi(buildStr)
  194. if err != nil {
  195. log.Error("build(%s) error(%v)", buildStr, err)
  196. c.JSON(nil, ecode.RequestErr)
  197. return
  198. }
  199. rid, err := strconv.Atoi(ridStr)
  200. if err != nil {
  201. log.Error("ridStr(%s) error(%v)", ridStr, err)
  202. return
  203. }
  204. var tagID int
  205. if tagIDStr != "" {
  206. if tagID, err = strconv.Atoi(tagIDStr); err != nil {
  207. log.Error("tagId(%s) error(%v)", tagID, err)
  208. c.JSON(nil, ecode.RequestErr)
  209. return
  210. }
  211. }
  212. pn, err := strconv.Atoi(pnStr)
  213. if err != nil || pn < 1 {
  214. pn = 1
  215. }
  216. // ps, err := strconv.Atoi(psStr)
  217. // if err != nil || ps > 60 || ps <= 0 {
  218. ps := 20
  219. // }
  220. if pn*ps > 400 {
  221. returnJSON(c, _emptyShowItems, nil)
  222. return
  223. }
  224. order := ""
  225. switch orderStr {
  226. case "view":
  227. order = "click"
  228. case "reply":
  229. order = "scores"
  230. case "danmaku":
  231. order = "dm"
  232. case "favorite":
  233. order = "stow"
  234. }
  235. device := params.Get("device")
  236. plat := model.Plat(mobiApp, device)
  237. platform := params.Get("platform")
  238. var mid int64
  239. if midInter, ok := c.Get("mid"); ok {
  240. mid = midInter.(int64)
  241. }
  242. // GetAudit
  243. if audit, ok := regionSvc.AuditChildList(c, mobiApp, order, plat, build, rid, tagID, pn, ps); ok {
  244. returnJSON(c, audit, nil)
  245. } else {
  246. mobiApp = model.MobiAPPBuleChange(mobiApp)
  247. data := regionSvc.ChildListShow(c, plat, rid, tagID, pn, ps, build, mid, order, platform, mobiApp, device)
  248. returnJSON(c, data, nil)
  249. }
  250. }
  251. // regionChildListShow region childlistShow
  252. func regionShowDynamic(c *bm.Context) {
  253. params := c.Request.Form
  254. ridStr := params.Get("rid")
  255. pnStr := params.Get("pn")
  256. psStr := params.Get("ps")
  257. rid, err := strconv.Atoi(ridStr)
  258. mobiApp := params.Get("mobi_app")
  259. mobiApp = model.MobiAPPBuleChange(mobiApp)
  260. buildStr := params.Get("build")
  261. build, _ := strconv.Atoi(buildStr)
  262. device := params.Get("device")
  263. if err != nil {
  264. log.Error("ridStr(%s) error(%v)", ridStr, err)
  265. c.JSON(nil, ecode.RequestErr)
  266. return
  267. }
  268. pn, err := strconv.Atoi(pnStr)
  269. if err != nil || pn < 1 {
  270. pn = 1
  271. }
  272. ps, err := strconv.Atoi(psStr)
  273. if err != nil || ps > 50 || ps <= 0 {
  274. ps = 50
  275. }
  276. if pn*ps > 200 {
  277. returnJSON(c, _emptyShowItems, nil)
  278. return
  279. }
  280. plat := model.Plat(mobiApp, device)
  281. data := regionSvc.ShowDynamic(c, plat, build, rid, pn, ps)
  282. returnJSON(c, data, nil)
  283. }
  284. func regionDynamic(c *bm.Context) {
  285. header := c.Request.Header
  286. params := c.Request.Form
  287. mobiApp := params.Get("mobi_app")
  288. ridStr := params.Get("rid")
  289. buildStr := params.Get("build")
  290. channel := params.Get("channel")
  291. network := params.Get("network")
  292. // check params
  293. build, err := strconv.Atoi(buildStr)
  294. if err != nil {
  295. log.Error("build(%s) error(%v)", buildStr, err)
  296. c.JSON(nil, ecode.RequestErr)
  297. return
  298. }
  299. rid, err := strconv.Atoi(ridStr)
  300. if err != nil {
  301. log.Error("ridStr(%s) error(%v)", ridStr, err)
  302. c.JSON(nil, ecode.RequestErr)
  303. return
  304. }
  305. var mid int64
  306. if midInter, ok := c.Get("mid"); ok {
  307. mid = midInter.(int64)
  308. }
  309. buvid := header.Get(_headerBuvid)
  310. device := params.Get("device")
  311. plat := model.Plat(mobiApp, device)
  312. adExtra := params.Get("ad_extra")
  313. // GetAudit
  314. if audit, ok := regionSvc.Audit(c, mobiApp, plat, build, rid, true); ok {
  315. returnJSON(c, audit, nil)
  316. } else {
  317. mobiApp = model.MobiAPPBuleChange(mobiApp)
  318. data := regionSvc.Dynamic(c, plat, rid, build, mid, channel, buvid, network, mobiApp, device, adExtra, time.Now())
  319. returnJSON(c, data, nil)
  320. }
  321. }
  322. func regionDynamicList(c *bm.Context) {
  323. params := c.Request.Form
  324. mobiApp := params.Get("mobi_app")
  325. ridStr := params.Get("rid")
  326. pullStr := params.Get("pull")
  327. ctimeStr := params.Get("ctime")
  328. buildStr := params.Get("build")
  329. build, err := strconv.Atoi(buildStr)
  330. if err != nil {
  331. log.Error("build(%s) error(%v)", buildStr, err)
  332. c.JSON(nil, ecode.RequestErr)
  333. return
  334. }
  335. rid, err := strconv.Atoi(ridStr)
  336. if err != nil {
  337. log.Error("ridStr(%s) error(%v)", ridStr, err)
  338. c.JSON(nil, ecode.RequestErr)
  339. return
  340. }
  341. pull, err := strconv.ParseBool(pullStr)
  342. if err != nil {
  343. log.Error("pullStr(%s) error(%v)", pullStr, err)
  344. c.JSON(nil, ecode.RequestErr)
  345. return
  346. }
  347. // ctime
  348. ctime, err := strconv.ParseInt(ctimeStr, 10, 64)
  349. if err != nil || ctime < 0 {
  350. ctime = 0
  351. }
  352. device := params.Get("device")
  353. plat := model.Plat(mobiApp, device)
  354. var mid int64
  355. if midInter, ok := c.Get("mid"); ok {
  356. mid = midInter.(int64)
  357. }
  358. // GetAudit
  359. if _, ok := regionSvc.Audit(c, mobiApp, plat, build, rid, false); ok {
  360. data := map[string]interface{}{}
  361. returnJSON(c, data, nil)
  362. } else {
  363. mobiApp = model.MobiAPPBuleChange(mobiApp)
  364. data := regionSvc.DynamicList(c, plat, rid, pull, ctime, mid, time.Now())
  365. returnJSON(c, data, nil)
  366. }
  367. }
  368. func regionDynamicChild(c *bm.Context) {
  369. params := c.Request.Form
  370. mobiApp := params.Get("mobi_app")
  371. ridStr := params.Get("rid")
  372. buildStr := params.Get("build")
  373. tagIDStr := params.Get("tag_id")
  374. // check params
  375. build, err := strconv.Atoi(buildStr)
  376. if err != nil {
  377. log.Error("build(%s) error(%v)", buildStr, err)
  378. c.JSON(nil, ecode.RequestErr)
  379. return
  380. }
  381. rid, err := strconv.Atoi(ridStr)
  382. if err != nil {
  383. log.Error("ridStr(%s) error(%v)", ridStr, err)
  384. c.JSON(nil, ecode.RequestErr)
  385. return
  386. }
  387. var mid int64
  388. if midInter, ok := c.Get("mid"); ok {
  389. mid = midInter.(int64)
  390. }
  391. device := params.Get("device")
  392. plat := model.Plat(mobiApp, device)
  393. var tagID int
  394. if tagIDStr != "" {
  395. if tagID, err = strconv.Atoi(tagIDStr); err != nil {
  396. log.Error("tagId(%s) error(%v)", tagID, err)
  397. c.JSON(nil, ecode.RequestErr)
  398. return
  399. }
  400. }
  401. // GetAudit
  402. if audit, ok := regionSvc.AuditChild(c, mobiApp, "", plat, build, rid, tagID); ok {
  403. returnJSON(c, audit, nil)
  404. } else {
  405. mobiApp = model.MobiAPPBuleChange(mobiApp)
  406. data := regionSvc.DynamicChild(c, plat, rid, tagID, build, mid, mobiApp, time.Now())
  407. returnJSON(c, data, nil)
  408. }
  409. }
  410. func regionDynamicChildList(c *bm.Context) {
  411. params := c.Request.Form
  412. mobiApp := params.Get("mobi_app")
  413. ridStr := params.Get("rid")
  414. pullStr := params.Get("pull")
  415. ctimeStr := params.Get("ctime")
  416. buildStr := params.Get("build")
  417. tagIDStr := params.Get("tag_id")
  418. build, err := strconv.Atoi(buildStr)
  419. if err != nil {
  420. log.Error("build(%s) error(%v)", buildStr, err)
  421. c.JSON(nil, ecode.RequestErr)
  422. return
  423. }
  424. rid, err := strconv.Atoi(ridStr)
  425. if err != nil {
  426. log.Error("ridStr(%s) error(%v)", ridStr, err)
  427. c.JSON(nil, ecode.RequestErr)
  428. return
  429. }
  430. pull, err := strconv.ParseBool(pullStr)
  431. if err != nil {
  432. log.Error("pullStr(%s) error(%v)", pullStr, err)
  433. c.JSON(nil, ecode.RequestErr)
  434. return
  435. }
  436. // ctime
  437. ctime, err := strconv.ParseInt(ctimeStr, 10, 64)
  438. if err != nil || ctime < 0 {
  439. ctime = 0
  440. }
  441. var tagID int
  442. if tagIDStr != "" {
  443. if tagID, err = strconv.Atoi(tagIDStr); err != nil {
  444. log.Error("tagId(%s) error(%v)", tagID, err)
  445. c.JSON(nil, ecode.RequestErr)
  446. return
  447. }
  448. }
  449. var mid int64
  450. if midInter, ok := c.Get("mid"); ok {
  451. mid = midInter.(int64)
  452. }
  453. device := params.Get("device")
  454. plat := model.Plat(mobiApp, device)
  455. // GetAudit
  456. if audit, ok := regionSvc.AuditChild(c, mobiApp, "", plat, build, rid, tagID); ok {
  457. returnJSON(c, audit, nil)
  458. } else {
  459. mobiApp = model.MobiAPPBuleChange(mobiApp)
  460. data := regionSvc.DynamicListChild(c, plat, rid, tagID, build, pull, ctime, mid, time.Now())
  461. returnJSON(c, data, nil)
  462. }
  463. }