report.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/interface/main/dm/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. "go-common/library/xstr"
  9. )
  10. const (
  11. _maxContentLen = 100
  12. )
  13. func addReport(c *bm.Context) {
  14. var (
  15. p = c.Request.Form
  16. err error
  17. cid, dmid int64
  18. reason int64
  19. )
  20. mid, _ := c.Get("mid")
  21. if cid, err = strconv.ParseInt(p.Get("cid"), 10, 64); err != nil {
  22. c.JSON(nil, ecode.RequestErr)
  23. return
  24. }
  25. if dmid, err = strconv.ParseInt(p.Get("dmid"), 10, 64); err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. if reason, err = strconv.ParseInt(p.Get("reason"), 10, 8); err != nil {
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. if int8(reason) > model.ReportReasonTeenagers {
  34. c.JSON(nil, ecode.DMReportReasonError)
  35. return
  36. }
  37. content := p.Get("content")
  38. if len([]rune(content)) > _maxContentLen {
  39. c.JSON(nil, ecode.DMReportReasonTooLong)
  40. return
  41. }
  42. if _, err = dmSvc.AddReport(c, cid, dmid, mid.(int64), int8(reason), content); err != nil {
  43. log.Error("dmSvc.AddReport(cid:%d, dmid:%d, mid:%v) error(%v)", cid, dmid, mid, err)
  44. c.JSON(nil, err)
  45. return
  46. }
  47. res := map[string]interface{}{}
  48. res["message"] = ""
  49. c.JSONMap(res, err)
  50. }
  51. func addReport2(c *bm.Context) {
  52. var (
  53. p = c.Request.Form
  54. err error
  55. cid int64
  56. reason int64
  57. dmids []int64
  58. ok2 bool
  59. )
  60. mid, _ := c.Get("mid")
  61. if cid, err = strconv.ParseInt(p.Get("cid"), 10, 64); err != nil {
  62. c.JSON(nil, ecode.RequestErr)
  63. return
  64. }
  65. if dmids, err = xstr.SplitInts(p.Get("dmids")); err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. if reason, err = strconv.ParseInt(p.Get("reason"), 10, 8); err != nil {
  70. c.JSON(nil, ecode.RequestErr)
  71. return
  72. }
  73. if int8(reason) > model.ReportReasonOther {
  74. c.JSON(nil, ecode.DMReportReasonError)
  75. return
  76. }
  77. content := p.Get("content")
  78. if len([]rune(content)) > _maxContentLen {
  79. c.JSON(nil, ecode.DMReportReasonTooLong)
  80. return
  81. }
  82. for _, dmid := range dmids {
  83. if _, err = dmSvc.AddReport(c, cid, dmid, mid.(int64), int8(reason), content); err != nil {
  84. log.Error("dmSvc.AddReport(cid:%d, dmid:%d, mid:%v) error(%v)", cid, dmid, mid, err)
  85. }
  86. if err == nil {
  87. ok2 = true
  88. }
  89. }
  90. if ok2 {
  91. res := map[string]interface{}{}
  92. res["message"] = ""
  93. c.JSONMap(res, nil)
  94. return
  95. }
  96. c.JSON(nil, err)
  97. }
  98. func editReport(c *bm.Context) {
  99. var (
  100. err error
  101. cid, dmid, op int64
  102. p = c.Request.Form
  103. )
  104. mid, _ := c.Get("mid")
  105. if dmid, err = strconv.ParseInt(p.Get("dmid"), 10, 64); err != nil {
  106. c.JSON(nil, ecode.RequestErr)
  107. return
  108. }
  109. if cid, err = strconv.ParseInt(p.Get("cid"), 10, 64); err != nil {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. if op, err = strconv.ParseInt(p.Get("op"), 10, 8); err != nil {
  114. c.JSON(nil, ecode.RequestErr)
  115. return
  116. }
  117. if int8(op) != model.StatUpperIgnore && int8(op) != model.StatUpperDelete {
  118. c.JSON(nil, ecode.RequestErr)
  119. return
  120. }
  121. _, err = dmSvc.EditReport(c, 1, cid, mid.(int64), dmid, int8(op))
  122. c.JSON(nil, err)
  123. }
  124. func reportList(c *bm.Context) {
  125. var (
  126. err error
  127. aid int64 = -1
  128. page, pageSize int64
  129. p = c.Request.Form
  130. upOp = model.StatUpperInit
  131. )
  132. mid, _ := c.Get("mid")
  133. aidStr := p.Get("aid")
  134. if aidStr != "" {
  135. if aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  136. c.JSON(nil, ecode.RequestErr)
  137. return
  138. }
  139. }
  140. if page, err = strconv.ParseInt(p.Get("page"), 10, 64); err != nil {
  141. c.JSON(nil, ecode.RequestErr)
  142. return
  143. }
  144. if pageSize, err = strconv.ParseInt(p.Get("size"), 10, 64); err != nil {
  145. c.JSON(nil, ecode.RequestErr)
  146. return
  147. }
  148. data, err := dmSvc.ReportList(c, mid.(int64), aid, page, pageSize, upOp, []int64{int64(model.StatFirstInit), int64(model.StatSecondInit)})
  149. if err != nil {
  150. log.Error("dmSvc.ReportList(mid:%v, aid:%d) error(%v)", mid, aid, err)
  151. c.JSON(nil, err)
  152. return
  153. }
  154. c.JSON(data, nil)
  155. }
  156. func rptArchives(c *bm.Context) {
  157. var (
  158. err error
  159. upOp = model.StatUpperInit
  160. states = []int8{model.StatFirstInit, model.StatSecondInit}
  161. pn, ps int64 = 1, 20
  162. )
  163. mid, _ := c.Get("mid")
  164. data, err := dmSvc.ReportArchives(c, mid.(int64), upOp, states, pn, ps)
  165. if err != nil {
  166. log.Error("dmSvc.ReportArchives(mid:%v) error(%v)", mid, err)
  167. c.JSON(nil, err)
  168. return
  169. }
  170. c.JSON(data, nil)
  171. }