From 357bab2626cddc9968703d509f01ce21056fbfa7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=AD=90=E9=93=AD?= Date: Thu, 6 Mar 2025 11:07:19 +0800 Subject: [PATCH] cmb --- internal/biz/cmb.go | 20 +++++++++++++++++--- internal/biz/vo/cmb.go | 15 +++++++++++++++ internal/service/cmb.go | 15 ++------------- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index c3076b4..7901194 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 *merchantexclusivecoupon.StockGetResponse, err error) { +func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (reps *v1.CmbQueryProductReply, 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,11 +58,25 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep return fmt.Errorf("只支持微信") } - reps, err = v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo) + wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo) if err != nil { return err } + // todo + reps = &v1.CmbQueryProductReply{ + ActivityName: product.Name, + ActivityId: product.ProductNo, + Amount: *wechatResp.GoodsName, + MinAmount: fmt.Sprintf("%d", *wechatResp.StockSendRule.MaxAmount), + AvailableType: *wechatResp.GoodsName, + AvailableDays: *wechatResp.GoodsName, + StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime), + EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime), + //AvailableStock: *wechatResp.SendCountInformation.TotalSendNum, + Detail: *wechatResp.GoodsName, + } + return nil }) diff --git a/internal/biz/vo/cmb.go b/internal/biz/vo/cmb.go index 6247317..0d50198 100644 --- a/internal/biz/vo/cmb.go +++ b/internal/biz/vo/cmb.go @@ -1,5 +1,6 @@ package vo +// CmbFuncName . 招行接口名称 type CmbFuncName string const ( @@ -12,6 +13,7 @@ func (s CmbFuncName) GetValue() string { return string(s) } +// CmbStatus . 券通知状态 type CmbStatus string const ( @@ -23,6 +25,7 @@ func (s CmbStatus) GetValue() string { return string(s) } +// CmbResponseStatus . 响应状态 type CmbResponseStatus string const ( @@ -33,3 +36,15 @@ const ( func (s CmbResponseStatus) GetValue() string { return string(s) } + +// CmbAvailableType . 有效期形式,0:固定有效期,1:动态有效期 +type CmbAvailableType string + +const ( + CmbAvailableTypeFixed CmbAvailableType = "0" + CmbAvailableTypeDynamic CmbAvailableType = "1" +) + +func (s CmbAvailableType) GetValue() string { + return string(s) +} diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 7d18716..d0fa1a5 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -111,21 +111,10 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR return nil, err } - wechatResp, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId) + reply, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId) if err != nil { return nil, err } - return &v1.CmbQueryProductReply{ - ActivityName: *wechatResp.GoodsName, - ActivityId: "", - Amount: "", - MinAmount: "", - AvailableType: "", - AvailableDays: "", - StartTime: "", - EndTime: "", - AvailableStock: "", - Detail: "", - }, nil + return reply, nil }