web_newcomer.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. package http
  2. import (
  3. "go-common/app/interface/main/creative/model/newcomer"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/metadata"
  8. "go-common/library/xstr"
  9. )
  10. func webTaskList(c *bm.Context) {
  11. params := c.Request.Form
  12. tyStr := params.Get("type")
  13. // check user
  14. midStr, ok := c.Get("mid")
  15. if !ok {
  16. c.JSON(nil, ecode.CreativeNotLogin)
  17. return
  18. }
  19. mid := midStr.(int64)
  20. // check white list
  21. if task := whiteSvc.TaskWhiteList(mid); task != 1 {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. ty, err := toInt(tyStr)
  26. if err != nil {
  27. c.JSON(nil, err)
  28. return
  29. }
  30. tks, err := newcomerSvc.TaskList(c, mid, int8(ty))
  31. if err != nil {
  32. c.JSON(nil, err)
  33. return
  34. }
  35. c.JSON(tks, nil)
  36. }
  37. func webRewardReceive(c *bm.Context) {
  38. params := c.Request.Form
  39. ridStr := params.Get("reward_id")
  40. rewardTypeStr := params.Get("reward_type")
  41. // check user
  42. midI, ok := c.Get("mid")
  43. if !ok {
  44. c.JSON(nil, ecode.CreativeNotLogin)
  45. return
  46. }
  47. mid, _ := midI.(int64)
  48. ip := metadata.String(c, metadata.RemoteIP)
  49. var (
  50. err error
  51. rewardID int64
  52. rewardType int
  53. )
  54. rewardID, err = toInt64(ridStr)
  55. if err != nil || rewardID <= 0 {
  56. c.JSON(nil, ecode.RequestErr)
  57. return
  58. }
  59. rewardType, err = toInt(rewardTypeStr)
  60. if err != nil || rewardType < 0 {
  61. c.JSON(nil, ecode.RequestErr)
  62. return
  63. }
  64. msg, err := newcomerSvc.RewardReceive(c, mid, rewardID, int8(rewardType), ip)
  65. if err != nil {
  66. c.JSON(nil, err)
  67. return
  68. }
  69. c.JSON(map[string]interface{}{
  70. "msg": msg,
  71. }, nil)
  72. }
  73. func webRewardActivate(c *bm.Context) {
  74. params := c.Request.Form
  75. idStr := params.Get("id")
  76. // check user
  77. midI, ok := c.Get("mid")
  78. if !ok {
  79. c.JSON(nil, ecode.CreativeNotLogin)
  80. return
  81. }
  82. mid, _ := midI.(int64)
  83. id, err := toInt64(idStr)
  84. if err != nil || id <= 0 {
  85. c.JSON(nil, ecode.RequestErr)
  86. return
  87. }
  88. ip := metadata.String(c, metadata.RemoteIP)
  89. row, err := newcomerSvc.RewardActivate(c, mid, id, ip)
  90. if err != nil {
  91. c.JSON(nil, err)
  92. return
  93. }
  94. c.JSON(map[string]interface{}{
  95. "row": row,
  96. }, nil)
  97. }
  98. func webRewardReceiveList(c *bm.Context) {
  99. // check user
  100. midI, ok := c.Get("mid")
  101. if !ok {
  102. c.JSON(nil, ecode.CreativeNotLogin)
  103. return
  104. }
  105. mid, _ := midI.(int64)
  106. recs, err := newcomerSvc.RewardReceives(c, mid)
  107. if err != nil {
  108. c.JSON(nil, err)
  109. return
  110. }
  111. c.JSON(recs, nil)
  112. }
  113. func webTaskBind(c *bm.Context) {
  114. // check user
  115. midI, ok := c.Get("mid")
  116. if !ok {
  117. c.JSON(nil, ecode.CreativeNotLogin)
  118. return
  119. }
  120. mid, _ := midI.(int64)
  121. // check white list
  122. if task := whiteSvc.TaskWhiteList(mid); task != 1 {
  123. c.JSON(nil, ecode.RequestErr)
  124. return
  125. }
  126. id, err := newcomerSvc.TaskBind(c, mid)
  127. if err != nil {
  128. c.JSON(nil, err)
  129. return
  130. }
  131. c.JSON(map[string]interface{}{
  132. "id": id,
  133. }, nil)
  134. }
  135. func growAccountStateInternal(c *bm.Context) {
  136. params := c.Request.Form
  137. midsStr := params.Get("mids")
  138. var (
  139. err error
  140. mids []int64
  141. )
  142. mids, err = xstr.SplitInts(midsStr)
  143. if err != nil {
  144. log.Error("strconv.ParseInt(%s) error(%v)", midsStr, err)
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. for _, mid := range mids {
  149. pubSvc.TaskPub(mid, newcomer.MsgForGrowAccount, newcomer.MsgFinishedCount)
  150. }
  151. c.JSON(nil, nil)
  152. }
  153. //webTaskMakeup to compensation update task status
  154. func webTaskMakeup(c *bm.Context) {
  155. params := c.Request.Form
  156. // check user
  157. midStr, ok := c.Get("mid")
  158. if !ok {
  159. c.JSON(nil, ecode.CreativeNotLogin)
  160. return
  161. }
  162. mid := midStr.(int64)
  163. if !dataSvc.IsWhite(mid) {
  164. c.JSON(nil, ecode.CreativeNotLogin)
  165. return
  166. }
  167. tmid := params.Get("tmid")
  168. tid, err := toInt64(tmid)
  169. if err != nil {
  170. c.JSON(nil, ecode.RequestErr)
  171. return
  172. }
  173. // check white list
  174. if task := whiteSvc.TaskWhiteList(tid); task != 1 {
  175. c.JSON(nil, ecode.RequestErr)
  176. return
  177. }
  178. if err := newcomerSvc.TaskMakeup(c, tid); err != nil {
  179. c.JSON(nil, err)
  180. return
  181. }
  182. c.JSON("ok", nil)
  183. }
  184. // taskPubList to apply task list
  185. func taskPubList(c *bm.Context) {
  186. midI, ok := c.Get("mid")
  187. if !ok {
  188. c.JSON(nil, ecode.CreativeNotLogin)
  189. return
  190. }
  191. mid, _ := midI.(int64)
  192. data, err := newcomerSvc.TaskPubList(c, mid)
  193. if err != nil {
  194. c.JSON(nil, err)
  195. return
  196. }
  197. c.JSON(data, nil)
  198. }