report.go 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344
  1. package http
  2. import (
  3. "net/url"
  4. "strconv"
  5. "strings"
  6. "go-common/app/admin/main/dm/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/xstr"
  11. )
  12. // checkState check admin operation.
  13. func checkState(state int8) (ok bool) {
  14. if state != model.StatFirstInit &&
  15. state != model.StatFirstDelete &&
  16. state != model.StatFirstIgnore &&
  17. state != model.StatSecondInit &&
  18. state != model.StatSecondIgnore &&
  19. state != model.StatSecondAutoDelete &&
  20. state != model.StatSecondDelete {
  21. ok = false
  22. } else {
  23. ok = true
  24. }
  25. return
  26. }
  27. func reportList2(c *bm.Context) {
  28. var (
  29. v = new(model.ReportListParams)
  30. )
  31. if err := c.Bind(v); err != nil {
  32. return
  33. }
  34. c.JSON(dmSvc.ReportList2(c, v))
  35. }
  36. func changeReportStat(c *bm.Context) {
  37. var (
  38. reason, notice, block, blockReason, moral int64
  39. cidDmids = map[int64][]int64{}
  40. params = c.Request.Form
  41. data struct {
  42. Affect int64 `json:"affect"`
  43. }
  44. )
  45. uid, err := strconv.ParseInt(params.Get("adminId"), 10, 64)
  46. if err != nil {
  47. c.JSON(nil, ecode.RequestErr)
  48. return
  49. }
  50. state, err := strconv.ParseInt(params.Get("state"), 10, 8)
  51. if err != nil {
  52. c.JSON(nil, ecode.RequestErr)
  53. return
  54. }
  55. uname := params.Get("uname")
  56. remark := params.Get("remark")
  57. noticeStr := params.Get("notice")
  58. if noticeStr != "" {
  59. if notice, err = strconv.ParseInt(noticeStr, 10, 8); err != nil {
  60. c.JSON(nil, ecode.RequestErr)
  61. return
  62. }
  63. }
  64. ids := strings.Split(params.Get("ids"), "|")
  65. if len(ids) == 0 {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. for _, idStr := range ids {
  70. var (
  71. cid int64
  72. dmids []int64
  73. )
  74. s := strings.Split(idStr, ":")
  75. if len(s) != 2 {
  76. c.JSON(nil, ecode.RequestErr)
  77. return
  78. }
  79. if cid, err = strconv.ParseInt(s[0], 10, 64); err != nil {
  80. c.JSON(nil, ecode.RequestErr)
  81. return
  82. }
  83. if dmids, err = xstr.SplitInts(s[1]); err != nil {
  84. c.JSON(nil, ecode.RequestErr)
  85. return
  86. }
  87. if !checkState(int8(state)) {
  88. c.JSON(nil, ecode.RequestErr)
  89. return
  90. }
  91. cidDmids[cid] = dmids
  92. }
  93. if state == int64(model.StatSecondDelete) || state == int64(model.StatFirstDelete) {
  94. blockStr := params.Get("block")
  95. if blockStr != "" {
  96. if block, err = strconv.ParseInt(blockStr, 10, 8); err != nil {
  97. c.JSON(nil, ecode.RequestErr)
  98. return
  99. }
  100. }
  101. MoralStr := params.Get("moral")
  102. if MoralStr != "" {
  103. if moral, err = strconv.ParseInt(MoralStr, 10, 8); err != nil {
  104. c.JSON(nil, ecode.RequestErr)
  105. return
  106. }
  107. }
  108. blockReasonStr := params.Get("block_reason")
  109. if blockReasonStr != "" {
  110. if blockReason, err = strconv.ParseInt(blockReasonStr, 10, 8); err != nil {
  111. c.JSON(nil, ecode.RequestErr)
  112. return
  113. }
  114. }
  115. reasonStr := params.Get("reason")
  116. if reasonStr != "" {
  117. if reason, err = strconv.ParseInt(reasonStr, 10, 8); err != nil {
  118. c.JSON(nil, ecode.RequestErr)
  119. return
  120. }
  121. }
  122. }
  123. data.Affect, err = dmSvc.ChangeReportStat(c, cidDmids, int8(state), int8(reason), int8(notice), uid, block, blockReason, moral, remark, uname)
  124. if err != nil {
  125. log.Error("dmSvc.ChangeReportStat(id:%+v, uid:%d) error(%v)", cidDmids, uid, err)
  126. c.JSON(nil, err)
  127. }
  128. res := map[string]interface{}{}
  129. res["data"] = data
  130. c.JSONMap(res, err)
  131. }
  132. func reportList(c *bm.Context) {
  133. var (
  134. tid, rpID []int64
  135. rt *model.Report
  136. p = c.Request.Form
  137. start, end, sort, order, keyword string
  138. )
  139. rt = &model.Report{
  140. Aid: -1,
  141. UID: -1,
  142. RpUID: -1,
  143. RpType: -1,
  144. Cid: -1,
  145. }
  146. state, err := xstr.SplitInts(p.Get("state"))
  147. if err != nil {
  148. c.JSON(nil, ecode.RequestErr)
  149. return
  150. }
  151. upOp, err := xstr.SplitInts(p.Get("up_op"))
  152. if err != nil {
  153. c.JSON(nil, ecode.RequestErr)
  154. return
  155. }
  156. page, err := strconv.ParseInt(p.Get("page"), 10, 64)
  157. if err != nil {
  158. c.JSON(nil, ecode.RequestErr)
  159. return
  160. }
  161. tidStr := p.Get("tid")
  162. if tidStr != "" {
  163. if tid, err = xstr.SplitInts(tidStr); err != nil {
  164. c.JSON(nil, ecode.RequestErr)
  165. return
  166. }
  167. }
  168. aidStr := p.Get("aid")
  169. if aidStr != "" {
  170. if rt.Aid, err = strconv.ParseInt(aidStr, 10, 64); err != nil {
  171. c.JSON(nil, ecode.RequestErr)
  172. return
  173. }
  174. }
  175. cidStr := p.Get("cid")
  176. if cidStr != "" {
  177. if rt.Cid, err = strconv.ParseInt(cidStr, 10, 64); err != nil {
  178. c.JSON(nil, ecode.RequestErr)
  179. return
  180. }
  181. }
  182. uidStr := p.Get("uid")
  183. if uidStr != "" {
  184. if rt.UID, err = strconv.ParseInt(uidStr, 10, 64); err != nil {
  185. c.JSON(nil, ecode.RequestErr)
  186. return
  187. }
  188. }
  189. userStr := p.Get("rp_user")
  190. if userStr != "" {
  191. if rt.RpUID, err = strconv.ParseInt(userStr, 10, 64); err != nil {
  192. c.JSON(nil, ecode.RequestErr)
  193. return
  194. }
  195. }
  196. typeStr := p.Get("rp_type")
  197. if typeStr != "" {
  198. if rpID, err = xstr.SplitInts(typeStr); err != nil {
  199. c.JSON(nil, ecode.RequestErr)
  200. return
  201. }
  202. }
  203. startStr := p.Get("start")
  204. start, err = url.QueryUnescape(startStr)
  205. if err != nil {
  206. c.JSON(nil, ecode.RequestErr)
  207. return
  208. }
  209. endStr := p.Get("end")
  210. end, err = url.QueryUnescape(endStr)
  211. if err != nil {
  212. c.JSON(nil, ecode.RequestErr)
  213. return
  214. }
  215. pageSizeStr := p.Get("page_size")
  216. var pageSize int64
  217. if pageSizeStr != "" {
  218. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil {
  219. c.JSON(nil, ecode.RequestErr)
  220. return
  221. }
  222. if pageSize > 100 {
  223. pageSize = 100
  224. }
  225. } else {
  226. pageSize = 100
  227. }
  228. // TODO: swap order&sort
  229. order = p.Get("sort")
  230. sort = p.Get("order")
  231. keyword = p.Get("keyword")
  232. rpts, err := dmSvc.ReportList(c, page, pageSize, start, end, order, sort, keyword, tid, rpID, state, upOp, rt)
  233. res := map[string]interface{}{}
  234. res["data"] = rpts
  235. c.JSONMap(res, err)
  236. }
  237. func reportLog(c *bm.Context) {
  238. p := c.Request.Form
  239. dmid, err := strconv.ParseInt(p.Get("dmid"), 10, 64)
  240. if err != nil {
  241. c.JSON(nil, ecode.RequestErr)
  242. return
  243. }
  244. data, err := dmSvc.ReportLog(c, dmid)
  245. res := map[string]interface{}{}
  246. res["data"] = data
  247. c.JSONMap(res, err)
  248. }
  249. func changeReportUserStat(c *bm.Context) {
  250. p := c.Request.Form
  251. dmids, err := xstr.SplitInts(p.Get("dmids"))
  252. if err != nil {
  253. c.JSON(nil, ecode.RequestErr)
  254. return
  255. }
  256. err = dmSvc.ChangeReportUserStat(c, dmids)
  257. c.JSON(nil, err)
  258. }
  259. func transferJudge(c *bm.Context) {
  260. var (
  261. err error
  262. uname string
  263. cidDmids = map[int64][]int64{}
  264. p = c.Request.Form
  265. )
  266. ids := strings.Split(p.Get("ids"), "|")
  267. if len(ids) == 0 {
  268. c.JSON(nil, ecode.RequestErr)
  269. return
  270. }
  271. for _, idStr := range ids {
  272. var (
  273. cid int64
  274. dmids []int64
  275. )
  276. s := strings.Split(idStr, ":")
  277. if len(s) != 2 {
  278. c.JSON(nil, ecode.RequestErr)
  279. return
  280. }
  281. if cid, err = strconv.ParseInt(s[0], 10, 64); err != nil {
  282. c.JSON(nil, ecode.RequestErr)
  283. return
  284. }
  285. if dmids, err = xstr.SplitInts(s[1]); err != nil {
  286. c.JSON(nil, ecode.RequestErr)
  287. return
  288. }
  289. cidDmids[cid] = dmids
  290. }
  291. uname = p.Get("uname")
  292. uid, err := strconv.ParseInt(p.Get("adminId"), 10, 64)
  293. if err != nil {
  294. c.JSON(nil, ecode.RequestErr)
  295. return
  296. }
  297. err = dmSvc.DMReportJudge(c, cidDmids, uid, uname)
  298. c.JSON(nil, err)
  299. }
  300. // JudgeResult post judgement result
  301. func JudgeResult(c *bm.Context) {
  302. p := c.Request.Form
  303. cid, err := strconv.ParseInt(p.Get("cid"), 10, 64)
  304. if err != nil {
  305. c.JSON(nil, ecode.RequestErr)
  306. return
  307. }
  308. dmid, err := strconv.ParseInt(p.Get("dmid"), 10, 64)
  309. if err != nil {
  310. c.JSON(nil, ecode.RequestErr)
  311. return
  312. }
  313. result, err := strconv.ParseInt(p.Get("result"), 10, 64)
  314. if err != nil {
  315. c.JSON(nil, ecode.RequestErr)
  316. return
  317. }
  318. err = dmSvc.JudgeResult(c, cid, dmid, result)
  319. c.JSON(nil, err)
  320. }
  321. func logList(c *bm.Context) {
  322. p := c.Request.Form
  323. dmid, err := strconv.ParseInt(p.Get("dmid"), 10, 64)
  324. if err != nil {
  325. c.JSON(nil, ecode.RequestErr)
  326. return
  327. }
  328. data, err := dmSvc.QueryOpLogs(c, dmid)
  329. res := map[string]interface{}{}
  330. res["data"] = data
  331. c.JSONMap(res, err)
  332. }