order.go 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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-company-gateway/errors"
  12. param_v1 "property-company-gateway/param/v1"
  13. "property-company-gateway/pb"
  14. "property-company-gateway/pb/v1"
  15. "property-company-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.CompanyPackageListResponse
  28. // @Failure 500 {object} base.HTTPError
  29. // @Router /api/v1/order/package [get]
  30. func (c *Controller) CompanyPackageList(ctx *gin.Context) {
  31. // 解析参数
  32. req := &param_v1.CompanyPackageListRequest{}
  33. parseParamTask := func() error {
  34. err := util.ShouldBind(ctx, &req.Header, nil, &req.CompanyPackageListQuery, 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.GetJwtTokenInfo(ctx)
  46. if err != nil {
  47. return err
  48. }
  49. if tokenInfo.Cid == 0 {
  50. return errors.TokenFailedError
  51. }
  52. // 响应数据
  53. resp := param_v1.CompanyPackageListResponse{}
  54. rpcReq := &v1.CompanyPackageListRequest{
  55. Status: req.Status,
  56. PageSize: req.PageSize,
  57. Page: req.Page,
  58. Cid: tokenInfo.Cid,
  59. }
  60. rpcRsp, err := pb.System.CompanyPackageList(ctx, rpcReq)
  61. if err != nil {
  62. s, _ := json.MarshalToString(req)
  63. logger.Error("func",
  64. zap.String("call", "pb.System.CompanyPackageList"),
  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.CompanyPackageItem, 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 page query int true "第几页,1为起始页, -1 不分页返回所有"
  87. // @Param page_size query int false "每页条数,-1 不分页返回所有"
  88. // @Success 200 {object} v1.CompanyPackageListResponse
  89. // @Failure 500 {object} base.HTTPError
  90. // @Router /api/v1/order/package_for_garden [get]
  91. func (c *Controller) CompanyPackageListForGarden(ctx *gin.Context) {
  92. // 解析参数
  93. req := &param_v1.CompanyPackageListRequest{}
  94. parseParamTask := func() error {
  95. err := util.ShouldBind(ctx, &req.Header, nil, &req.CompanyPackageListQuery, nil)
  96. if err != nil {
  97. logger.Error("func",
  98. zap.String("call", "util.ShouldBind"),
  99. zap.String("error", err.Error()))
  100. return errors.ParamsError
  101. }
  102. return nil
  103. }
  104. // 业务处理
  105. handleServiceTask := func() error {
  106. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  107. if err != nil {
  108. return err
  109. }
  110. if tokenInfo.Cid == 0 {
  111. return errors.TokenFailedError
  112. }
  113. // 响应数据
  114. resp := param_v1.CompanyPackageListResponse{}
  115. rpcReq := &v1.CompanyPackageListRequest{
  116. Status: 2,
  117. PageSize: req.PageSize,
  118. Page: req.Page,
  119. Cid: tokenInfo.Cid,
  120. ForGarden: true,
  121. }
  122. rpcRsp, err := pb.System.CompanyPackageList(ctx, rpcReq)
  123. if err != nil {
  124. s, _ := json.MarshalToString(req)
  125. logger.Error("func",
  126. zap.String("call", "pb.System.CompanyPackageList"),
  127. zap.String("params", s),
  128. zap.String("error", err.Error()))
  129. return errors.ErrorTransForm(err)
  130. }
  131. if rpcRsp.List == nil {
  132. rpcRsp.List = make([]*v1.CompanyPackageItem, 0)
  133. }
  134. resp.Data = *rpcRsp
  135. ctx.JSON(http.StatusOK, resp)
  136. return nil
  137. }
  138. // 执行任务
  139. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  140. }
  141. //
  142. // @Summary 新增套餐
  143. // @Description 新增套餐
  144. // @Tags 公司套餐
  145. // @Accept json
  146. // @Produce json
  147. // @Param token header string true " "
  148. // @Param body body v1.PackageOrderAddBody true "信息"
  149. // @Success 200 {object} v1.PackageOrderAddResponse
  150. // @Failure 500 {object} base.HTTPError
  151. // @Router /api/v1/order/package [post]
  152. func (c *Controller) PackageOrderAdd(ctx *gin.Context) {
  153. // 解析参数
  154. req := &param_v1.PackageOrderAddRequest{}
  155. parseParamTask := func() error {
  156. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PackageOrderAddBody)
  157. if err != nil {
  158. logger.Error("func",
  159. zap.String("call", "util.ShouldBind"),
  160. zap.String("error", err.Error()))
  161. return errors.ParamsError
  162. }
  163. return nil
  164. }
  165. // 业务处理
  166. handleServiceTask := func() error {
  167. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  168. if err != nil {
  169. return err
  170. }
  171. if tokenInfo.Cid == 0 {
  172. return errors.TokenFailedError
  173. }
  174. // 响应数据
  175. resp := param_v1.PackageOrderAddResponse{}
  176. rpcReq := &v1.PackageOrderAddRequest{
  177. Cid: tokenInfo.Cid,
  178. PackageId: req.PackageId,
  179. Period: req.Period,
  180. GardenCount: 1,
  181. Amount: req.Amount,
  182. CompanyName: tokenInfo.CompanyName,
  183. OrderType: 1,
  184. ShouldAccess: false,
  185. }
  186. rpcRsp, err := pb.System.PackageOrderAdd(ctx, rpcReq)
  187. if err != nil {
  188. s, _ := json.MarshalToString(req)
  189. logger.Error("func",
  190. zap.String("call", "pb.System.PackageOrderAdd"),
  191. zap.String("params", s),
  192. zap.String("error", err.Error()))
  193. return errors.ErrorTransForm(err)
  194. }
  195. resp.Data = *rpcRsp
  196. ctx.JSON(http.StatusOK, resp)
  197. return nil
  198. }
  199. // 执行任务
  200. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  201. }
  202. //
  203. // @Summary 套餐续费
  204. // @Description 套餐续费
  205. // @Tags 公司套餐
  206. // @Accept json
  207. // @Produce json
  208. // @Param token header string true " "
  209. // @Param body body v1.PackageOrderAddRenewBody true "信息"
  210. // @Success 200 {object} v1.PackageOrderAddRenewResponse
  211. // @Failure 500 {object} base.HTTPError
  212. // @Router /api/v1/order/renew [post]
  213. func (c *Controller) PackageOrderAddRenew(ctx *gin.Context) {
  214. // 解析参数
  215. req := &param_v1.PackageOrderAddRenewRequest{}
  216. parseParamTask := func() error {
  217. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PackageOrderAddRenewBody)
  218. if err != nil {
  219. logger.Error("func",
  220. zap.String("call", "util.ShouldBind"),
  221. zap.String("error", err.Error()))
  222. return errors.ParamsError
  223. }
  224. return nil
  225. }
  226. // 业务处理
  227. handleServiceTask := func() error {
  228. //tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  229. //if err != nil {
  230. // return err
  231. //}
  232. // 响应数据
  233. resp := param_v1.PackageOrderAddRenewResponse{}
  234. rpcReq := &v1.PackageOrderAddRequest{
  235. PackageId: req.PackageId,
  236. Period: req.Period,
  237. GardenCount: 1,
  238. Amount: req.Amount,
  239. GardenId: req.GardenId,
  240. OrderType: 2,
  241. ShouldAccess: false,
  242. }
  243. rpcRsp, err := pb.System.PackageOrderAdd(ctx, rpcReq)
  244. if err != nil {
  245. s, _ := json.MarshalToString(req)
  246. logger.Error("func",
  247. zap.String("call", "pb.System.PackageOrderAdd"),
  248. zap.String("params", s),
  249. zap.String("error", err.Error()))
  250. return errors.ErrorTransForm(err)
  251. }
  252. resp.Data = *rpcRsp
  253. ctx.JSON(http.StatusOK, resp)
  254. return nil
  255. }
  256. // 执行任务
  257. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  258. }