splash.go 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/interface/main/app-resource/model"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. // splashs splash handler
  11. func splashs(c *bm.Context) {
  12. params := c.Request.Form
  13. mobiApp := params.Get("mobi_app")
  14. mobiApp = model.MobiAPPBuleChange(mobiApp)
  15. widthStr := params.Get("width")
  16. heightStr := params.Get("height")
  17. buildStr := params.Get("build")
  18. channel := params.Get("channel")
  19. ver := params.Get("ver")
  20. // check params
  21. width, err := strconv.Atoi(widthStr)
  22. if err != nil {
  23. log.Error("width(%s) is invalid", widthStr)
  24. c.JSON(nil, ecode.RequestErr)
  25. return
  26. }
  27. height, err := strconv.Atoi(heightStr)
  28. if err != nil {
  29. log.Error("height(%s) is invalid", heightStr)
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. build, _ := strconv.Atoi(buildStr)
  34. device := params.Get("device")
  35. var plat int8
  36. if mobiApp != "" {
  37. plat = model.Plat(mobiApp, device)
  38. } else {
  39. plat = model.PlatAndroid
  40. }
  41. result, version, err := splashSvc.Display(c, plat, width, height, int(build), channel, ver, time.Now())
  42. res := map[string]interface{}{
  43. "data": result,
  44. "ver": version,
  45. }
  46. c.JSONMap(res, err)
  47. }
  48. func birthSplash(c *bm.Context) {
  49. params := c.Request.Form
  50. mobiApp := params.Get("mobi_app")
  51. mobiApp = model.MobiAPPBuleChange(mobiApp)
  52. widthStr := params.Get("width")
  53. heightStr := params.Get("height")
  54. year := params.Get("year")
  55. birth := params.Get("birth")
  56. if year == "1930" && birth == "0101" {
  57. log.Error("birth day is empty(%s,%s)", year, birth)
  58. c.JSON(nil, ecode.NothingFound)
  59. return
  60. }
  61. // check params
  62. width, err := strconv.Atoi(widthStr)
  63. if err != nil {
  64. log.Error("width(%s) is invalid", widthStr)
  65. c.JSON(nil, ecode.RequestErr)
  66. return
  67. }
  68. height, err := strconv.Atoi(heightStr)
  69. if err != nil {
  70. log.Error("height(%s) is invalid", heightStr)
  71. c.JSON(nil, ecode.RequestErr)
  72. return
  73. }
  74. device := params.Get("device")
  75. plat := model.Plat(mobiApp, device)
  76. result, err := splashSvc.Birthday(c, plat, width, height, birth)
  77. c.JSON(result, err)
  78. }
  79. // splashList ad splash handler
  80. func splashList(c *bm.Context) {
  81. var (
  82. header = c.Request.Header
  83. params = c.Request.Form
  84. )
  85. mobiApp := params.Get("mobi_app")
  86. mobiApp = model.MobiAPPBuleChange(mobiApp)
  87. widthStr := params.Get("width")
  88. heightStr := params.Get("height")
  89. buildStr := params.Get("build")
  90. birth := params.Get("birth")
  91. adExtra := params.Get("ad_extra")
  92. device := params.Get("device")
  93. // check params
  94. width, err := strconv.Atoi(widthStr)
  95. if err != nil {
  96. log.Error("width(%s) is invalid", widthStr)
  97. c.JSON(nil, ecode.RequestErr)
  98. return
  99. }
  100. height, err := strconv.Atoi(heightStr)
  101. if err != nil {
  102. log.Error("height(%s) is invalid", heightStr)
  103. c.JSON(nil, ecode.RequestErr)
  104. return
  105. }
  106. build, _ := strconv.Atoi(buildStr)
  107. var mid int64
  108. if midInter, ok := c.Get("mid"); ok {
  109. mid = midInter.(int64)
  110. }
  111. buvid := header.Get(_headerBuvid)
  112. plat := model.Plat(mobiApp, device)
  113. result, err := splashSvc.AdList(c, plat, mobiApp, device, buvid, birth, adExtra, height, width, build, mid)
  114. c.JSON(result, err)
  115. }