report.go 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/admin/main/reply/conf"
  6. "go-common/app/admin/main/reply/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. )
  11. func reportSearch(c *bm.Context) {
  12. var (
  13. err error
  14. typ, startTime, endTime int64
  15. page = int64(conf.Conf.Reply.PageNum)
  16. pageSize = int64(conf.Conf.Reply.PageSize)
  17. sp = &model.SearchReportParams{}
  18. )
  19. params := c.Request.Form
  20. typeStr := params.Get("type")
  21. oidStr := params.Get("oid")
  22. uidStr := params.Get("uid")
  23. startTimeStr := params.Get("start_time")
  24. endTimeStr := params.Get("end_time")
  25. pageStr := params.Get("page")
  26. pageSizeStr := params.Get("pagesize")
  27. // parse params
  28. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  29. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  30. c.JSON(nil, ecode.RequestErr)
  31. return
  32. }
  33. if oidStr != "" {
  34. if sp.Oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  35. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  36. c.JSON(nil, ecode.RequestErr)
  37. return
  38. }
  39. }
  40. if uidStr != "" {
  41. if sp.UID, err = strconv.ParseInt(uidStr, 10, 64); err != nil {
  42. log.Warn("strconv.ParseInt(uid:%s) error(%v)", uidStr, err)
  43. c.JSON(nil, ecode.RequestErr)
  44. return
  45. }
  46. }
  47. if startTimeStr != "" {
  48. if startTime, err = strconv.ParseInt(startTimeStr, 10, 64); err == nil {
  49. sp.StartTime = time.Unix(startTime, 0).Format(model.DateFormat)
  50. } else {
  51. var t time.Time
  52. t, err = time.Parse("2006-01-02", startTimeStr)
  53. if err == nil {
  54. sp.StartTime = t.Format(model.DateFormat)
  55. } else {
  56. sp.StartTime = startTimeStr
  57. }
  58. }
  59. }
  60. if endTimeStr != "" {
  61. if endTime, err = strconv.ParseInt(endTimeStr, 10, 64); err == nil {
  62. sp.EndTime = time.Unix(endTime, 0).Format(model.DateFormat)
  63. } else {
  64. var t time.Time
  65. t, err = time.Parse("2006-01-02", endTimeStr)
  66. if err == nil {
  67. sp.EndTime = t.Format(model.DateFormat)
  68. } else {
  69. sp.EndTime = endTimeStr
  70. }
  71. }
  72. } else if startTimeStr != "" {
  73. t := time.Now()
  74. sp.EndTime = t.Format(model.DateFormat)
  75. }
  76. if pageStr != "" {
  77. if page, err = strconv.ParseInt(pageStr, 10, 64); err != nil || page < 1 {
  78. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageStr, err)
  79. c.JSON(nil, ecode.RequestErr)
  80. return
  81. }
  82. }
  83. if pageSizeStr != "" {
  84. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil || pageSize < 1 || pageSize > int64(conf.Conf.Reply.PageSize) {
  85. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageSizeStr, err)
  86. c.JSON(nil, ecode.RequestErr)
  87. return
  88. }
  89. }
  90. sp.Type = int32(typ)
  91. sp.Reason = params.Get("reason")
  92. sp.Typeids = params.Get("typeids")
  93. sp.Keyword = params.Get("keyword")
  94. sp.Nickname = params.Get("nickname")
  95. sp.States = params.Get("states")
  96. sp.Order = params.Get("order")
  97. sp.Sort = params.Get("sort")
  98. rpts, err := rpSvc.ReportSearch(c, sp, page, pageSize)
  99. if err != nil {
  100. log.Error("rpSvc.ReportSearch(%d,%d,%v) error(%v)", page, pageSize, sp, err)
  101. c.JSON(nil, err)
  102. return
  103. }
  104. res := map[string]interface{}{}
  105. res["data"] = rpts
  106. c.JSONMap(res, nil)
  107. }
  108. func reportDel(c *bm.Context) {
  109. v := new(struct {
  110. RpID []int64 `form:"rpid,split" validate:"required"`
  111. Oid []int64 `form:"oid,split" validate:"required"`
  112. Type []int32 `form:"type,split" validate:"required"`
  113. AdminID int64 `form:"adid"`
  114. Remark string `form:"remark"`
  115. Moral int32 `form:"moral"`
  116. Notify bool `form:"notify"`
  117. FTime int64 `form:"ftime"`
  118. AdName string `form:"adname"`
  119. FReason int32 `form:"freason"`
  120. Audit int32 `form:"audit"`
  121. Reason int32 `form:"reason"`
  122. Content string `form:"reason_content"`
  123. })
  124. err := c.Bind(v)
  125. if err != nil {
  126. return
  127. }
  128. if len(v.RpID) == 0 {
  129. c.JSON(nil, ecode.RequestErr)
  130. return
  131. }
  132. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  133. c.JSON(nil, ecode.RequestErr)
  134. return
  135. }
  136. // reason没传修改为-1而不是0
  137. params := c.Request.Form
  138. if params.Get("reason") == "" {
  139. v.Reason = -1
  140. }
  141. tMap := make(map[int32]*Compose)
  142. for i, tp := range v.Type {
  143. if c, ok := tMap[tp]; ok {
  144. c.Oids = append(c.Oids, v.Oid[i])
  145. c.RpIDs = append(c.RpIDs, v.RpID[i])
  146. } else {
  147. c = &Compose{
  148. Oids: []int64{v.Oid[i]},
  149. RpIDs: []int64{v.RpID[i]},
  150. }
  151. tMap[tp] = c
  152. }
  153. }
  154. adid := v.AdminID
  155. if uid, ok := c.Get("uid"); ok {
  156. adid = uid.(int64)
  157. }
  158. adname := v.AdName
  159. if username, ok := c.Get("username"); ok {
  160. adname = username.(string)
  161. }
  162. for tp, com := range tMap {
  163. err = rpSvc.ReportDel(c, com.Oids, com.RpIDs, adid, v.FTime, tp, v.Audit, v.Moral, v.Reason, v.FReason, v.Notify, adname, v.Remark, v.Content)
  164. if err != nil {
  165. c.JSON(nil, err)
  166. return
  167. }
  168. }
  169. c.JSON(nil, err)
  170. return
  171. }
  172. func reportIgnore(c *bm.Context) {
  173. v := new(struct {
  174. RpID []int64 `form:"rpid,split" validate:"required"`
  175. Oid []int64 `form:"oid,split" validate:"required"`
  176. Type []int32 `form:"type,split" validate:"required"`
  177. AdminID int64 `form:"adid"`
  178. Remark string `form:"remark"`
  179. Audit int32 `form:"audit"`
  180. })
  181. err := c.Bind(v)
  182. if err != nil {
  183. return
  184. }
  185. if len(v.RpID) == 0 {
  186. c.JSON(nil, ecode.RequestErr)
  187. return
  188. }
  189. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  190. c.JSON(nil, ecode.RequestErr)
  191. return
  192. }
  193. tMap := make(map[int32]*Compose)
  194. for i, tp := range v.Type {
  195. if c, ok := tMap[tp]; ok {
  196. c.Oids = append(c.Oids, v.Oid[i])
  197. c.RpIDs = append(c.RpIDs, v.RpID[i])
  198. } else {
  199. c = &Compose{
  200. Oids: []int64{v.Oid[i]},
  201. RpIDs: []int64{v.RpID[i]},
  202. }
  203. tMap[tp] = c
  204. }
  205. }
  206. adid := v.AdminID
  207. if uid, ok := c.Get("uid"); ok {
  208. adid = uid.(int64)
  209. }
  210. var adName string
  211. if uname, ok := c.Get("username"); ok {
  212. adName = uname.(string)
  213. }
  214. for tp, com := range tMap {
  215. err = rpSvc.ReportIgnore(c, com.Oids, com.RpIDs, adid, adName, tp, v.Audit, v.Remark, true)
  216. }
  217. c.JSON(nil, err)
  218. return
  219. }
  220. func reportRecover(c *bm.Context) {
  221. v := new(struct {
  222. RpID []int64 `form:"rpid,split" validate:"required"`
  223. Oid []int64 `form:"oid,split" validate:"required"`
  224. Type []int32 `form:"type,split" validate:"required"`
  225. AdminID int64 `form:"adid"`
  226. Remark string `form:"remark"`
  227. Audit int32 `form:"audit"`
  228. })
  229. err := c.Bind(v)
  230. if err != nil {
  231. return
  232. }
  233. if len(v.RpID) == 0 {
  234. c.JSON(nil, ecode.RequestErr)
  235. return
  236. }
  237. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  238. c.JSON(nil, ecode.RequestErr)
  239. return
  240. }
  241. tMap := make(map[int32]*Compose)
  242. for i, tp := range v.Type {
  243. if c, ok := tMap[tp]; ok {
  244. c.Oids = append(c.Oids, v.Oid[i])
  245. c.RpIDs = append(c.RpIDs, v.RpID[i])
  246. } else {
  247. c = &Compose{
  248. Oids: []int64{v.Oid[i]},
  249. RpIDs: []int64{v.RpID[i]},
  250. }
  251. tMap[tp] = c
  252. }
  253. }
  254. adid := v.AdminID
  255. if uid, ok := c.Get("uid"); ok {
  256. adid = uid.(int64)
  257. }
  258. for tp, com := range tMap {
  259. err = rpSvc.ReportRecover(c, com.Oids, com.RpIDs, adid, tp, v.Audit, v.Remark)
  260. }
  261. c.JSON(nil, err)
  262. }
  263. func reportTransfer(c *bm.Context) {
  264. v := new(struct {
  265. RpID []int64 `form:"rpid,split" validate:"required"`
  266. Oid []int64 `form:"oid,split" validate:"required"`
  267. Type []int32 `form:"type,split" validate:"required"`
  268. AdminID int64 `form:"adid"`
  269. Remark string `form:"remark"`
  270. Audit int32 `form:"audit"`
  271. })
  272. err := c.Bind(v)
  273. if err != nil {
  274. return
  275. }
  276. if len(v.RpID) == 0 {
  277. c.JSON(nil, ecode.RequestErr)
  278. return
  279. }
  280. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  281. c.JSON(nil, ecode.RequestErr)
  282. return
  283. }
  284. tMap := make(map[int32]*Compose)
  285. for i, tp := range v.Type {
  286. if c, ok := tMap[tp]; ok {
  287. c.Oids = append(c.Oids, v.Oid[i])
  288. c.RpIDs = append(c.RpIDs, v.RpID[i])
  289. } else {
  290. c = &Compose{
  291. Oids: []int64{v.Oid[i]},
  292. RpIDs: []int64{v.RpID[i]},
  293. }
  294. tMap[tp] = c
  295. }
  296. }
  297. adid := v.AdminID
  298. if uid, ok := c.Get("uid"); ok {
  299. adid = uid.(int64)
  300. }
  301. var adName string
  302. if uname, ok := c.Get("username"); ok {
  303. adName = uname.(string)
  304. }
  305. for tp, com := range tMap {
  306. err = rpSvc.ReportTransfer(c, com.Oids, com.RpIDs, adid, adName, tp, v.Audit, v.Remark)
  307. }
  308. c.JSON(nil, err)
  309. }
  310. func reportStateSet(c *bm.Context) {
  311. v := new(struct {
  312. RpID []int64 `form:"rpid,split" validate:"required"`
  313. Oid []int64 `form:"oid,split" validate:"required"`
  314. Type []int32 `form:"type,split" validate:"required"`
  315. AdminID int64 `form:"adid"`
  316. AdName string `form:"adname"`
  317. Remark string `form:"remark"`
  318. State int32 `form:"state"`
  319. })
  320. err := c.Bind(v)
  321. if err != nil {
  322. return
  323. }
  324. if len(v.RpID) == 0 {
  325. c.JSON(nil, ecode.RequestErr)
  326. return
  327. }
  328. if len(v.RpID) != len(v.Oid) || len(v.RpID) != len(v.Type) {
  329. c.JSON(nil, ecode.RequestErr)
  330. return
  331. }
  332. tMap := make(map[int32]*Compose)
  333. for i, tp := range v.Type {
  334. if c, ok := tMap[tp]; ok {
  335. c.Oids = append(c.Oids, v.Oid[i])
  336. c.RpIDs = append(c.RpIDs, v.RpID[i])
  337. } else {
  338. c = &Compose{
  339. Oids: []int64{v.Oid[i]},
  340. RpIDs: []int64{v.RpID[i]},
  341. }
  342. tMap[tp] = c
  343. }
  344. }
  345. if uid, ok := c.Get("uid"); ok {
  346. v.AdminID = uid.(int64)
  347. }
  348. if uname, ok := c.Get("username"); ok {
  349. v.AdName = uname.(string)
  350. }
  351. for tp, com := range tMap {
  352. err = rpSvc.ReportStateSet(c, com.Oids, com.RpIDs, v.AdminID, v.AdName, tp, v.State, v.Remark, true)
  353. }
  354. c.JSON(nil, err)
  355. }