h5_task.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. "go-common/library/log"
  5. "go-common/library/net/metadata"
  6. bm "go-common/library/net/http/blademaster"
  7. "strings"
  8. )
  9. func h5TaskBind(c *bm.Context) {
  10. // check user
  11. midI, ok := c.Get("mid")
  12. if !ok {
  13. c.JSON(nil, ecode.CreativeNotLogin)
  14. return
  15. }
  16. mid, _ := midI.(int64)
  17. // check white list
  18. if task := whiteSvc.TaskWhiteList(mid); task != 1 {
  19. c.JSON(nil, ecode.RequestErr)
  20. return
  21. }
  22. id, err := newcomerSvc.TaskBind(c, mid)
  23. if err != nil {
  24. c.JSON(nil, err)
  25. return
  26. }
  27. c.JSON(map[string]interface{}{
  28. "id": id,
  29. }, nil)
  30. }
  31. func h5TaskList(c *bm.Context) {
  32. params := c.Request.Form
  33. // check user
  34. midStr, ok := c.Get("mid")
  35. if !ok {
  36. c.JSON(nil, ecode.CreativeNotLogin)
  37. return
  38. }
  39. mid := midStr.(int64)
  40. // check white list
  41. if task := whiteSvc.TaskWhiteList(mid); task != 1 {
  42. log.Warn("h5TaskList whiteSvc.TaskWhiteList mid(%d)", mid)
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. from := params.Get("from")
  47. if !strings.EqualFold(from, "ios") && !strings.EqualFold(from, "android") {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. tks, err := newcomerSvc.H5TaskList(c, mid, from)
  52. if err != nil {
  53. c.JSON(nil, err)
  54. return
  55. }
  56. c.JSON(tks, nil)
  57. }
  58. func h5RewardReceive(c *bm.Context) {
  59. params := c.Request.Form
  60. ridStr := params.Get("reward_id")
  61. rewardTypeStr := params.Get("reward_type")
  62. // check user
  63. midI, ok := c.Get("mid")
  64. if !ok {
  65. c.JSON(nil, ecode.CreativeNotLogin)
  66. return
  67. }
  68. mid, _ := midI.(int64)
  69. ip := metadata.String(c, metadata.RemoteIP)
  70. var (
  71. err error
  72. rewardID int64
  73. rewardType int
  74. )
  75. rewardID, err = toInt64(ridStr)
  76. if err != nil || rewardID <= 0 {
  77. c.JSON(nil, ecode.RequestErr)
  78. return
  79. }
  80. rewardType, err = toInt(rewardTypeStr)
  81. if err != nil || rewardType < 0 {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. msg, err := newcomerSvc.RewardReceive(c, mid, rewardID, int8(rewardType), ip)
  86. if err != nil {
  87. c.JSON(nil, err)
  88. return
  89. }
  90. c.JSON(map[string]interface{}{
  91. "msg": msg,
  92. }, nil)
  93. }
  94. func h5RewardActivate(c *bm.Context) {
  95. params := c.Request.Form
  96. idStr := params.Get("id")
  97. // check user
  98. midI, ok := c.Get("mid")
  99. if !ok {
  100. c.JSON(nil, ecode.CreativeNotLogin)
  101. return
  102. }
  103. mid, _ := midI.(int64)
  104. id, err := toInt64(idStr)
  105. if err != nil || id <= 0 {
  106. c.JSON(nil, ecode.RequestErr)
  107. return
  108. }
  109. ip := metadata.String(c, metadata.RemoteIP)
  110. row, err := newcomerSvc.RewardActivate(c, mid, id, ip)
  111. if err != nil {
  112. c.JSON(nil, err)
  113. return
  114. }
  115. c.JSON(map[string]interface{}{
  116. "row": row,
  117. }, nil)
  118. }
  119. func h5RewardReceiveList(c *bm.Context) {
  120. // check user
  121. midI, ok := c.Get("mid")
  122. if !ok {
  123. c.JSON(nil, ecode.CreativeNotLogin)
  124. return
  125. }
  126. mid, _ := midI.(int64)
  127. recs, err := newcomerSvc.RewardReceives(c, mid)
  128. if err != nil {
  129. c.JSON(nil, err)
  130. return
  131. }
  132. c.JSON(recs, nil)
  133. }