reply.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721
  1. package http
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "net/http"
  6. "strconv"
  7. "strings"
  8. "time"
  9. "go-common/app/admin/main/reply/conf"
  10. "go-common/app/admin/main/reply/model"
  11. "go-common/library/ecode"
  12. "go-common/library/log"
  13. bm "go-common/library/net/http/blademaster"
  14. "go-common/library/net/http/blademaster/binding"
  15. "go-common/library/net/ip"
  16. )
  17. func replyExport(c *bm.Context) {
  18. var (
  19. err error
  20. startTime time.Time
  21. endTime time.Time
  22. )
  23. v := new(struct {
  24. Oid int64 `form:"oid" validate:"required"`
  25. Type int8 `form:"type" validate:"required"`
  26. StartTime string `form:"start_time"`
  27. EndTime string `form:"end_time"`
  28. States []int64 `form:"states,split"`
  29. Mid int64 `form:"uid"`
  30. })
  31. err = c.Bind(v)
  32. if err != nil {
  33. return
  34. }
  35. if v.StartTime == "" {
  36. startTime = time.Now().AddDate(0, -3, 0)
  37. v.StartTime = startTime.Format("2006-01-02")
  38. } else {
  39. if startTime, err = time.Parse("2006-01-02", v.StartTime); err != nil {
  40. log.Warn("time.Parse(%s) error(%v)", v.StartTime, err)
  41. c.JSON(nil, ecode.RequestErr)
  42. return
  43. }
  44. }
  45. if v.EndTime == "" {
  46. endTime = time.Now()
  47. v.EndTime = endTime.Format("2006-01-02")
  48. } else {
  49. if endTime, err = time.Parse("2006-01-02", v.EndTime); err != nil {
  50. log.Warn("time.Parse(%s) error(%v)", v.EndTime, err)
  51. c.JSON(nil, ecode.RequestErr)
  52. return
  53. }
  54. }
  55. states := strings.Trim(strings.Join(strings.Split(fmt.Sprint(v.States), " "), ","), "[]")
  56. data, err := rpSvc.ExportReply(c, v.Oid, v.Mid, v.Type, states, startTime, endTime)
  57. if err != nil {
  58. log.Error("Svc.ExportReply(%d,%d,%d,%s,%v,%v) error(%v)", v.Oid, v.Mid, v.Type, states, startTime, endTime, err)
  59. c.Render(http.StatusInternalServerError, model.CSV{
  60. Data: nil,
  61. Title: "",
  62. })
  63. return
  64. }
  65. c.Render(http.StatusOK, model.CSV{
  66. Data: data,
  67. Title: v.StartTime + "至" + v.EndTime,
  68. })
  69. return
  70. }
  71. func replySearch(c *bm.Context) {
  72. var (
  73. err error
  74. typ, startTime, endTime int64
  75. page = int64(conf.Conf.Reply.PageNum)
  76. pageSize = int64(conf.Conf.Reply.PageSize)
  77. sp = &model.SearchParams{}
  78. )
  79. params := c.Request.Form
  80. typeStr := params.Get("type")
  81. oidStr := params.Get("oid")
  82. uidStr := params.Get("uid")
  83. adminIDStr := params.Get("adminid")
  84. startTimeStr := params.Get("start_time")
  85. endTimeStr := params.Get("end_time")
  86. ipStr := params.Get("ip")
  87. pageStr := params.Get("page")
  88. pageSizeStr := params.Get("pagesize")
  89. // parse params
  90. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  91. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. if oidStr != "" {
  96. if sp.Oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  97. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  98. c.JSON(nil, ecode.RequestErr)
  99. return
  100. }
  101. }
  102. if uidStr != "" {
  103. if sp.UID, err = strconv.ParseInt(uidStr, 10, 64); err != nil {
  104. log.Warn("strconv.ParseInt(uid:%s) error(%v)", uidStr, err)
  105. c.JSON(nil, ecode.RequestErr)
  106. return
  107. }
  108. }
  109. if adminIDStr != "" {
  110. if sp.AdminID, err = strconv.ParseInt(adminIDStr, 10, 64); err != nil {
  111. log.Warn("strconv.ParseInt(adminid:%s) error(%v)", adminIDStr, err)
  112. c.JSON(nil, ecode.RequestErr)
  113. return
  114. }
  115. }
  116. if startTimeStr != "" {
  117. if startTime, err = strconv.ParseInt(startTimeStr, 10, 64); err == nil {
  118. sp.Begin = time.Unix(startTime, 0)
  119. } else {
  120. var t time.Time
  121. t, err = time.Parse("2006-01-02", startTimeStr)
  122. if err == nil {
  123. sp.Begin = t
  124. } else {
  125. c.JSON(nil, ecode.RequestErr)
  126. return
  127. }
  128. }
  129. }
  130. if endTimeStr != "" {
  131. if endTime, err = strconv.ParseInt(endTimeStr, 10, 64); err == nil {
  132. sp.End = time.Unix(endTime, 0)
  133. } else {
  134. var t time.Time
  135. t, err = time.Parse("2006-01-02", endTimeStr)
  136. if err == nil {
  137. sp.End = t
  138. } else {
  139. c.JSON(nil, ecode.RequestErr)
  140. return
  141. }
  142. }
  143. } else if startTimeStr != "" {
  144. sp.End = time.Now()
  145. }
  146. if ipStr != "" {
  147. if sp.IP, err = strconv.ParseInt(ipStr, 10, 64); err != nil {
  148. sp.IP = int64(ip.InetAtoN(ipStr))
  149. }
  150. }
  151. if pageStr != "" {
  152. if page, err = strconv.ParseInt(pageStr, 10, 64); err != nil || page < 1 {
  153. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageStr, err)
  154. c.JSON(nil, ecode.RequestErr)
  155. return
  156. }
  157. }
  158. if pageSizeStr != "" {
  159. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil || pageSize < int64(1) || pageSize > int64(conf.Conf.Reply.PageSize) {
  160. log.Warn("strconv.ParseInt(pagesize:%s) error(%v)", pageSizeStr, err)
  161. c.JSON(nil, ecode.RequestErr)
  162. return
  163. }
  164. }
  165. sp.Type = int32(typ)
  166. sp.TypeIds = params.Get("typeids")
  167. sp.Keyword = params.Get("keyword")
  168. sp.KeywordHigh = params.Get("keyword_high")
  169. sp.Uname = params.Get("nickname")
  170. sp.States = params.Get("states")
  171. sp.Sort = params.Get("sort")
  172. sp.Order = params.Get("order")
  173. sp.Attr = params.Get("attr")
  174. sp.AdminName = params.Get("adminname")
  175. sp.Sort, sp.Order = sp.Order, sp.Sort
  176. if sp.Sort == "" {
  177. sp.Sort = "desc"
  178. }
  179. if sp.Order == "" {
  180. sp.Order = "ctime"
  181. }
  182. rs, err := rpSvc.ReplySearch(c, sp, page, pageSize)
  183. if err != nil {
  184. log.Error("svc.ReplySearch(%v,%d,%d) error(%v)", sp, page, pageSize, err)
  185. c.JSON(nil, err)
  186. return
  187. }
  188. res := map[string]interface{}{}
  189. res["data"] = rs
  190. c.JSONMap(res, nil)
  191. return
  192. }
  193. func updateReplyConfig(c *bm.Context) {
  194. var (
  195. err error
  196. typ, oid, showEntry, showAdmin, adminID int64
  197. operator string
  198. config = &model.Config{}
  199. bs []byte
  200. )
  201. params := c.Request.Form
  202. typeStr := params.Get("type")
  203. oidStr := params.Get("oid")
  204. adminIDStr := params.Get("adminid")
  205. operator = params.Get("operator")
  206. showEntityStr := params.Get("showentry")
  207. showAdminStr := params.Get("showadmin")
  208. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  209. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  210. c.JSON(nil, ecode.RequestErr)
  211. return
  212. }
  213. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  214. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  215. c.JSON(nil, ecode.RequestErr)
  216. return
  217. }
  218. if showEntry, err = strconv.ParseInt(showEntityStr, 10, 64); err != nil {
  219. log.Warn("strconv.ParseInt(showEntry:%s) error(%v)", showEntityStr, err)
  220. c.JSON(nil, ecode.RequestErr)
  221. return
  222. }
  223. if showAdmin, err = strconv.ParseInt(showAdminStr, 10, 64); err != nil {
  224. log.Warn("strconv.ParseInt(showAdmin:%s) error(%v)", showAdminStr, err)
  225. c.JSON(nil, ecode.RequestErr)
  226. return
  227. }
  228. adminID, _ = strconv.ParseInt(adminIDStr, 10, 64)
  229. if uid, ok := c.Get("uid"); ok {
  230. adminID = uid.(int64)
  231. }
  232. config.Oid = oid
  233. config.Type = int32(typ)
  234. config.Category = 1
  235. config.AdminID = adminID
  236. config.Operator = operator
  237. configValue := map[string]int64{
  238. "showentry": showEntry,
  239. "showadmin": showAdmin,
  240. }
  241. config.ShowEntry = int32(showEntry)
  242. config.ShowAdmin = int32(showAdmin)
  243. if bs, err = json.Marshal(configValue); err == nil {
  244. config.Config = string(bs)
  245. }
  246. if _, err = rpSvc.AddReplyConfig(c, config); err != nil {
  247. log.Error("svc.AddReplyConfig(%v) error(%v)", config, err)
  248. c.JSON(nil, err)
  249. return
  250. }
  251. c.JSON(nil, nil)
  252. }
  253. func renewReplyConfig(c *bm.Context) {
  254. var (
  255. err error
  256. id int64
  257. )
  258. params := c.Request.Form
  259. idStr := params.Get("id")
  260. if id, err = strconv.ParseInt(idStr, 10, 64); err != nil {
  261. log.Warn("strconv.ParseInt(type:%s) error(%v)", idStr, err)
  262. c.JSON(nil, ecode.RequestErr)
  263. return
  264. }
  265. if _, err = rpSvc.RenewReplyConfig(c, id); err != nil {
  266. log.Error("svc.RenewReplyConfig(%d) error(%v)", id, err)
  267. c.JSON(nil, err)
  268. return
  269. }
  270. c.JSON(nil, nil)
  271. }
  272. func paginateReplyConfig(c *bm.Context) {
  273. var (
  274. err error
  275. oid, typ, category int64
  276. page = int64(conf.Conf.Reply.PageNum)
  277. pageSize = int64(conf.Conf.Reply.PageSize)
  278. )
  279. params := c.Request.Form
  280. typeStr := params.Get("type")
  281. categoryStr := params.Get("category")
  282. oidStr := params.Get("oid")
  283. operator := params.Get("operator")
  284. pageStr := params.Get("pn")
  285. pageSizeStr := params.Get("ps")
  286. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  287. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  288. }
  289. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  290. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  291. }
  292. if category, err = strconv.ParseInt(categoryStr, 10, 64); err != nil {
  293. log.Warn("strconv.ParseInt(category:%s) error(%v)", categoryStr, err)
  294. }
  295. if pageStr != "" {
  296. if page, err = strconv.ParseInt(pageStr, 10, 64); err != nil || page < 1 {
  297. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageStr, err)
  298. c.JSON(nil, ecode.RequestErr)
  299. return
  300. }
  301. }
  302. if pageSizeStr != "" {
  303. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil || pageSize < 1 || pageSize > int64(conf.Conf.Reply.PageSize) {
  304. log.Warn("strconv.ParseInt(pagesize:%s) error(%v)", pageSizeStr, err)
  305. c.JSON(nil, ecode.RequestErr)
  306. return
  307. }
  308. }
  309. configs, totalCount, pages, err := rpSvc.PaginateReplyConfig(c, int32(typ), int32(category), oid, operator, int(page-1)*int(pageSize), int(pageSize))
  310. if err != nil {
  311. log.Error("svc.PaginateReplyConfig(%d,%d,%d,%v,%d,%d) error(%v)", int32(typ), 1, oid, operator, int(page), int(pageSize), err)
  312. c.JSON(nil, err)
  313. return
  314. }
  315. data := map[string]interface{}{
  316. "page": page,
  317. "pagesize": pageSize,
  318. "pagecount": pages,
  319. "total": totalCount,
  320. "order": "default",
  321. "result": configs,
  322. }
  323. c.JSONMap(data, nil)
  324. return
  325. }
  326. func loadReplyConfig(c *bm.Context) {
  327. var (
  328. err error
  329. oid, typ, category int64
  330. )
  331. params := c.Request.Form
  332. typeStr := params.Get("type")
  333. categoryStr := params.Get("category")
  334. oidStr := params.Get("oid")
  335. if oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  336. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  337. c.JSON(nil, ecode.RequestErr)
  338. return
  339. }
  340. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  341. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  342. c.JSON(nil, ecode.RequestErr)
  343. return
  344. }
  345. if category, err = strconv.ParseInt(categoryStr, 10, 64); err != nil {
  346. log.Warn("strconv.ParseInt(category:%s) error(%v)", categoryStr, err)
  347. c.JSON(nil, ecode.RequestErr)
  348. return
  349. }
  350. config, err := rpSvc.LoadReplyConfig(c, int32(typ), int32(category), oid)
  351. if err != nil {
  352. log.Error("Svc.LoadReplyConfig(%d,%d,%d) error(%v)", int32(typ), 1, oid, err)
  353. c.JSON(nil, err)
  354. return
  355. }
  356. c.JSON(config, nil)
  357. return
  358. }
  359. // adminPassReply pass reply normal.
  360. func adminPassReply(c *bm.Context) {
  361. v := new(struct {
  362. RpID []int64 `form:"rpid,split" validate:"required"`
  363. Oid []int64 `form:"oid,split" validate:"required"`
  364. Type int32 `form:"type" validate:"required"`
  365. AdminID int64 `form:"adid"`
  366. Remark string `form:"remark"`
  367. })
  368. var err error
  369. err = c.Bind(v)
  370. if err != nil {
  371. return
  372. }
  373. if len(v.Oid) != len(v.RpID) {
  374. log.Warn("len(v.Oid) != len(v.RpID),%d != %d", len(v.Oid), len(v.RpID))
  375. c.JSON(nil, ecode.RequestErr)
  376. }
  377. adid := v.AdminID
  378. if uid, ok := c.Get("uid"); ok {
  379. adid = uid.(int64)
  380. }
  381. var adName string
  382. if uname, ok := c.Get("username"); ok {
  383. adName = uname.(string)
  384. }
  385. err = rpSvc.AdminPassReply(c, adid, adName, v.Oid, v.RpID, v.Type, v.Remark)
  386. c.JSON(nil, err)
  387. return
  388. }
  389. // adminRecoverReply recover reply normal.
  390. func adminRecoverReply(c *bm.Context) {
  391. v := new(struct {
  392. RpID int64 `form:"rpid" validate:"required"`
  393. Oid int64 `form:"oid" validate:"required"`
  394. Type int32 `form:"type" validate:"required"`
  395. AdminID int64 `form:"adid"`
  396. Remark string `form:"remark"`
  397. })
  398. var err error
  399. err = c.Bind(v)
  400. if err != nil {
  401. return
  402. }
  403. adid := v.AdminID
  404. if uid, ok := c.Get("uid"); ok {
  405. adid = uid.(int64)
  406. }
  407. var adName string
  408. if uname, ok := c.Get("username"); ok {
  409. adName = uname.(string)
  410. }
  411. err = rpSvc.AdminRecoverReply(c, adid, adName, v.Oid, v.RpID, v.Type, v.Remark)
  412. c.JSON(nil, err)
  413. return
  414. }
  415. // adminEditReply edit reply normal.
  416. func adminEditReply(c *bm.Context) {
  417. v := new(struct {
  418. RpID int64 `form:"rpid" validate:"required"`
  419. Oid int64 `form:"oid" validate:"required"`
  420. Type int32 `form:"type" validate:"required"`
  421. AdminID int64 `form:"adid"`
  422. Message string `form:"message"`
  423. Remark string `form:"remark"`
  424. })
  425. var err error
  426. err = c.Bind(v)
  427. if err != nil {
  428. return
  429. }
  430. adid := v.AdminID
  431. if uid, ok := c.Get("uid"); ok {
  432. adid = uid.(int64)
  433. }
  434. var adName string
  435. if uname, ok := c.Get("username"); ok {
  436. adName = uname.(string)
  437. }
  438. err = rpSvc.AdminEditReply(c, adid, adName, v.Oid, v.RpID, v.Type, v.Message, v.Remark)
  439. c.JSON(nil, err)
  440. return
  441. }
  442. // Compose compose struct
  443. type Compose struct {
  444. RpIDs []int64
  445. Oids []int64
  446. }
  447. // adminDelReply del reply normal.
  448. func adminDelReply(c *bm.Context) {
  449. v := new(struct {
  450. RpID []int64 `form:"rpid,split" validate:"required"`
  451. Oid []int64 `form:"oid,split" validate:"required"`
  452. Type []int32 `form:"type,split" validate:"required"`
  453. AdminID int64 `form:"adid"`
  454. Remark string `form:"remark"`
  455. Moral int32 `form:"moral"`
  456. Notify bool `form:"notify"`
  457. FTime int64 `form:"ftime"`
  458. AdName string `form:"adname"`
  459. Reason int32 `form:"reason"`
  460. FReason int32 `form:"freason"`
  461. })
  462. var err error
  463. err = c.Bind(v)
  464. if err != nil {
  465. return
  466. }
  467. if len(v.RpID) == 0 {
  468. c.JSON(nil, ecode.RequestErr)
  469. return
  470. }
  471. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  472. c.JSON(nil, ecode.RequestErr)
  473. return
  474. }
  475. tMap := make(map[int32]*Compose)
  476. for i, tp := range v.Type {
  477. if c, ok := tMap[tp]; ok {
  478. c.Oids = append(c.Oids, v.Oid[i])
  479. c.RpIDs = append(c.RpIDs, v.RpID[i])
  480. } else {
  481. c = &Compose{
  482. Oids: []int64{v.Oid[i]},
  483. RpIDs: []int64{v.RpID[i]},
  484. }
  485. tMap[tp] = c
  486. }
  487. }
  488. if uid, ok := c.Get("uid"); ok {
  489. v.AdminID = uid.(int64)
  490. }
  491. if uname, ok := c.Get("username"); ok {
  492. v.AdName = uname.(string)
  493. }
  494. for tp, com := range tMap {
  495. err = rpSvc.AdminDeleteReply(c, v.AdminID, com.Oids, com.RpIDs, v.FTime, tp, v.Moral, v.Notify, v.AdName, v.Remark, v.Reason, v.FReason)
  496. if !ecode.NothingFound.Equal(err) {
  497. err = nil
  498. }
  499. }
  500. c.JSON(nil, err)
  501. return
  502. }
  503. // callbackDelReply del reply normal.
  504. func callbackDelReply(c *bm.Context) {
  505. v := new(struct {
  506. Actor struct {
  507. AdminID int64 `json:"admin_id"`
  508. AdminName string `json:"admin_name"`
  509. } `json:"actor"`
  510. CTime int64 `json:"ctime"`
  511. Object struct {
  512. TagID int32 `json:"tag_id"`
  513. DecreaseMoral int32 `json:"decrease_moral"`
  514. BlockReasonID int32 `json:"block_reason_id"`
  515. BlockDay int64 `json:"block_day"`
  516. Reason string `json:"reason"`
  517. DisposeMode int32 `json:"dispose_mode"`
  518. State int32 `json:"state"`
  519. RID int32 `json:"rid"`
  520. } `json:"object"`
  521. Target []struct {
  522. OID int64 `json:"oid"`
  523. FID int32 `json:"fid"`
  524. EID int64 `json:"eid"`
  525. State int32 `json:"state"`
  526. } `json:"targets"`
  527. })
  528. var err error
  529. err = c.BindWith(v, binding.JSON)
  530. if err != nil {
  531. return
  532. }
  533. log.Info("callbackDelReply V:%+v", *v)
  534. if v.Object.State == 2 {
  535. for _, t := range v.Target {
  536. rpSvc.ReportIgnore(c, []int64{t.OID}, []int64{t.EID}, v.Actor.AdminID, v.Actor.AdminName, t.FID, v.Object.RID, v.Object.Reason, false)
  537. }
  538. } else if v.Object.State == 1 {
  539. for _, t := range v.Target {
  540. err = rpSvc.CallbackDeleteReply(c, v.Actor.AdminID, t.OID, t.EID, v.Object.BlockDay, t.FID, v.Object.DecreaseMoral, v.Actor.AdminName, v.Object.Reason, v.Object.TagID, v.Object.BlockReasonID)
  541. }
  542. } else if v.Object.State == 10 {
  543. for _, t := range v.Target {
  544. rpSvc.ReportStateSet(c, []int64{t.OID}, []int64{t.EID}, v.Actor.AdminID, v.Actor.AdminName, t.FID, 8, v.Object.Reason, false)
  545. }
  546. } else {
  547. log.Warn("callbackDelReply RequestErr(%d,%d)", v.Object.State, v.Object.DisposeMode)
  548. }
  549. c.JSON(nil, err)
  550. return
  551. }
  552. // adminTopReply top reply normal.
  553. func adminTopReply(c *bm.Context) {
  554. v := new(struct {
  555. RpID int64 `form:"rpid" validate:"required"`
  556. Oid int64 `form:"oid" validate:"required"`
  557. Type int32 `form:"type" validate:"required"`
  558. AdminID int64 `form:"adid"`
  559. Action uint32 `form:"action"`
  560. })
  561. var err error
  562. err = c.Bind(v)
  563. if err != nil {
  564. return
  565. }
  566. adid := v.AdminID
  567. if uid, ok := c.Get("uid"); ok {
  568. adid = uid.(int64)
  569. }
  570. var adName string
  571. if uname, ok := c.Get("username"); ok {
  572. adName = uname.(string)
  573. }
  574. err = rpSvc.AddTop(c, adid, adName, v.Oid, v.RpID, v.Type, v.Action)
  575. c.JSON(nil, err)
  576. return
  577. }
  578. // adminTopReplyLog get reply top log.
  579. func adminTopReplyLog(c *bm.Context) {
  580. v := new(struct {
  581. Oid int64 `form:"oid" `
  582. Type int32 `form:"type" `
  583. StartTime string `form:"start_time"`
  584. EndTime string `form:"end_time"`
  585. Page int64 `form:"pn"`
  586. PageSize int64 `form:"ps"`
  587. Order string `form:"order"`
  588. Sort string `form:"sort"`
  589. })
  590. var err error
  591. err = c.Bind(v)
  592. if err != nil {
  593. return
  594. }
  595. sp := model.LogSearchParam{
  596. Oid: v.Oid,
  597. Type: v.Type,
  598. CtimeFrom: v.StartTime,
  599. CtimeTo: v.EndTime,
  600. Pn: v.Page,
  601. Ps: v.PageSize,
  602. Order: v.Order,
  603. Sort: v.Sort,
  604. }
  605. data, err := rpSvc.ReplyTopLog(c, sp)
  606. res := map[string]interface{}{}
  607. res["data"] = data
  608. c.JSONMap(res, err)
  609. return
  610. }
  611. // adminMarkAsSpam make a reply as spam
  612. func adminMarkAsSpam(c *bm.Context) {
  613. v := new(struct {
  614. RpIDs []int64 `form:"rpid,split" validate:"required"`
  615. Oids []int64 `form:"oid,split" validate:"required"`
  616. AdminID int64 `form:"adid"`
  617. Remark string `form:"remark"`
  618. })
  619. var err error
  620. err = c.Bind(v)
  621. if err != nil {
  622. return
  623. }
  624. adid := v.AdminID
  625. if uid, ok := c.Get("uid"); ok {
  626. adid = uid.(int64)
  627. }
  628. var adName string
  629. if uname, ok := c.Get("username"); ok {
  630. adName = uname.(string)
  631. }
  632. err = rpSvc.MarkAsSpam(c, v.Oids, v.RpIDs, adid, adName, v.Remark)
  633. c.JSON(nil, err)
  634. return
  635. }
  636. // adminMarkAsSpam make a reply as spam
  637. func adminReplyList(c *bm.Context) {
  638. v := new(struct {
  639. RpIDs []int64 `form:"eids,split" validate:"required"`
  640. Oids []int64 `form:"oids,split" validate:"required"`
  641. IDs []int64 `form:"ids,split" validate:"required"`
  642. })
  643. var err error
  644. err = c.Bind(v)
  645. if err != nil {
  646. return
  647. }
  648. res := make(map[int64]*model.ReplyEx)
  649. if len(v.RpIDs) == len(v.IDs) && len(v.IDs) == len(v.Oids) && len(v.RpIDs) > 0 {
  650. for i := range v.IDs {
  651. ex := &model.ReplyEx{}
  652. ex.ID = v.RpIDs[i]
  653. ex.Oid = v.Oids[i]
  654. res[v.IDs[i]] = ex
  655. }
  656. var rpMap map[int64]*model.ReplyEx
  657. rpMap, err = rpSvc.ReplyList(c, v.Oids, v.RpIDs)
  658. for k, data := range res {
  659. res[k] = rpMap[data.ID]
  660. }
  661. } else {
  662. log.Error("adminReplyList request invalid(%v)", v)
  663. err = ecode.RequestErr
  664. }
  665. c.JSON(res, err)
  666. return
  667. }
  668. func topChildReply(c *bm.Context) {
  669. v := new(struct {
  670. Root int64 `form:"root" validate:"required"`
  671. Child int64 `form:"child" validate:"required"`
  672. Oid int64 `form:"oid" validate:"required"`
  673. })
  674. if err := c.Bind(v); err != nil {
  675. return
  676. }
  677. c.JSON(nil, rpSvc.TopChildReply(c, v.Root, v.Child, v.Oid))
  678. }
  679. func foldReply(c *bm.Context) {
  680. v := new(struct {
  681. Oids []int64 `form:"oids,split" validate:"required"`
  682. RpIDs []int64 `form:"rpids,split" validate:"required"`
  683. Types []int64 `form:"types,split" validate:"required"`
  684. })
  685. if err := c.Bind(v); err != nil {
  686. return
  687. }
  688. if len(v.Oids) != len(v.RpIDs) || len(v.Oids) != len(v.Types) {
  689. c.JSON(nil, ecode.RequestErr)
  690. return
  691. }
  692. c.JSON(nil, rpSvc.FoldReplies(c, v.Oids, v.Types, v.RpIDs))
  693. }