app_bgm.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package http
  2. import (
  3. "go-common/app/interface/main/creative/model/app"
  4. mMdl "go-common/app/interface/main/creative/model/music"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "strconv"
  8. )
  9. // prepare ext data for bgm-detail pager
  10. func appBgmExt(c *bm.Context) {
  11. midStr, _ := c.Get("mid")
  12. mid := midStr.(int64)
  13. if mid <= 0 {
  14. c.JSON(nil, ecode.CreativeNotLogin)
  15. return
  16. }
  17. params := c.Request.Form
  18. sidStr := params.Get("sid")
  19. var (
  20. sid int64
  21. err error
  22. ext *mMdl.BgmExt
  23. )
  24. sid, err = strconv.ParseInt(sidStr, 10, 64)
  25. if err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. ext, err = musicSvc.BgmExt(c, mid, sid)
  30. if err != nil {
  31. c.JSON(nil, ecode.RequestErr)
  32. return
  33. }
  34. c.JSON(ext, nil)
  35. }
  36. func appBgmPre(c *bm.Context) {
  37. midStr, _ := c.Get("mid")
  38. mid := midStr.(int64)
  39. if mid <= 0 {
  40. c.JSON(nil, ecode.CreativeNotLogin)
  41. return
  42. }
  43. params := c.Request.Form
  44. fromStr := params.Get("from")
  45. from, _ := strconv.Atoi(fromStr)
  46. if _, ok := app.BgmFrom[from]; !ok {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. c.JSON(map[string]interface{}{
  51. "typelist": musicSvc.PreByFrom(c, from),
  52. "hotword": musicSvc.Hotwords,
  53. }, nil)
  54. }
  55. func appBgmList(c *bm.Context) {
  56. midStr, _ := c.Get("mid")
  57. mid := midStr.(int64)
  58. if mid <= 0 {
  59. c.JSON(nil, ecode.CreativeNotLogin)
  60. return
  61. }
  62. params := c.Request.Form
  63. tidStr := params.Get("tid")
  64. tid, err := strconv.Atoi(tidStr)
  65. if err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. c.JSON(musicSvc.BgmList(c, tid), nil)
  70. }
  71. func arcBgmList(c *bm.Context) {
  72. v := new(struct {
  73. AID int64 `form:"aid" validate:"required"`
  74. CID int64 `form:"cid" validate:"required"`
  75. Cache bool `form:"cache"`
  76. })
  77. if err := c.Bind(v); err != nil {
  78. return
  79. }
  80. res, err := pubSvc.BgmBindList(c, v.AID, v.CID, 3, true)
  81. if err != nil {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. c.JSON(res, nil)
  86. }
  87. func appBgmSearch(c *bm.Context) {
  88. midStr, _ := c.Get("mid")
  89. mid := midStr.(int64)
  90. if mid <= 0 {
  91. c.JSON(nil, ecode.CreativeNotLogin)
  92. return
  93. }
  94. params := c.Request.Form
  95. pnStr := params.Get("pn")
  96. psStr := params.Get("ps")
  97. kw := params.Get("kw")
  98. pn, _ := strconv.Atoi(pnStr)
  99. if pn < 1 {
  100. pn = 1
  101. }
  102. ps, _ := strconv.Atoi(psStr)
  103. if ps > 20 || ps < 0 {
  104. ps = 20
  105. }
  106. c.JSON(musicSvc.BgmSearch(c, kw, mid, pn, ps), nil)
  107. }
  108. func appBgmView(c *bm.Context) {
  109. midStr, _ := c.Get("mid")
  110. mid := midStr.(int64)
  111. if mid <= 0 {
  112. c.JSON(nil, ecode.CreativeNotLogin)
  113. return
  114. }
  115. params := c.Request.Form
  116. sidStr := params.Get("sid")
  117. sid, err := strconv.ParseInt(sidStr, 10, 64)
  118. if err != nil {
  119. c.JSON(nil, ecode.RequestErr)
  120. return
  121. }
  122. c.JSON(musicSvc.BgmView(c, sid), nil)
  123. }
  124. func appMaterialPre(c *bm.Context) {
  125. midStr, _ := c.Get("mid")
  126. mid := midStr.(int64)
  127. if mid <= 0 {
  128. c.JSON(nil, ecode.CreativeNotLogin)
  129. return
  130. }
  131. params := c.Request.Form
  132. buildStr := params.Get("build")
  133. build, _ := strconv.Atoi(buildStr)
  134. plat := params.Get("platform")
  135. c.JSON(musicSvc.MaterialPre(c, mid, plat, build), nil)
  136. }
  137. func appMaterial(c *bm.Context) {
  138. midStr, _ := c.Get("mid")
  139. mid := midStr.(int64)
  140. if mid <= 0 {
  141. c.JSON(nil, ecode.CreativeNotLogin)
  142. return
  143. }
  144. params := c.Request.Form
  145. idStr := params.Get("id")
  146. id, _ := strconv.ParseInt(idStr, 10, 64)
  147. tpStr := params.Get("type")
  148. tp, _ := strconv.Atoi(tpStr)
  149. c.JSONMap(map[string]interface{}{
  150. "data": musicSvc.Material(c, id, int8(tp), mid),
  151. }, nil)
  152. }
  153. func appMissionByType(c *bm.Context) {
  154. midStr, _ := c.Get("mid")
  155. mid := midStr.(int64)
  156. if mid <= 0 {
  157. c.JSON(nil, ecode.CreativeNotLogin)
  158. return
  159. }
  160. params := c.Request.Form
  161. tidStr := params.Get("tid")
  162. tid, _ := strconv.Atoi(tidStr)
  163. actWithTP, _ := arcSvc.MissionOnlineByTid(c, int16(tid), 1)
  164. c.JSON(actWithTP, nil)
  165. }
  166. func appH5BgmFeedback(c *bm.Context) {
  167. midStr, _ := c.Get("mid")
  168. mid := midStr.(int64)
  169. if mid <= 0 {
  170. c.JSON(nil, ecode.CreativeNotLogin)
  171. return
  172. }
  173. var err error
  174. v := new(struct {
  175. Name string `form:"name"`
  176. Musicians string `form:"musicians"`
  177. })
  178. if err = c.Bind(v); err != nil {
  179. return
  180. }
  181. if len(v.Name) == 0 && len(v.Musicians) == 0 {
  182. c.JSON(nil, ecode.RequestErr)
  183. return
  184. }
  185. c.JSON(musicSvc.AddBgmFeedBack(c, v.Name, v.Musicians, "h5", mid), nil)
  186. }