123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 |
- // 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-company-gateway/errors"
- param_v1 "property-company-gateway/param/v1"
- "property-company-gateway/pb"
- "property-company-gateway/pb/v1"
- "property-company-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.CompanyPackageListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/package [get]
- func (c *Controller) CompanyPackageList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CompanyPackageListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.CompanyPackageListQuery, 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.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- if tokenInfo.Cid == 0 {
- return errors.TokenFailedError
- }
- // 响应数据
- resp := param_v1.CompanyPackageListResponse{}
- rpcReq := &v1.CompanyPackageListRequest{
- Status: req.Status,
- PageSize: req.PageSize,
- Page: req.Page,
- Cid: tokenInfo.Cid,
- }
- rpcRsp, err := pb.System.CompanyPackageList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.CompanyPackageList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.CompanyPackageItem, 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 page query int true "第几页,1为起始页, -1 不分页返回所有"
- // @Param page_size query int false "每页条数,-1 不分页返回所有"
- // @Success 200 {object} v1.CompanyPackageListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/package_for_garden [get]
- func (c *Controller) CompanyPackageListForGarden(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.CompanyPackageListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.CompanyPackageListQuery, 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.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- if tokenInfo.Cid == 0 {
- return errors.TokenFailedError
- }
- // 响应数据
- resp := param_v1.CompanyPackageListResponse{}
- rpcReq := &v1.CompanyPackageListRequest{
- Status: 2,
- PageSize: req.PageSize,
- Page: req.Page,
- Cid: tokenInfo.Cid,
- ForGarden: true,
- }
- rpcRsp, err := pb.System.CompanyPackageList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.CompanyPackageList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.CompanyPackageItem, 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.PackageOrderAddBody true "信息"
- // @Success 200 {object} v1.PackageOrderAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/package [post]
- func (c *Controller) PackageOrderAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PackageOrderAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PackageOrderAddBody)
- 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.GetJwtTokenInfo(ctx)
- if err != nil {
- return err
- }
- if tokenInfo.Cid == 0 {
- return errors.TokenFailedError
- }
- // 响应数据
- resp := param_v1.PackageOrderAddResponse{}
- rpcReq := &v1.PackageOrderAddRequest{
- Cid: tokenInfo.Cid,
- PackageId: req.PackageId,
- Period: req.Period,
- GardenCount: 1,
- Amount: req.Amount,
- CompanyName: tokenInfo.CompanyName,
- OrderType: 1,
- ShouldAccess: false,
- }
- rpcRsp, err := pb.System.PackageOrderAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.PackageOrderAdd"),
- 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)
- }
- //
- // @Summary 套餐续费
- // @Description 套餐续费
- // @Tags 公司套餐
- // @Accept json
- // @Produce json
- // @Param token header string true " "
- // @Param body body v1.PackageOrderAddRenewBody true "信息"
- // @Success 200 {object} v1.PackageOrderAddRenewResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/order/renew [post]
- func (c *Controller) PackageOrderAddRenew(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.PackageOrderAddRenewRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PackageOrderAddRenewBody)
- 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.GetJwtTokenFromCtx(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.PackageOrderAddRenewResponse{}
- rpcReq := &v1.PackageOrderAddRequest{
- PackageId: req.PackageId,
- Period: req.Period,
- GardenCount: 1,
- Amount: req.Amount,
- GardenId: req.GardenId,
- OrderType: 2,
- ShouldAccess: false,
- }
- rpcRsp, err := pb.System.PackageOrderAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.PackageOrderAdd"),
- 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)
- }
|