From 803a8706b128ff7b0064bf45b30b19c5fb181d3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Fri, 7 Mar 2025 18:12:56 +0800 Subject: [PATCH] cmb --- internal/biz/cmb.go | 21 ++++++------ internal/server/http.go | 2 -- internal/service/cmb.go | 74 ++++++++++++++++++++++------------------- 3 files changed, 50 insertions(+), 47 deletions(-) diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index b84e362..12010ba 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -65,19 +65,18 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep } reps = &v1.CmbQueryProductReply{ - ActivityName: product.Name, - ActivityId: product.ProductNo, - - StartTime: *wechatResp.AvailableBeginTime, - EndTime: *wechatResp.AvailableEndTime, - Detail: *wechatResp.Description, - - Amount: "", - MinAmount: "", - - AvailableStock: "", + RespCode: vo.CmbResponseStatusSuccess.GetValue(), + RespMsg: "成功", + ActivityName: product.Name, + ActivityId: product.ProductNo, + Amount: "", + MinAmount: "", AvailableType: "", AvailableDays: "", // 动态有效期天数 + StartTime: *wechatResp.AvailableBeginTime, + EndTime: *wechatResp.AvailableEndTime, + AvailableStock: "", + Detail: *wechatResp.Description, } reps.Amount = fmt.Sprintf("%d", *wechatResp.StockUseRule.FixedNormalCoupon.CouponAmount) diff --git a/internal/server/http.go b/internal/server/http.go index f1329b4..c6495d2 100644 --- a/internal/server/http.go +++ b/internal/server/http.go @@ -34,8 +34,6 @@ func NewHTTPServer( return ctx.String(http2.StatusOK, "pong") }) - r.POST("/v1/wechat/notify", voucherService.WechatNotify) - cmb := r.Group("/cmb") cmb.POST("/v1/orderMock", voucherService.CmbOrderMock) diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 855aaf1..2ed1c17 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -2,6 +2,7 @@ package service import ( "encoding/json" + "github.com/go-kratos/kratos/v2/log" "github.com/go-kratos/kratos/v2/transport/http" v1 "voucher/api/v1" "voucher/internal/biz/bo" @@ -12,29 +13,36 @@ func (s *VoucherService) CmbOrder(ctx http.Context) error { var ( reply *v1.CmbReply - err error + + bizReply *v1.CmbOrderReply ) orderNo, err := s.cmbOrder(ctx) if err != nil { - reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ - RespCode: vo.CmbResponseStatusFail.GetValue(), - RespMsg: err.Error(), - BizContent: "", - }) + bizReply = &v1.CmbOrderReply{ + RespCode: vo.CmbResponseStatusFail.GetValue(), + RespMsg: err.Error(), + CodeNo: orderNo, + } } else { - bizReply := &v1.CmbOrderReply{ + bizReply = &v1.CmbOrderReply{ RespCode: vo.CmbResponseStatusSuccess.GetValue(), RespMsg: "成功", CodeNo: orderNo, } - replyBizContent, _ := json.Marshal(bizReply) - reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ - RespCode: vo.CmbResponseStatusSuccess.GetValue(), - RespMsg: "成功", - BizContent: string(replyBizContent), - }) + } + + replyBizContent, _ := json.Marshal(bizReply) + xx := &bo.CmbResponseBo{ + RespCode: vo.CmbResponseStatusSuccess.GetValue(), + RespMsg: err.Error(), + BizContent: string(replyBizContent), + } + + reply, err = s.CmbMixRepo.GetResponse(ctx, xx) + if err != nil { + log.Errorf("cmbOrder CmbMixRepo GetResponse error: %v", err) } return ctx.JSON(200, reply) @@ -76,25 +84,28 @@ func (s *VoucherService) CmbProductQuery(ctx http.Context) error { var ( reply *v1.CmbReply - err error + + bizReply *v1.CmbQueryProductReply ) bizReply, err := s.cmbProductQuery(ctx) if err != nil { - reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ - RespCode: vo.CmbResponseStatusFail.GetValue(), - RespMsg: err.Error(), - BizContent: "", - }, - ) - } else { - replyBizContent, _ := json.Marshal(bizReply) - reply, err = s.CmbMixRepo.GetResponse(ctx, &bo.CmbResponseBo{ - RespCode: vo.CmbResponseStatusSuccess.GetValue(), - RespMsg: "成功", - BizContent: string(replyBizContent), - }, - ) + bizReply = &v1.CmbQueryProductReply{ + RespCode: vo.CmbResponseStatusFail.GetValue(), + RespMsg: err.Error(), + } + } + + replyBizContent, _ := json.Marshal(bizReply) + xx := &bo.CmbResponseBo{ + RespCode: vo.CmbResponseStatusSuccess.GetValue(), + RespMsg: "成功", + BizContent: string(replyBizContent), + } + + reply, err = s.CmbMixRepo.GetResponse(ctx, xx) + if err != nil { + log.Errorf("cmbProductQuery CmbMixRepo GetResponse error: %v", err) } return ctx.JSON(200, reply) @@ -116,10 +127,5 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR return nil, err } - reply, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId) - if err != nil { - return nil, err - } - - return reply, nil + return s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId) }