trade.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. package http
  2. import (
  3. "fmt"
  4. "net/http"
  5. "time"
  6. "go-common/app/admin/main/growup/model"
  7. "go-common/library/log"
  8. "go-common/library/net/http/blademaster"
  9. "go-common/library/net/http/blademaster/render"
  10. )
  11. func goodsSync(c *blademaster.Context) {
  12. var arg = new(struct {
  13. GoodsType int `form:"goods_type" validate:"required"`
  14. })
  15. if err := c.Bind(arg); err != nil {
  16. return
  17. }
  18. eff, err := svr.SyncGoods(c, arg.GoodsType)
  19. if err != nil {
  20. log.Error("svr.SyncGoods err(%v)", err)
  21. c.JSON(nil, err)
  22. return
  23. }
  24. c.JSON(eff, nil)
  25. }
  26. func goodsUpdate(c *blademaster.Context) {
  27. var arg = new(struct {
  28. ID int64 `form:"id" validate:"required"`
  29. Discount int `form:"discount" validate:"min=1,max=100"`
  30. })
  31. if err := c.Bind(arg); err != nil {
  32. return
  33. }
  34. eff, err := svr.UpdateGoodsInfo(c, arg.Discount, arg.ID)
  35. if err != nil {
  36. log.Error("svr.UpdateGoodsInfo err(%v)", err)
  37. c.JSON(nil, err)
  38. return
  39. }
  40. c.JSON(eff, nil)
  41. }
  42. func goodsDisplay(c *blademaster.Context) {
  43. arg := new(struct {
  44. IDs []int64 `form:"ids,split" validate:"required"`
  45. Display int `form:"display" validate:"required"`
  46. })
  47. if err := c.Bind(arg); err != nil {
  48. return
  49. }
  50. eff, err := svr.UpdateGoodsDisplay(c, model.DisplayStatus(arg.Display), arg.IDs)
  51. if err != nil {
  52. log.Error("svr.UpdateGoodsDisplay err(%v)", err)
  53. c.JSON(nil, err)
  54. return
  55. }
  56. c.JSON(eff, nil)
  57. }
  58. func goodsList(c *blademaster.Context) {
  59. arg := new(struct {
  60. From int `form:"from" validate:"min=0" default:"0"`
  61. Limit int `form:"limit" validate:"min=1" default:"20"`
  62. })
  63. if err := c.Bind(arg); err != nil {
  64. return
  65. }
  66. total, list, err := svr.GoodsList(c, arg.From, arg.Limit)
  67. if err != nil {
  68. log.Error("svr.GoodsList err(%v)", err)
  69. c.JSON(nil, err)
  70. return
  71. }
  72. renderPagRes(list, total, arg.Limit)(c)
  73. }
  74. func orderList(c *blademaster.Context) {
  75. arg := new(model.OrderQueryArg)
  76. if err := c.Bind(arg); err != nil {
  77. return
  78. }
  79. total, list, err := svr.OrderList(c, arg, arg.From, arg.Limit)
  80. if err != nil {
  81. log.Error("svr.OrderList err(%v)", err)
  82. c.JSON(nil, err)
  83. return
  84. }
  85. renderPagRes(list, total, arg.Limit)(c)
  86. }
  87. func renderPagRes(list interface{}, total int64, ps int) func(c *blademaster.Context) {
  88. return func(c *blademaster.Context) {
  89. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  90. "code": 0,
  91. "message": "0",
  92. "data": list,
  93. "paging": map[string]interface{}{
  94. "page_size": ps,
  95. "total": total,
  96. },
  97. }))
  98. }
  99. }
  100. func orderExport(c *blademaster.Context) {
  101. arg := new(model.OrderQueryArg)
  102. if err := c.Bind(arg); err != nil {
  103. return
  104. }
  105. content, err := svr.OrderExport(c, arg, arg.From, arg.Limit)
  106. if err != nil {
  107. log.Error("svr.OrderExport err(%v)", err)
  108. c.JSON(nil, err)
  109. return
  110. }
  111. c.Render(http.StatusOK, CSV{
  112. Content: content,
  113. Title: fmt.Sprintf("%s-%s", time.Now().Format("2006-01-02"), "creative_order"),
  114. })
  115. }
  116. func orderStatistics(c *blademaster.Context) {
  117. arg := new(model.OrderQueryArg)
  118. if err := c.Bind(arg); err != nil {
  119. return
  120. }
  121. res, err := svr.OrderStatistics(c, arg)
  122. if err != nil {
  123. log.Error("svr.OrderStatistics err(%v)", err)
  124. c.JSON(nil, err)
  125. return
  126. }
  127. c.JSON(res, nil)
  128. }