common.go 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/feed/model/common"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. bm "go-common/library/net/http/blademaster"
  8. )
  9. func managerInfo(c *bm.Context) (uid int64, username string) {
  10. if nameInter, ok := c.Get("username"); ok {
  11. username = nameInter.(string)
  12. }
  13. if uidInter, ok := c.Get("uid"); ok {
  14. uid = uidInter.(int64)
  15. }
  16. if username == "" {
  17. cookie, err := c.Request.Cookie("username")
  18. if err != nil {
  19. log.Error("managerInfo get cookie error (%v)", err)
  20. return
  21. }
  22. username = cookie.Value
  23. c, err := c.Request.Cookie("uid")
  24. if err != nil {
  25. log.Error("managerInfo get cookie error (%v)", err)
  26. return
  27. }
  28. uidInt, _ := strconv.Atoi(c.Value)
  29. uid = int64(uidInt)
  30. }
  31. return
  32. }
  33. func cardPreview2(c *bm.Context) {
  34. var (
  35. err error
  36. title string
  37. res = map[string]interface{}{}
  38. )
  39. type Card struct {
  40. Type string `form:"type" validate:"required"`
  41. ID int64 `form:"id" validate:"required"`
  42. }
  43. card := &Card{}
  44. if err = c.Bind(card); err != nil {
  45. return
  46. }
  47. if title, err = commonSvc.CardPreview(c, card.Type, card.ID); err != nil {
  48. res["message"] = err.Error()
  49. c.JSONMap(res, ecode.RequestErr)
  50. return
  51. }
  52. titleReturn := common.CardPreview{
  53. Title: title,
  54. }
  55. c.JSON(titleReturn, nil)
  56. }
  57. func actionLog(c *bm.Context) {
  58. var (
  59. res = map[string]interface{}{}
  60. )
  61. type Log struct {
  62. Type int64 `form:"module" validate:"required"`
  63. Uame string `form:"uname"`
  64. CtimeFrom string `form:"ctime_from"`
  65. CtimeTo string `form:"ctime_to"`
  66. Ps int64 `form:"ps" default:"20"`
  67. Pn int64 `form:"pn" default:"1"`
  68. }
  69. log := &Log{}
  70. if err := c.Bind(log); err != nil {
  71. return
  72. }
  73. searchRes, err := commonSvc.LogAction(c, log.Type, log.Ps, log.Pn, log.CtimeFrom, log.CtimeTo, log.Uame)
  74. if err != nil {
  75. res["message"] = err.Error()
  76. c.JSONMap(res, ecode.RequestErr)
  77. return
  78. }
  79. res["data"] = searchRes.Item
  80. res["pager"] = searchRes.Page
  81. c.JSONMap(res, nil)
  82. }
  83. func cardType(c *bm.Context) {
  84. var (
  85. res = map[string]interface{}{}
  86. )
  87. res["data"] = commonSvc.CardType()
  88. c.JSONMap(res, nil)
  89. }