exchange.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. package http
  2. import (
  3. "net/http"
  4. "go-common/library/ecode"
  5. "go-common/library/log"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/net/http/blademaster/render"
  8. )
  9. func goodsState(c *bm.Context) {
  10. data, err := svc.GoodsState(c)
  11. if err != nil {
  12. log.Error("growup svc.GoodsState error(%v)", err)
  13. c.JSON(nil, err)
  14. return
  15. }
  16. c.JSON(data, nil)
  17. }
  18. func goodsShow(c *bm.Context) {
  19. midI, ok := c.Get("mid")
  20. if !ok {
  21. c.JSON(nil, ecode.NoLogin)
  22. return
  23. }
  24. mid, _ := midI.(int64)
  25. data, err := svc.GoodsShow(c, mid)
  26. if err != nil {
  27. log.Error("growup svc.GoodsShow error(%v)", err)
  28. c.JSON(nil, err)
  29. return
  30. }
  31. c.JSON(data, nil)
  32. }
  33. func goodsRecord(c *bm.Context) {
  34. v := new(struct {
  35. Page int `form:"page" default:"1" validate:"min=1"`
  36. Size int `form:"size" default:"20" validate:"min=1"`
  37. })
  38. if err := c.Bind(v); err != nil {
  39. return
  40. }
  41. midI, ok := c.Get("mid")
  42. if !ok {
  43. c.JSON(nil, ecode.NoLogin)
  44. return
  45. }
  46. mid, _ := midI.(int64)
  47. data, total, err := svc.GoodsRecord(c, mid, v.Page, v.Size)
  48. if err != nil {
  49. log.Error("growup svc.GoodsRecord error(%v)", err)
  50. c.JSON(nil, err)
  51. return
  52. }
  53. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  54. "code": 0,
  55. "message": "0",
  56. "data": data,
  57. "paging": map[string]int{
  58. "page_size": v.Size,
  59. "total": total,
  60. },
  61. }))
  62. }
  63. func goodsBuy(c *bm.Context) {
  64. var err error
  65. v := new(struct {
  66. ProductID string `form:"product_id" validate:"required"`
  67. GoodsType int `form:"goods_type" validate:"required"`
  68. Price int64 `form:"price" validate:"required"`
  69. })
  70. if err = c.Bind(v); err != nil {
  71. return
  72. }
  73. midI, ok := c.Get("mid")
  74. if !ok {
  75. c.JSON(nil, ecode.NoLogin)
  76. return
  77. }
  78. mid, _ := midI.(int64)
  79. if err = svc.GoodsBuy(c, mid, v.ProductID, v.GoodsType, v.Price); err != nil {
  80. c.Render(http.StatusOK, render.MapJSON(map[string]interface{}{
  81. "code": 500,
  82. "message": err.Error(),
  83. }))
  84. } else {
  85. c.JSON(nil, nil)
  86. }
  87. }