order.go 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "git.getensh.com/common/gopkgs/logger"
  6. "git.getensh.com/common/gopkgs/tasker/httptasker"
  7. "git.getensh.com/common/gopkgs/util"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "property-system-gateway/errors"
  12. param_v1 "property-system-gateway/param/v1"
  13. "property-system-gateway/pb"
  14. "property-system-gateway/pb/v1"
  15. "property-system-gateway/utils"
  16. )
  17. //
  18. // @Summary 应用订单列表
  19. // @Description 应用订单列表
  20. // @Tags 应用订单
  21. // @Accept json
  22. // @Produce json
  23. // @Param token header string true " "
  24. // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
  25. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  26. // @Param status query int false "0不过滤,1待认证 2 已通过(已购) 3 未通过"
  27. // @Success 200 {object} v1.GardenApplicationListResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1/order/application [get]
  30. func (c *Controller) GardenApplicationList(ctx *gin.Context) {
  31. // 解析参数
  32. req := &param_v1.GardenApplicationListRequest{}
  33. parseParamTask := func() error {
  34. err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenApplicationListQuery, nil)
  35. if err != nil {
  36. logger.Error("func",
  37. zap.String("call", "util.ShouldBind"),
  38. zap.String("error", err.Error()))
  39. return errors.ParamsError
  40. }
  41. return nil
  42. }
  43. // 业务处理
  44. handleServiceTask := func() error {
  45. tokenInfo, err := utils.GetSubjectValue(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. if tokenInfo.Cid == 0 {
  50. return errors.TokenFailedError
  51. }
  52. // 响应数据
  53. resp := param_v1.GardenApplicationListResponse{}
  54. rpcReq := &v1.GardenApplicationListRequest{
  55. Status: req.Status,
  56. PageSize: req.PageSize,
  57. Page: req.Page,
  58. GardenId: tokenInfo.GardenId,
  59. }
  60. rpcRsp, err := pb.System.GardenApplicationList(ctx, rpcReq)
  61. if err != nil {
  62. s, _ := json.MarshalToString(req)
  63. logger.Error("func",
  64. zap.String("call", "pb.System.GardenApplicationList"),
  65. zap.String("params", s),
  66. zap.String("error", err.Error()))
  67. return errors.ErrorTransForm(err)
  68. }
  69. if rpcRsp.List == nil {
  70. rpcRsp.List = make([]*v1.GardenApplicationItem, 0)
  71. }
  72. resp.Data = *rpcRsp
  73. ctx.JSON(http.StatusOK, resp)
  74. return nil
  75. }
  76. // 执行任务
  77. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  78. }
  79. //
  80. // @Summary 购买应用
  81. // @Description 购买应用
  82. // @Tags 应用订单
  83. // @Accept json
  84. // @Produce json
  85. // @Param token header string true " "
  86. // @Param body body v1.ApplicationOrderAddBody true "信息"
  87. // @Success 200 {object} v1.ApplicationOrderAddResponse
  88. // @Failure 500 {object} base.HTTPError
  89. // @Router /api/v1/order/application [post]
  90. func (c *Controller) ApplicationOrderAdd(ctx *gin.Context) {
  91. // 解析参数
  92. req := &param_v1.ApplicationOrderAddRequest{}
  93. parseParamTask := func() error {
  94. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ApplicationOrderAddBody)
  95. if err != nil {
  96. logger.Error("func",
  97. zap.String("call", "util.ShouldBind"),
  98. zap.String("error", err.Error()))
  99. return errors.ParamsError
  100. }
  101. return nil
  102. }
  103. // 业务处理
  104. handleServiceTask := func() error {
  105. tokenInfo, err := utils.GetSubjectValue(ctx)
  106. if err != nil {
  107. return err
  108. }
  109. if tokenInfo.Cid == 0 {
  110. return errors.TokenFailedError
  111. }
  112. // 响应数据
  113. resp := param_v1.ApplicationOrderAddResponse{}
  114. rpcReq := &v1.ApplicationOrderAddRequest{
  115. Cid: tokenInfo.Cid,
  116. ApplicationId: req.ApplicationId,
  117. GardenId: tokenInfo.GardenId,
  118. }
  119. rpcRsp, err := pb.System.ApplicationOrderAdd(ctx, rpcReq)
  120. if err != nil {
  121. s, _ := json.MarshalToString(req)
  122. logger.Error("func",
  123. zap.String("call", "pb.System.ApplicationOrderAdd"),
  124. zap.String("params", s),
  125. zap.String("error", err.Error()))
  126. return errors.ErrorTransForm(err)
  127. }
  128. resp.Data = *rpcRsp
  129. ctx.JSON(http.StatusOK, resp)
  130. return nil
  131. }
  132. // 执行任务
  133. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  134. }