123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217 |
- // 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 不分页返回所有"
- // @Success 200 {object} v1.MsgPackageListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/msg_package [get]
- func (c *Controller) MsgPackageList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.MsgPackageListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.MsgPackageListQuery, 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.GetJwtTokenFromCtx(ctx)
- //if err != nil {
- // return err
- //}
- // 响应数据
- resp := param_v1.MsgPackageListResponse{}
- rpcReq := &v1.MsgPackageListRequest{
- //PackageId: req.PackageId,
- PageSize: req.PageSize,
- Page: req.Page,
- }
- rpcRsp, err := pb.Common.MsgPackageList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.Common.MsgPackageList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.MsgPackageItem, 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 不分页返回所有"
- // @Param status query int false "0不过滤,1待认证 2 已通过(已购) 3 未通过"
- // @Success 200 {object} v1.MsgPackageOrderListResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/msg_package/order [get]
- func (c *Controller) MsgPackageOrderList(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.MsgPackageOrderListRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, &req.MsgPackageOrderListQuery, 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.MsgPackageOrderListResponse{}
- rpcReq := &v1.MsgPackageOrderListRequest{
- Status: int64(req.Status),
- PageSize: req.PageSize,
- Page: req.Page,
- GardenId: tokenInfo.GardenId,
- }
- rpcRsp, err := pb.System.MsgPackageOrderList(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.MsgPackageOrderList"),
- zap.String("params", s),
- zap.String("error", err.Error()))
- return errors.ErrorTransForm(err)
- }
- if rpcRsp.List == nil {
- rpcRsp.List = make([]*v1.MsgPackageOrderItem, 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.MsgPackageOrderAddBody true "信息"
- // @Success 200 {object} v1.MsgPackageOrderAddResponse
- // @Failure 500 {object} base.HTTPError
- // @Router /api/v1/msg_package/order [post]
- func (c *Controller) MsgPackageOrderAdd(ctx *gin.Context) {
- // 解析参数
- req := ¶m_v1.MsgPackageOrderAddRequest{}
- parseParamTask := func() error {
- err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.MsgPackageOrderAddBody)
- 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.MsgPackageOrderAddResponse{}
- rpcReq := &v1.MsgPackageOrderAddRequest{
- Cid: tokenInfo.Cid,
- PackageCount: req.PackageCount,
- PackageId: req.PackageId,
- GardenId: tokenInfo.GardenId,
- Amount: req.Amount,
- }
- rpcRsp, err := pb.System.MsgPackageOrderAdd(ctx, rpcReq)
- if err != nil {
- s, _ := json.MarshalToString(req)
- logger.Error("func",
- zap.String("call", "pb.System.MsgPackageOrderAdd"),
- 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)
- }
|