reply_admin.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782
  1. package http
  2. import (
  3. "strconv"
  4. "strings"
  5. "text/template"
  6. "go-common/app/interface/main/reply/conf"
  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. const (
  13. _remarkLength = 200
  14. )
  15. func adminSubjectMid(c *bm.Context) {
  16. var (
  17. err error
  18. tp int64
  19. oid int64
  20. mid int64
  21. adid int64
  22. )
  23. params := c.Request.Form
  24. tpStr := params.Get("type")
  25. oidStr := params.Get("oid")
  26. midStr := params.Get("mid")
  27. adidStr := params.Get("adid")
  28. remark := params.Get("remark")
  29. if tp, err = strconv.ParseInt(tpStr, 10, 64); err != nil {
  30. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  31. err = ecode.RequestErr
  32. c.JSON(nil, err)
  33. return
  34. }
  35. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  36. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  37. err = ecode.RequestErr
  38. c.JSON(nil, err)
  39. return
  40. }
  41. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  42. log.Warn("strconv.ParseInt(%s) error(%v)", midStr, err)
  43. err = ecode.RequestErr
  44. c.JSON(nil, err)
  45. return
  46. }
  47. if adid, err = strconv.ParseInt(adidStr, 10, 64); err != nil {
  48. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  49. err = ecode.RequestErr
  50. c.JSON(nil, err)
  51. return
  52. }
  53. err = rpSvr.AdminSubjectMid(c, adid, mid, oid, int8(tp), remark)
  54. c.JSON(nil, err)
  55. }
  56. func adminSubRegist(c *bm.Context) {
  57. var (
  58. err error
  59. oid int64
  60. tp int64
  61. state int64
  62. mid int64
  63. )
  64. params := c.Request.Form
  65. midStr := params.Get("mid")
  66. oidStr := params.Get("oid")
  67. tpStr := params.Get("type")
  68. stateStr := params.Get("state")
  69. appkey := params.Get("appkey")
  70. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  71. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  72. err = ecode.RequestErr
  73. c.JSON(nil, err)
  74. return
  75. }
  76. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  77. log.Warn("strconv.ParseInt(%s) error(%v)", midStr, err)
  78. err = ecode.RequestErr
  79. c.JSON(nil, err)
  80. return
  81. }
  82. if stateStr != "" {
  83. if state, err = strconv.ParseInt(stateStr, 10, 8); err != nil {
  84. log.Warn("strconv.ParseInt(%s) error(%v)", stateStr, err)
  85. err = ecode.RequestErr
  86. c.JSON(nil, err)
  87. return
  88. }
  89. }
  90. if tpStr != "" {
  91. if tp, err = strconv.ParseInt(tpStr, 10, 8); err != nil {
  92. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  93. err = ecode.RequestErr
  94. c.JSON(nil, err)
  95. return
  96. }
  97. }
  98. err = rpSvr.AdminSubRegist(c, oid, mid, int8(tp), int8(state), appkey)
  99. c.JSON(nil, err)
  100. }
  101. func adminSubject(c *bm.Context) {
  102. params := c.Request.Form
  103. oidStr := params.Get("oid")
  104. tpStr := params.Get("type")
  105. oid, err := strconv.ParseInt(oidStr, 10, 64)
  106. if err != nil {
  107. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  108. err = ecode.RequestErr
  109. c.JSON(nil, err)
  110. return
  111. }
  112. tp, err := strconv.ParseInt(tpStr, 10, 8)
  113. if err != nil {
  114. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  115. err = ecode.RequestErr
  116. c.JSON(nil, err)
  117. return
  118. }
  119. sub, err := rpSvr.AdminGetSubject(c, oid, int8(tp))
  120. if err != nil {
  121. log.Warn("rpSvr.AdminGetSubjectState(oid%d,tp,%d)error(%v)", oid, int8(tp))
  122. c.JSON(nil, err)
  123. return
  124. }
  125. c.JSON(sub, nil)
  126. }
  127. // adminModifySubject modify subject state.
  128. func adminSubjectState(c *bm.Context) {
  129. var (
  130. err error
  131. mid int64
  132. )
  133. params := c.Request.Form
  134. adidStr := params.Get("adid")
  135. oidStr := params.Get("oid")
  136. tpStr := params.Get("type")
  137. stateStr := params.Get("state")
  138. midStr := params.Get("mid")
  139. remark := params.Get("remark")
  140. // check params
  141. remark = strings.TrimSpace(remark)
  142. rml := len([]rune(remark))
  143. if rml > _remarkLength {
  144. log.Warn("remark(%s) length %d, max %d", remark, rml, _remarkLength)
  145. err = ecode.RequestErr
  146. c.JSON(nil, err)
  147. return
  148. }
  149. remark = template.HTMLEscapeString(remark)
  150. adid, err := strconv.ParseInt(adidStr, 10, 64)
  151. if err != nil {
  152. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  153. err = ecode.RequestErr
  154. c.JSON(nil, err)
  155. return
  156. }
  157. oid, err := strconv.ParseInt(oidStr, 10, 64)
  158. if err != nil {
  159. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  160. err = ecode.RequestErr
  161. c.JSON(nil, err)
  162. return
  163. }
  164. tp, err := strconv.ParseInt(tpStr, 10, 8)
  165. if err != nil {
  166. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  167. err = ecode.RequestErr
  168. c.JSON(nil, err)
  169. return
  170. }
  171. state, err := strconv.ParseInt(stateStr, 10, 8)
  172. if err != nil {
  173. log.Warn("strconv.ParseInt(%s) error(%v)", stateStr, err)
  174. err = ecode.RequestErr
  175. c.JSON(nil, err)
  176. return
  177. }
  178. if midStr != "" {
  179. if mid, err = strconv.ParseInt(midStr, 10, 64); err != nil {
  180. log.Warn("strconv.ParseInt(%s) error(%v)", midStr, err)
  181. err = ecode.RequestErr
  182. c.JSON(nil, err)
  183. return
  184. }
  185. }
  186. err = rpSvr.AdminSubjectState(c, adid, oid, mid, int8(tp), int8(state), remark)
  187. c.JSON(nil, err)
  188. }
  189. func adminAuditSub(c *bm.Context) {
  190. }
  191. // adminPassReply pass reply normal.
  192. func adminPassReply(c *bm.Context) {
  193. var err error
  194. params := c.Request.Form
  195. adidStr := params.Get("adid")
  196. oidStr := params.Get("oid")
  197. tpStr := params.Get("type")
  198. rpIDStr := params.Get("rpid")
  199. remark := params.Get("remark")
  200. // check params
  201. remark = strings.TrimSpace(remark)
  202. rml := len([]rune(remark))
  203. if rml > _remarkLength {
  204. log.Warn("remark(%s) length %d, max %d", remark, rml, _remarkLength)
  205. err = ecode.RequestErr
  206. c.JSON(nil, err)
  207. return
  208. }
  209. remark = template.HTMLEscapeString(remark)
  210. // remark = template.JSEscapeString(remark)
  211. adid, err := strconv.ParseInt(adidStr, 10, 64)
  212. if err != nil {
  213. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  214. err = ecode.RequestErr
  215. c.JSON(nil, err)
  216. return
  217. }
  218. oids, err := xstr.SplitInts(oidStr)
  219. if err != nil {
  220. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  221. err = ecode.RequestErr
  222. c.JSON(nil, err)
  223. return
  224. }
  225. rpIDs, err := xstr.SplitInts(rpIDStr)
  226. if err != nil {
  227. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  228. err = ecode.RequestErr
  229. c.JSON(nil, err)
  230. return
  231. }
  232. tp, err := strconv.ParseInt(tpStr, 10, 8)
  233. if err != nil {
  234. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  235. err = ecode.RequestErr
  236. c.JSON(nil, err)
  237. return
  238. }
  239. if len(oids) != len(rpIDs) {
  240. log.Warn("oids:%s rpIDs:%s ", oids, rpIDs)
  241. return
  242. }
  243. for i := 0; i < len(oids); i++ {
  244. err = rpSvr.AdminPass(c, adid, oids[i], rpIDs[i], int8(tp), remark)
  245. }
  246. c.JSON(nil, err)
  247. }
  248. // adminRecoverReply recover reply normal.
  249. func adminRecoverReply(c *bm.Context) {
  250. var err error
  251. params := c.Request.Form
  252. adidStr := params.Get("adid")
  253. oidStr := params.Get("oid")
  254. tpStr := params.Get("type")
  255. rpIDStr := params.Get("rpid")
  256. remark := params.Get("remark")
  257. // check params
  258. remark = strings.TrimSpace(remark)
  259. rml := len([]rune(remark))
  260. if rml > _remarkLength {
  261. log.Warn("remark(%s) length %d, max %d", remark, rml, _remarkLength)
  262. err = ecode.RequestErr
  263. c.JSON(nil, err)
  264. return
  265. }
  266. remark = template.HTMLEscapeString(remark)
  267. adid, err := strconv.ParseInt(adidStr, 10, 64)
  268. if err != nil {
  269. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  270. err = ecode.RequestErr
  271. c.JSON(nil, err)
  272. return
  273. }
  274. oid, err := strconv.ParseInt(oidStr, 10, 64)
  275. if err != nil {
  276. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  277. err = ecode.RequestErr
  278. c.JSON(nil, err)
  279. return
  280. }
  281. rpID, err := strconv.ParseInt(rpIDStr, 10, 64)
  282. if err != nil {
  283. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  284. err = ecode.RequestErr
  285. c.JSON(nil, err)
  286. return
  287. }
  288. tp, err := strconv.ParseInt(tpStr, 10, 8)
  289. if err != nil {
  290. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  291. err = ecode.RequestErr
  292. c.JSON(nil, err)
  293. return
  294. }
  295. err = rpSvr.AdminRecover(c, adid, oid, rpID, int8(tp), remark)
  296. c.JSON(nil, err)
  297. }
  298. // adminEditReply edit reply content by admin.
  299. func adminEditReply(c *bm.Context) {
  300. var err error
  301. params := c.Request.Form
  302. adidStr := params.Get("adid")
  303. oidStr := params.Get("oid")
  304. tpStr := params.Get("type")
  305. rpIDStr := params.Get("rpid")
  306. msg := params.Get("message")
  307. remark := params.Get("remark")
  308. // check params
  309. msg = strings.TrimSpace(msg)
  310. ml := len([]rune(msg))
  311. if conf.Conf.Reply.MaxConLen < ml || ml < conf.Conf.Reply.MinConLen {
  312. log.Warn("content(%s) length %d, max %d, min %d", msg, ml, conf.Conf.Reply.MaxConLen, conf.Conf.Reply.MinConLen)
  313. err = ecode.RequestErr
  314. c.JSON(nil, err)
  315. return
  316. }
  317. msg = template.HTMLEscapeString(msg)
  318. remark = strings.TrimSpace(remark)
  319. rml := len([]rune(remark))
  320. if rml > _remarkLength {
  321. log.Warn("remark(%s) length %d, max %d", remark, rml, _remarkLength)
  322. err = ecode.RequestErr
  323. c.JSON(nil, err)
  324. return
  325. }
  326. remark = template.HTMLEscapeString(remark)
  327. adid, err := strconv.ParseInt(adidStr, 10, 64)
  328. if err != nil {
  329. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  330. err = ecode.RequestErr
  331. c.JSON(nil, err)
  332. return
  333. }
  334. oid, err := strconv.ParseInt(oidStr, 10, 64)
  335. if err != nil {
  336. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  337. err = ecode.RequestErr
  338. c.JSON(nil, err)
  339. return
  340. }
  341. rpID, err := strconv.ParseInt(rpIDStr, 10, 64)
  342. if err != nil {
  343. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  344. err = ecode.RequestErr
  345. c.JSON(nil, err)
  346. return
  347. }
  348. tp, err := strconv.ParseInt(tpStr, 10, 8)
  349. if err != nil {
  350. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  351. err = ecode.RequestErr
  352. c.JSON(nil, err)
  353. return
  354. }
  355. err = rpSvr.AdminEdit(c, adid, oid, rpID, int8(tp), msg, remark)
  356. c.JSON(nil, err)
  357. }
  358. // report reason
  359. const (
  360. TypeReportReasonOthers = 0
  361. )
  362. // _delReply delete reply, this call be limited to this file.
  363. func _delReply(c *bm.Context, isReport bool) {
  364. var (
  365. err error
  366. reason int64
  367. freason int64
  368. )
  369. params := c.Request.Form
  370. adidStr := params.Get("adid")
  371. adname := params.Get("adname")
  372. oidStr := params.Get("oid")
  373. tpStr := params.Get("type")
  374. rpIDStr := params.Get("rpid")
  375. morStr := params.Get("moral")
  376. notStr := params.Get("notify")
  377. remark := params.Get("remark")
  378. ftimeStr := params.Get("ftime")
  379. auditStr := params.Get("audit")
  380. reasonStr := params.Get("reason")
  381. content := params.Get("reason_content")
  382. freasonStr := params.Get("freason")
  383. // check params
  384. remark = strings.TrimSpace(remark)
  385. ml := len([]rune(remark))
  386. if ml > _remarkLength {
  387. log.Warn("remark (%s) length %d, max %d", remark, ml, _remarkLength)
  388. err = ecode.RequestErr
  389. c.JSON(nil, err)
  390. return
  391. }
  392. remark = template.HTMLEscapeString(remark)
  393. adid, err := strconv.ParseInt(adidStr, 10, 64)
  394. if err != nil {
  395. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  396. err = ecode.RequestErr
  397. c.JSON(nil, err)
  398. return
  399. }
  400. oids, err := xstr.SplitInts(oidStr)
  401. if err != nil {
  402. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  403. err = ecode.RequestErr
  404. c.JSON(nil, err)
  405. return
  406. }
  407. rpIDs, err := xstr.SplitInts(rpIDStr)
  408. if err != nil {
  409. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  410. err = ecode.RequestErr
  411. c.JSON(nil, err)
  412. return
  413. }
  414. tps, err := xstr.SplitInts(tpStr)
  415. if err != nil {
  416. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  417. err = ecode.RequestErr
  418. c.JSON(nil, err)
  419. return
  420. }
  421. moral, err := strconv.ParseInt(morStr, 10, 8)
  422. if err != nil {
  423. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  424. err = ecode.RequestErr
  425. c.JSON(nil, err)
  426. return
  427. }
  428. notify, err := strconv.ParseBool(notStr)
  429. if err != nil {
  430. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  431. err = ecode.RequestErr
  432. c.JSON(nil, err)
  433. return
  434. }
  435. if reasonStr != "" {
  436. if reason, err = strconv.ParseInt(reasonStr, 10, 64); err != nil {
  437. log.Warn("strconv.ParseInt(%s) error(%v)", reasonStr, err)
  438. err = ecode.RequestErr
  439. c.JSON(nil, err)
  440. return
  441. }
  442. }
  443. if freasonStr != "" {
  444. if freason, err = strconv.ParseInt(freasonStr, 10, 64); err != nil {
  445. log.Warn("strconv.ParseInt(%s) error(%v)", freasonStr, err)
  446. err = ecode.RequestErr
  447. c.JSON(nil, err)
  448. return
  449. }
  450. }
  451. ftime, _ := strconv.ParseInt(ftimeStr, 10, 64)
  452. audit, _ := strconv.ParseInt(auditStr, 10, 8)
  453. if len(oids) == 0 || len(rpIDs) != len(oids) || len(tps) != len(oids) {
  454. log.Warn("admin del reply oids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  455. err = ecode.RequestErr
  456. c.JSON(nil, err)
  457. return
  458. }
  459. if reason != TypeReportReasonOthers {
  460. content = ""
  461. }
  462. for i := 0; i < len(oids); i++ {
  463. if isReport {
  464. err = rpSvr.AdminDeleteByReport(c, adid, oids[i], rpIDs[i], ftime, int8(tps[i]), int(moral), notify, adname, remark, int8(audit), int8(reason), content, int8(freason))
  465. } else {
  466. err = rpSvr.AdminDelete(c, adid, oids[i], rpIDs[i], ftime, int8(tps[i]), int(moral), notify, adname, remark, int8(reason), int8(freason))
  467. }
  468. }
  469. c.JSON(nil, err)
  470. }
  471. // adminDelReply delete reply by admin.
  472. func adminDelReply(c *bm.Context) {
  473. _delReply(c, false)
  474. }
  475. // adminDelReplyByReport delete a report reply by admin.
  476. func adminDelReplyByReport(c *bm.Context) {
  477. _delReply(c, true)
  478. }
  479. func adminReportStateSet(c *bm.Context) {
  480. params := c.Request.Form
  481. adidStr := params.Get("adid")
  482. oidStr := params.Get("oid")
  483. tpStr := params.Get("type")
  484. rpIDStr := params.Get("rpid")
  485. stateStr := params.Get("state")
  486. var adid int64
  487. if adidStr != "" {
  488. var err error
  489. adid, err = strconv.ParseInt(adidStr, 10, 64)
  490. if err != nil {
  491. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  492. err = ecode.RequestErr
  493. c.JSON(nil, err)
  494. return
  495. }
  496. }
  497. oids, err := xstr.SplitInts(oidStr)
  498. if err != nil {
  499. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  500. err = ecode.RequestErr
  501. c.JSON(nil, err)
  502. return
  503. }
  504. rpIDs, err := xstr.SplitInts(rpIDStr)
  505. if err != nil {
  506. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  507. err = ecode.RequestErr
  508. c.JSON(nil, err)
  509. return
  510. }
  511. tps, err := xstr.SplitInts(tpStr)
  512. if err != nil {
  513. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  514. err = ecode.RequestErr
  515. c.JSON(nil, err)
  516. return
  517. }
  518. if len(oids) == 0 || len(rpIDs) != len(oids) || len(tps) != len(oids) {
  519. log.Warn("admin set report oids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  520. err = ecode.RequestErr
  521. c.JSON(nil, err)
  522. return
  523. }
  524. state, err := strconv.ParseInt(stateStr, 10, 8)
  525. if err != nil {
  526. log.Warn("admin set report soids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  527. err = ecode.RequestErr
  528. c.JSON(nil, err)
  529. return
  530. }
  531. for i := 0; i < len(oids); i++ {
  532. err = rpSvr.AdminReportStateSet(c, adid, oids[i], rpIDs[i], int8(tps[i]), int8(state))
  533. }
  534. c.JSON(nil, err)
  535. }
  536. func adminTransferReport(c *bm.Context) {
  537. params := c.Request.Form
  538. adidStr := params.Get("adid")
  539. oidStr := params.Get("oid")
  540. tpStr := params.Get("type")
  541. rpIDStr := params.Get("rpid")
  542. auditStr := params.Get("audit")
  543. adid, err := strconv.ParseInt(adidStr, 10, 64)
  544. if err != nil {
  545. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  546. err = ecode.RequestErr
  547. c.JSON(nil, err)
  548. return
  549. }
  550. oids, err := xstr.SplitInts(oidStr)
  551. if err != nil {
  552. log.Warn("strconv.SplitInts(%s) error(%v)", oidStr, err)
  553. err = ecode.RequestErr
  554. c.JSON(nil, err)
  555. return
  556. }
  557. rpIDs, err := xstr.SplitInts(rpIDStr)
  558. if err != nil {
  559. log.Warn("strconv.SplitInts(%s) error(%v)", rpIDStr, err)
  560. err = ecode.RequestErr
  561. c.JSON(nil, err)
  562. return
  563. }
  564. tps, err := xstr.SplitInts(tpStr)
  565. if err != nil {
  566. log.Warn("strconv.SplitInts(%s) error(%v)", tpStr, err)
  567. err = ecode.RequestErr
  568. c.JSON(nil, err)
  569. return
  570. }
  571. if len(oids) == 0 || len(rpIDs) != len(oids) || len(tps) != len(oids) {
  572. log.Warn("admin del reply oids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  573. err = ecode.RequestErr
  574. c.JSON(nil, err)
  575. return
  576. }
  577. audit, _ := strconv.ParseInt(auditStr, 10, 8)
  578. for i := 0; i < len(oids); i++ {
  579. err = rpSvr.AdminReportTransfer(c, adid, oids[i], rpIDs[i], int8(tps[i]), int8(audit))
  580. }
  581. c.JSON(nil, err)
  582. }
  583. // adminIgnoreReport ignore a report.
  584. func adminIgnoreReport(c *bm.Context) {
  585. var err error
  586. params := c.Request.Form
  587. adidStr := params.Get("adid")
  588. oidStr := params.Get("oid")
  589. tpStr := params.Get("type")
  590. rpIDStr := params.Get("rpid")
  591. auditStr := params.Get("audit")
  592. remark := params.Get("remark")
  593. // check params
  594. remark = strings.TrimSpace(remark)
  595. ml := len([]rune(remark))
  596. if ml > _remarkLength {
  597. log.Warn("remark (%s) length %d, max %d", remark, ml, 255)
  598. err = ecode.RequestErr
  599. c.JSON(nil, err)
  600. return
  601. }
  602. remark = template.HTMLEscapeString(remark)
  603. adid, err := strconv.ParseInt(adidStr, 10, 64)
  604. if err != nil {
  605. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  606. err = ecode.RequestErr
  607. c.JSON(nil, err)
  608. return
  609. }
  610. oids, err := xstr.SplitInts(oidStr)
  611. if err != nil {
  612. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  613. err = ecode.RequestErr
  614. c.JSON(nil, err)
  615. return
  616. }
  617. rpIDs, err := xstr.SplitInts(rpIDStr)
  618. if err != nil {
  619. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  620. err = ecode.RequestErr
  621. c.JSON(nil, err)
  622. return
  623. }
  624. tps, err := xstr.SplitInts(tpStr)
  625. if err != nil {
  626. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  627. err = ecode.RequestErr
  628. c.JSON(nil, err)
  629. return
  630. }
  631. audit, _ := strconv.ParseInt(auditStr, 10, 8)
  632. if len(oids) == 0 || len(rpIDs) != len(oids) || len(tps) != len(oids) {
  633. log.Warn("admin del reply oids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  634. err = ecode.RequestErr
  635. c.JSON(nil, err)
  636. return
  637. }
  638. for i := 0; i < len(oids); i++ {
  639. err = rpSvr.AdminReportIgnore(c, adid, oids[i], rpIDs[i], int8(tps[i]), int8(audit), remark)
  640. }
  641. c.JSON(nil, err)
  642. }
  643. // adminAddTopReply add top reply
  644. func adminAddTopReply(c *bm.Context) {
  645. params := c.Request.Form
  646. adidStr := params.Get("adid")
  647. oidStr := params.Get("oid")
  648. tpStr := params.Get("type")
  649. rpIDStr := params.Get("rpid")
  650. actStr := params.Get("action")
  651. // check params
  652. adid, err := strconv.ParseInt(adidStr, 10, 64)
  653. if err != nil {
  654. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  655. err = ecode.RequestErr
  656. c.JSON(nil, err)
  657. return
  658. }
  659. oid, err := strconv.ParseInt(oidStr, 10, 64)
  660. if err != nil {
  661. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  662. err = ecode.RequestErr
  663. c.JSON(nil, err)
  664. return
  665. }
  666. rpID, err := strconv.ParseInt(rpIDStr, 10, 64)
  667. if err != nil {
  668. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  669. err = ecode.RequestErr
  670. c.JSON(nil, err)
  671. return
  672. }
  673. tp, err := strconv.ParseInt(tpStr, 10, 8)
  674. if err != nil {
  675. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  676. err = ecode.RequestErr
  677. c.JSON(nil, err)
  678. return
  679. }
  680. act, err := strconv.ParseInt(actStr, 10, 8)
  681. if err != nil {
  682. log.Warn("strconv.ParseInt(actStr :%s) err(%v)", actStr, err)
  683. act = 1
  684. }
  685. err = rpSvr.AdminAddTop(c, adid, oid, rpID, int8(tp), int8(act))
  686. c.JSON(nil, err)
  687. }
  688. func adminReportRecover(c *bm.Context) {
  689. var err error
  690. params := c.Request.Form
  691. adidStr := params.Get("adid")
  692. oidStr := params.Get("oid")
  693. tpStr := params.Get("type")
  694. rpIDStr := params.Get("rpid")
  695. auditStr := params.Get("audit")
  696. remark := params.Get("remark")
  697. // check params
  698. remark = strings.TrimSpace(remark)
  699. rml := len([]rune(remark))
  700. if rml > _remarkLength {
  701. log.Warn("remark(%s) length %d, max %d", remark, rml, _remarkLength)
  702. err = ecode.RequestErr
  703. c.JSON(nil, err)
  704. return
  705. }
  706. remark = template.HTMLEscapeString(remark)
  707. adid, err := strconv.ParseInt(adidStr, 10, 64)
  708. if err != nil {
  709. log.Warn("strconv.ParseInt(%s) error(%v)", adidStr, err)
  710. err = ecode.RequestErr
  711. c.JSON(nil, err)
  712. return
  713. }
  714. oids, err := xstr.SplitInts(oidStr)
  715. if err != nil {
  716. log.Warn("strconv.ParseInt(%s) error(%v)", oidStr, err)
  717. err = ecode.RequestErr
  718. c.JSON(nil, err)
  719. return
  720. }
  721. rpIDs, err := xstr.SplitInts(rpIDStr)
  722. if err != nil {
  723. log.Warn("strconv.ParseInt(%s) error(%v)", rpIDStr, err)
  724. err = ecode.RequestErr
  725. c.JSON(nil, err)
  726. return
  727. }
  728. tps, err := xstr.SplitInts(tpStr)
  729. if err != nil {
  730. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  731. err = ecode.RequestErr
  732. c.JSON(nil, err)
  733. return
  734. }
  735. audit, err := strconv.ParseInt(auditStr, 10, 8)
  736. if err != nil {
  737. log.Warn("strconv.ParseInt(%s) error(%v)", tpStr, err)
  738. err = ecode.RequestErr
  739. c.JSON(nil, err)
  740. return
  741. }
  742. if len(oids) == 0 || len(rpIDs) != len(oids) || len(tps) != len(oids) {
  743. log.Warn("admin del reply oids: %v, rpIDs: %v, tps: %v", oids, rpIDs, tps)
  744. err = ecode.RequestErr
  745. c.JSON(nil, err)
  746. return
  747. }
  748. for i := 0; i < len(oids); i++ {
  749. err = rpSvr.AdminReportRecover(c, adid, oids[i], rpIDs[i], int8(tps[i]), int8(audit), remark)
  750. }
  751. c.JSON(nil, err)
  752. }