diff --git a/go.sum b/go.sum index 80fa89b..81ebe16 100644 --- a/go.sum +++ b/go.sum @@ -133,7 +133,6 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= -github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= diff --git a/internal/data/mixrepoimpl/cmb.go b/internal/data/mixrepoimpl/cmb.go index f8086d0..570e024 100644 --- a/internal/data/mixrepoimpl/cmb.go +++ b/internal/data/mixrepoimpl/cmb.go @@ -268,7 +268,7 @@ func (s *CmbMixRepoImpl) Request(ctx context.Context, req *v1.CmbRequest, uri st r := uri + "?" + uv.Encode() - _, bodyBytes, err := request.Post(ctx, r, nil, request.WithHeaders(h)) + _, bodyBytes, err := request.Post(ctx, r, nil, request.WithHeaders(h), request.WithTimeout(time.Second*20)) if err != nil { log.Errorf("请求掌上生活报错,url:%s,err:%v", r, err) return nil, err diff --git a/internal/server/http.go b/internal/server/http.go index 6aed79e..3e0023e 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -39,8 +39,6 @@ func NewHTTPServer( srv.Route("/voucher/").GET("notifyRetry/{id}", cmb.NotifyRetry) srv.Route("/voucher/").GET("queryOrder/{order_no}", cmb.QueryOrder) - srv.HandleFunc("/voucher/queryByOrderNo/{order_no}", cmb.QueryByOrderNo) - v1.RegisterCmbHTTPServer(srv, cmb) return srv diff --git a/internal/service/cmb.go b/internal/service/cmb.go index e037566..2a3043f 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -2,9 +2,12 @@ package service import ( "context" + "fmt" "github.com/go-kratos/kratos/v2/log" + "github.com/go-kratos/kratos/v2/transport/http" "github.com/robfig/cron" - "html/template" + http2 "net/http" + "strconv" v1 "voucher/api/v1" "voucher/internal/biz" "voucher/internal/biz/bo" @@ -22,7 +25,6 @@ type CmbService struct { VoucherBiz *biz.VoucherBiz CmbMixRepo mixrepos.CmbMixRepo WechatCpnRepo wechatrepo.WechatCpnRepo - tmpl *template.Template } func NewCmbService( @@ -31,7 +33,6 @@ func NewCmbService( VoucherBiz *biz.VoucherBiz, CmbMixRepo mixrepos.CmbMixRepo, WechatCpnRepo wechatrepo.WechatCpnRepo, - tmpl *template.Template, ) *CmbService { return &CmbService{ bc: bc, @@ -39,7 +40,6 @@ func NewCmbService( VoucherBiz: VoucherBiz, CmbMixRepo: CmbMixRepo, WechatCpnRepo: WechatCpnRepo, - tmpl: tmpl, } } @@ -59,3 +59,34 @@ func (c *CmbService) GetResponse(ctx context.Context, replyBizContent []byte) (* return reply, nil } + +func (this *CmbService) NotifyRetry(ctx http.Context) error { + id := ctx.Vars().Get("id") + if id == "" { + return fmt.Errorf("id is empty") + } + + orderNotifyId, err := strconv.ParseUint(id, 10, 64) + if err != nil { + return err + } + + return this.VoucherBiz.PushNotifyRetryDelayMQ(ctx, 1, orderNotifyId) +} + +func (this *CmbService) QueryOrder(ctx http.Context) error { + + orderNo := ctx.Vars().Get("order_no") + if orderNo == "" { + return fmt.Errorf("orderNo is empty") + } + + str, err := this.VoucherBiz.QueryOrder(ctx, orderNo) + if err != nil { + return err + } + + return ctx.JSON(http2.StatusOK, map[string]interface{}{ + "data": str, + }) +}