msg_package.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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. // @Success 200 {object} v1.MsgPackageListResponse
  27. // @Failure 500 {object} base.HTTPError
  28. // @Router /api/v1/msg_package [get]
  29. func (c *Controller) MsgPackageList(ctx *gin.Context) {
  30. // 解析参数
  31. req := &param_v1.MsgPackageListRequest{}
  32. parseParamTask := func() error {
  33. err := util.ShouldBind(ctx, &req.Header, nil, &req.MsgPackageListQuery, nil)
  34. if err != nil {
  35. logger.Error("func",
  36. zap.String("call", "util.ShouldBind"),
  37. zap.String("error", err.Error()))
  38. return errors.ParamsError
  39. }
  40. return nil
  41. }
  42. // 业务处理
  43. handleServiceTask := func() error {
  44. //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  45. //if err != nil {
  46. // return err
  47. //}
  48. // 响应数据
  49. resp := param_v1.MsgPackageListResponse{}
  50. rpcReq := &v1.MsgPackageListRequest{
  51. //PackageId: req.PackageId,
  52. PageSize: req.PageSize,
  53. Page: req.Page,
  54. }
  55. rpcRsp, err := pb.Common.MsgPackageList(ctx, rpcReq)
  56. if err != nil {
  57. s, _ := json.MarshalToString(req)
  58. logger.Error("func",
  59. zap.String("call", "pb.Common.MsgPackageList"),
  60. zap.String("params", s),
  61. zap.String("error", err.Error()))
  62. return errors.ErrorTransForm(err)
  63. }
  64. if rpcRsp.List == nil {
  65. rpcRsp.List = make([]*v1.MsgPackageItem, 0)
  66. }
  67. resp.Data = *rpcRsp
  68. ctx.JSON(http.StatusOK, resp)
  69. return nil
  70. }
  71. // 执行任务
  72. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  73. }
  74. //
  75. // @Summary 短信套餐订单列表
  76. // @Description 短信套餐订单列表
  77. // @Tags 短信套餐
  78. // @Accept json
  79. // @Produce json
  80. // @Param token header string true " "
  81. // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
  82. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  83. // @Param status query int false "0不过滤,1待认证 2 已通过(已购) 3 未通过"
  84. // @Success 200 {object} v1.MsgPackageOrderListResponse
  85. // @Failure 500 {object} base.HTTPError
  86. // @Router /api/v1/msg_package/order [get]
  87. func (c *Controller) MsgPackageOrderList(ctx *gin.Context) {
  88. // 解析参数
  89. req := &param_v1.MsgPackageOrderListRequest{}
  90. parseParamTask := func() error {
  91. err := util.ShouldBind(ctx, &req.Header, nil, &req.MsgPackageOrderListQuery, nil)
  92. if err != nil {
  93. logger.Error("func",
  94. zap.String("call", "util.ShouldBind"),
  95. zap.String("error", err.Error()))
  96. return errors.ParamsError
  97. }
  98. return nil
  99. }
  100. // 业务处理
  101. handleServiceTask := func() error {
  102. tokenInfo, err := utils.GetSubjectValue(ctx)
  103. if err != nil {
  104. return err
  105. }
  106. if tokenInfo.Cid == 0 {
  107. return errors.TokenFailedError
  108. }
  109. // 响应数据
  110. resp := param_v1.MsgPackageOrderListResponse{}
  111. rpcReq := &v1.MsgPackageOrderListRequest{
  112. Status: int64(req.Status),
  113. PageSize: req.PageSize,
  114. Page: req.Page,
  115. GardenId: tokenInfo.GardenId,
  116. }
  117. rpcRsp, err := pb.System.MsgPackageOrderList(ctx, rpcReq)
  118. if err != nil {
  119. s, _ := json.MarshalToString(req)
  120. logger.Error("func",
  121. zap.String("call", "pb.System.MsgPackageOrderList"),
  122. zap.String("params", s),
  123. zap.String("error", err.Error()))
  124. return errors.ErrorTransForm(err)
  125. }
  126. if rpcRsp.List == nil {
  127. rpcRsp.List = make([]*v1.MsgPackageOrderItem, 0)
  128. }
  129. resp.Data = *rpcRsp
  130. ctx.JSON(http.StatusOK, resp)
  131. return nil
  132. }
  133. // 执行任务
  134. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  135. }
  136. //
  137. // @Summary 购买短信套餐
  138. // @Description 购买短信套餐
  139. // @Tags 短信套餐
  140. // @Accept json
  141. // @Produce json
  142. // @Param token header string true " "
  143. // @Param body body v1.MsgPackageOrderAddBody true "信息"
  144. // @Success 200 {object} v1.MsgPackageOrderAddResponse
  145. // @Failure 500 {object} base.HTTPError
  146. // @Router /api/v1/msg_package/order [post]
  147. func (c *Controller) MsgPackageOrderAdd(ctx *gin.Context) {
  148. // 解析参数
  149. req := &param_v1.MsgPackageOrderAddRequest{}
  150. parseParamTask := func() error {
  151. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.MsgPackageOrderAddBody)
  152. if err != nil {
  153. logger.Error("func",
  154. zap.String("call", "util.ShouldBind"),
  155. zap.String("error", err.Error()))
  156. return errors.ParamsError
  157. }
  158. return nil
  159. }
  160. // 业务处理
  161. handleServiceTask := func() error {
  162. tokenInfo, err := utils.GetSubjectValue(ctx)
  163. if err != nil {
  164. return err
  165. }
  166. if tokenInfo.Cid == 0 {
  167. return errors.TokenFailedError
  168. }
  169. // 响应数据
  170. resp := param_v1.MsgPackageOrderAddResponse{}
  171. rpcReq := &v1.MsgPackageOrderAddRequest{
  172. Cid: tokenInfo.Cid,
  173. PackageCount: req.PackageCount,
  174. PackageId: req.PackageId,
  175. GardenId: tokenInfo.GardenId,
  176. Amount: req.Amount,
  177. }
  178. rpcRsp, err := pb.System.MsgPackageOrderAdd(ctx, rpcReq)
  179. if err != nil {
  180. s, _ := json.MarshalToString(req)
  181. logger.Error("func",
  182. zap.String("call", "pb.System.MsgPackageOrderAdd"),
  183. zap.String("params", s),
  184. zap.String("error", err.Error()))
  185. return errors.ErrorTransForm(err)
  186. }
  187. resp.Data = *rpcRsp
  188. ctx.JSON(http.StatusOK, resp)
  189. return nil
  190. }
  191. // 执行任务
  192. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  193. }