web_feedback.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. package http
  2. import (
  3. "go-common/library/ecode"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/metadata"
  7. "strconv"
  8. )
  9. func webFeedbacks(c *bm.Context) {
  10. params := c.Request.Form
  11. stateStr := params.Get("state")
  12. tagIDStr := params.Get("tag_id")
  13. pnStr := params.Get("pn")
  14. psStr := params.Get("ps")
  15. start := params.Get("start")
  16. end := params.Get("end")
  17. platform := params.Get("platform")
  18. ip := metadata.String(c, metadata.RemoteIP)
  19. midI, ok := c.Get("mid")
  20. if !ok {
  21. c.JSON(nil, ecode.NoLogin)
  22. return
  23. }
  24. mid, _ := midI.(int64)
  25. tagID, err := strconv.ParseInt(tagIDStr, 10, 64)
  26. if err != nil {
  27. tagID = 0
  28. }
  29. pn, err := strconv.ParseInt(pnStr, 10, 64)
  30. if err != nil || pn < 1 {
  31. pn = 1
  32. }
  33. ps, err := strconv.ParseInt(psStr, 10, 64)
  34. if err != nil || pn < 1 {
  35. ps = 10
  36. }
  37. if platform == "" { //兼容老逻辑
  38. platform = "ugc"
  39. }
  40. feedbacks, count, err := fdSvc.Feedbacks(c, mid, ps, pn, tagID, stateStr, start, end, platform, ip)
  41. if err != nil {
  42. c.JSON(nil, err)
  43. return
  44. }
  45. c.JSONMap(map[string]interface{}{
  46. "data": feedbacks,
  47. "pager": map[string]int64{
  48. "pn": pn,
  49. "ps": ps,
  50. "count": count,
  51. },
  52. }, nil)
  53. }
  54. func webFeedbackAdd(c *bm.Context) {
  55. params := c.Request.Form
  56. tagIDStr := params.Get("tag_id")
  57. aid := params.Get("aid")
  58. title := params.Get("title")
  59. browser := params.Get("browser")
  60. content := params.Get("content")
  61. sessionIDStr := params.Get("session_id")
  62. qq := params.Get("qq")
  63. imgURL := params.Get("img_url")
  64. platform := params.Get("platform")
  65. ip := metadata.String(c, metadata.RemoteIP)
  66. tagID, err := strconv.ParseInt(tagIDStr, 10, 64)
  67. if err != nil {
  68. log.Error("tagID(%s) format error", tagIDStr)
  69. tagID = 0
  70. }
  71. sessionID, err := strconv.ParseInt(sessionIDStr, 10, 64)
  72. if err != nil {
  73. log.Error("sessionID(%s) format error", sessionIDStr)
  74. sessionID = 0
  75. }
  76. if content == "" {
  77. log.Error("content empty")
  78. c.JSON(nil, ecode.RequestErr)
  79. return
  80. }
  81. if sessionID == 0 && tagID == 0 {
  82. log.Error("add feedback session tag empty")
  83. c.JSON(nil, ecode.RequestErr)
  84. return
  85. }
  86. if sessionID == 0 {
  87. // add feedback
  88. content = title + "#p#" + content
  89. }
  90. midI, ok := c.Get("mid")
  91. if !ok {
  92. c.JSON(nil, ecode.NoLogin)
  93. return
  94. }
  95. mid, _ := midI.(int64)
  96. if platform == "" { //兼容老逻辑
  97. platform = "ugc"
  98. }
  99. c.JSON(nil, fdSvc.AddFeedback(c, mid, tagID, sessionID, qq, content, aid, imgURL, browser, platform, ip))
  100. }
  101. func webFeedbackDetail(c *bm.Context) {
  102. params := c.Request.Form
  103. sessionIDStr := params.Get("session_id")
  104. ip := metadata.String(c, metadata.RemoteIP)
  105. sessionID, err := strconv.ParseInt(sessionIDStr, 10, 64)
  106. if err != nil {
  107. log.Error("sessionID(%s) format error", sessionIDStr)
  108. c.JSON(nil, ecode.RequestErr)
  109. return
  110. }
  111. midI, ok := c.Get("mid")
  112. if !ok {
  113. c.JSON(nil, ecode.NoLogin)
  114. return
  115. }
  116. mid, _ := midI.(int64)
  117. feedbacks, err := fdSvc.Detail(c, mid, sessionID, ip)
  118. if err != nil {
  119. c.JSON(nil, err)
  120. return
  121. }
  122. c.JSON(feedbacks, nil)
  123. }
  124. func webFeedbackTags(c *bm.Context) {
  125. ip := metadata.String(c, metadata.RemoteIP)
  126. midI, ok := c.Get("mid")
  127. if !ok {
  128. c.JSON(nil, ecode.NoLogin)
  129. return
  130. }
  131. mid, _ := midI.(int64)
  132. tags, err := fdSvc.Tags(c, mid, ip)
  133. if err != nil {
  134. c.JSON(nil, err)
  135. return
  136. }
  137. c.JSON(tags, nil)
  138. }
  139. func webFeedbackClose(c *bm.Context) {
  140. params := c.Request.Form
  141. sessionIDStr := params.Get("session_id")
  142. ip := metadata.String(c, metadata.RemoteIP)
  143. _, ok := c.Get("mid")
  144. if !ok {
  145. c.JSON(nil, ecode.NoLogin)
  146. return
  147. }
  148. sessionID, err := strconv.ParseInt(sessionIDStr, 10, 64)
  149. if err != nil {
  150. log.Error("sessionID(%s) format error", sessionIDStr)
  151. c.JSON(nil, ecode.RequestErr)
  152. return
  153. }
  154. c.JSON(nil, fdSvc.CloseSession(c, sessionID, ip))
  155. }
  156. func webFeedbackNewTags(c *bm.Context) {
  157. ip := metadata.String(c, metadata.RemoteIP)
  158. midI, ok := c.Get("mid")
  159. if !ok {
  160. c.JSON(nil, ecode.NoLogin)
  161. return
  162. }
  163. mid, _ := midI.(int64)
  164. tags, err := fdSvc.NewTags(c, mid, ip)
  165. if err != nil {
  166. c.JSON(nil, err)
  167. return
  168. }
  169. c.JSON(tags, nil)
  170. }