budgetstatistics.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/library/log"
  5. bm "go-common/library/net/http/blademaster"
  6. "go-common/library/net/http/blademaster/render"
  7. )
  8. func budgetDayStatistics(c *bm.Context) {
  9. v := new(struct {
  10. Type int `form:"type"`
  11. From int `form:"from" default:"0" validate:"min=0"`
  12. Limit int `form:"limit" default:"20" validate:"min=1"`
  13. })
  14. if err := c.Bind(v); err != nil {
  15. return
  16. }
  17. total, infos, err := svr.BudgetDayStatistics(c, v.Type, v.From, v.Limit)
  18. if err != nil {
  19. log.Error("s.budgetDayStatistics error(%v)", err)
  20. c.JSON(nil, err)
  21. return
  22. }
  23. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  24. "code": 0,
  25. "data": infos,
  26. "paging": map[string]int{
  27. "page_size": v.Limit,
  28. "total": total,
  29. },
  30. }))
  31. }
  32. func budgetDayGraph(c *bm.Context) {
  33. v := new(struct {
  34. Type int `form:"type"`
  35. })
  36. if err := c.Bind(v); err != nil {
  37. return
  38. }
  39. info, err := svr.BudgetDayGraph(c, v.Type)
  40. if err != nil {
  41. log.Error("s.budgetDayGraph error(%v)", err)
  42. c.JSON(nil, err)
  43. return
  44. }
  45. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  46. "code": 0,
  47. "data": info,
  48. }))
  49. }
  50. func budgetMonthStatistics(c *bm.Context) {
  51. v := new(struct {
  52. Type int `form:"type"`
  53. From int `form:"from" default:"0" validate:"min=0"`
  54. Limit int `form:"limit" default:"20" validate:"min=1"`
  55. })
  56. if err := c.Bind(v); err != nil {
  57. return
  58. }
  59. total, infos, err := svr.BudgetMonthStatistics(c, v.Type, v.From, v.Limit)
  60. if err != nil {
  61. log.Error("s.budgetMonthStatistics BudgetMonthStatistics error(%v)", err)
  62. c.JSON(nil, err)
  63. return
  64. }
  65. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  66. "code": 0,
  67. "data": infos,
  68. "paging": map[string]int{
  69. "page_size": v.Limit,
  70. "total": total,
  71. },
  72. }))
  73. }