log.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package common
  2. import (
  3. "encoding/json"
  4. "net/url"
  5. "strconv"
  6. "go-common/app/admin/main/feed/model/common"
  7. searchModel "go-common/app/admin/main/search/model"
  8. bm "go-common/library/net/http/blademaster"
  9. )
  10. const (
  11. logURL = "/x/admin/search/log"
  12. )
  13. //LogAction log action
  14. func (s *Service) LogAction(c *bm.Context, typ, ps, pn int64, ctimeFrom, ctimeTo, uName string) (res *common.LogManagers, err error) {
  15. var (
  16. items []*common.LogManager
  17. )
  18. res = &common.LogManagers{}
  19. params := url.Values{}
  20. params.Set("appid", "log_audit")
  21. params.Set("business", strconv.FormatUint(common.BusinessID, 10))
  22. params.Set("order", "ctime")
  23. params.Set("type", strconv.FormatInt(typ, 10))
  24. params.Set("ps", strconv.FormatInt(ps, 10))
  25. params.Set("pn", strconv.FormatInt(pn, 10))
  26. if ctimeFrom != "" {
  27. params.Set("ctime_from", ctimeFrom)
  28. }
  29. if ctimeTo != "" {
  30. params.Set("ctime_to", ctimeTo)
  31. }
  32. if uName != "" {
  33. params.Set("uname", uName)
  34. }
  35. type log struct {
  36. Code int `json:"code"`
  37. Data *searchModel.SearchResult `json:"data"`
  38. }
  39. l := &log{}
  40. if err = s.client.Get(c, s.managerURL+logURL, "", params, l); err != nil {
  41. return
  42. }
  43. var logS []*common.LogSearch
  44. for _, v := range l.Data.Result {
  45. log := &common.LogSearch{}
  46. if err = json.Unmarshal(v, log); err != nil {
  47. return
  48. }
  49. logS = append(logS, log)
  50. }
  51. for _, v := range logS {
  52. tmp := &common.LogManager{
  53. OID: v.OID,
  54. Uname: v.Uname,
  55. UID: v.UID,
  56. Type: v.Type,
  57. ExtraData: v.ExtraData,
  58. Action: v.Action,
  59. CTime: v.CTime,
  60. }
  61. items = append(items, tmp)
  62. }
  63. res.Item = items
  64. res.Page.TotalItems = int(l.Data.Page.Total)
  65. res.Page.PageSize = l.Data.Page.Ps
  66. res.Page.CurrentPage = l.Data.Page.Pn
  67. return
  68. }