From a6c258fd29fc9b00fea7036e81f273ad607f99a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Wed, 5 Mar 2025 09:44:59 +0800 Subject: [PATCH] cmb --- internal/biz/cmb.go | 8 +++----- internal/service/cmb.go | 27 ++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index a1e534c..c3076b4 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -4,9 +4,9 @@ import ( "context" "errors" "fmt" + "github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon" "gorm.io/gorm" "time" - v1 "voucher/api/v1" "voucher/internal/biz/bo" "voucher/internal/pkg/lock" ) @@ -45,7 +45,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or return } -func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *v1.CmbQueryProductReply, err error) { +func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *merchantexclusivecoupon.StockGetResponse, err error) { err = lock.NewMutex(v.rdb.Rdb, time.Second*30).Lock(ctx, fmt.Sprintf("cmb_product_query_%s", productNo), func(ctx context.Context) error { @@ -58,13 +58,11 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep return fmt.Errorf("只支持微信") } - _, err = v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo) + reps, err = v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo) if err != nil { return err } - // 数据构造返回 - return nil }) diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 23f6506..0594634 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -92,10 +92,31 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) error { return err } - s.VoucherBiz.CmbProductQuery(ctx, req.ActivityId) - // todo 签名验证 + q, err := s.VoucherBiz.CmbProductQuery(ctx, req.ActivityId) + if err != nil { + return err + } - rep := &v1.CmbQueryProductReply{} + // 数据构造 加签 返回 + rep := &v1.CmbQueryProductReply{ + RespCode: "", + RespMsg: "", + Date: "", + KeyAlias: "", + CmbKeyAlias: "", + EncryptBody: "", + Sign: "", + ActivityName: "", + ActivityId: *q.StockId, + Amount: "", + MinAmount: "", + AvailableType: "", + AvailableDays: "", + StartTime: "", + EndTime: "", + AvailableStock: "", + Detail: "", + } return ctx.JSON(200, rep) }