123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- // Copyright 2019 github.com. All rights reserved.
- // Use of this source code is governed by github.com.
- package v1
- import (
- "git.getensh.com/common/gopkgs/logger"
- "git.getensh.com/common/gopkgs/tasker/httptasker"
- "git.getensh.com/common/gopkgs/util"
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
- "net/http"
- "property-system-gateway/errors"
- param_v1 "property-system-gateway/param/v1"
- "property-system-gateway/pb"
- "property-system-gateway/pb/v1"
- "property-system-gateway/utils"
- )
- //
- // @Summary 应用订单列表
- // @Description 应用订单列表
- // @Tags 应用订单
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param page query int true "第几页,1为起始页, -1 不分页返回所有"
- // @Param page_size query int false "每页条数,-1 不分页返回所有"
- // @Param status query int false "0不过滤,1待认证 2 已通过(已购) 3 未通过"
- // @Success 200 {object} v1.GardenApplicationListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/application [get]
- func (c *Controller) GardenApplicationList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.GardenApplicationListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.GardenApplicationListQuery, nil)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- if tokenInfo.Cid == 0 {
- return errors.TokenFailedError
- }
- // 响应数据
- resp := param_v1.GardenApplicationListResponse{}
- rpcReq := &v1.GardenApplicationListRequest{
- Status: req.Status,
- PageSize: req.PageSize,
- Page: req.Page,
- GardenId: tokenInfo.GardenId,
- }
- rpcRsp, err := pb.System.GardenApplicationList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.GardenApplicationList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.GardenApplicationItem, 0)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
- //
- // @Summary 购买应用
- // @Description 购买应用
- // @Tags 应用订单
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.ApplicationOrderAddBody true "信息"
- // @Success 200 {object} v1.ApplicationOrderAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/application [post]
- func (c *Controller) ApplicationOrderAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.ApplicationOrderAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.ApplicationOrderAddBody)
- if err != nil {
- logger.Error("func",
- zap.String("call", "util.ShouldBind"),
- zap.String("error", err.Error()))
- return errors.ParamsError
- }
- return nil
- }
- // 业务处理
- handleServiceTask := func() error {
- tokenInfo, err := utils.GetSubjectValue(ctx)
- if err != nil {
- return err
- }
- if tokenInfo.Cid == 0 {
- return errors.TokenFailedError
- }
- // 响应数据
- resp := param_v1.ApplicationOrderAddResponse{}
- rpcReq := &v1.ApplicationOrderAddRequest{
- Cid: tokenInfo.Cid,
- ApplicationId: req.ApplicationId,
- GardenId: tokenInfo.GardenId,
- }
- rpcRsp, err := pb.System.ApplicationOrderAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.ApplicationOrderAdd"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- resp.Data = *rpcRsp
- ctx.JSON(http.StatusOK, resp)
- return nil
- }
- // 执行任务
- httptasker.Exec(ctx, parseParamTask, handleServiceTask)
- }
|