up_trend.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. package http
  2. import (
  3. "go-common/app/admin/main/up/util"
  4. "go-common/library/ecode"
  5. bm "go-common/library/net/http/blademaster"
  6. "time"
  7. )
  8. func yesterday(c *bm.Context) {
  9. v := new(struct {
  10. Date int64 `form:"date" validate:"required"`
  11. })
  12. if err := c.Bind(v); err != nil {
  13. c.JSON(nil, ecode.RequestErr)
  14. return
  15. }
  16. res, err := Svc.Crmservice.QueryYesterday(c, time.Unix(v.Date, 0))
  17. if err != nil {
  18. c.JSON(nil, err)
  19. return
  20. }
  21. c.JSON(res, err)
  22. }
  23. func trend(c *bm.Context) {
  24. v := new(struct {
  25. StatType int `form:"stat_type" validate:"required"`
  26. DateType int `form:"date_type" validate:"required"`
  27. })
  28. if err := c.Bind(v); err != nil {
  29. c.JSON(nil, ecode.RequestErr)
  30. }
  31. endDate := util.TruncateDate(time.Now())
  32. var days = 7
  33. if v.DateType == 2 {
  34. days = 30
  35. }
  36. data, err := Svc.Crmservice.QueryTrend(c, v.StatType, endDate, days)
  37. if err != nil {
  38. c.JSON(nil, err)
  39. return
  40. }
  41. c.JSON(data, nil)
  42. }
  43. func trendDetail(c *bm.Context) {
  44. v := new(struct {
  45. DateType int `form:"date_type" validate:"required"`
  46. })
  47. if err := c.Bind(v); err != nil {
  48. c.JSON(nil, ecode.RequestErr)
  49. return
  50. }
  51. endDate := util.TruncateDate(time.Now())
  52. var days = 7
  53. if v.DateType == 2 {
  54. days = 30
  55. }
  56. data, err := Svc.Crmservice.QueryDetail(c, endDate, days)
  57. if err != nil {
  58. c.JSON(nil, err)
  59. return
  60. }
  61. c.JSON(data, nil)
  62. }