This commit is contained in:
李子铭 2025-03-06 11:07:19 +08:00
parent 87acc327b8
commit 357bab2626
3 changed files with 34 additions and 16 deletions

View File

@ -4,9 +4,9 @@ import (
"context" "context"
"errors" "errors"
"fmt" "fmt"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"gorm.io/gorm" "gorm.io/gorm"
"time" "time"
v1 "voucher/api/v1"
"voucher/internal/biz/bo" "voucher/internal/biz/bo"
"voucher/internal/pkg/lock" "voucher/internal/pkg/lock"
) )
@ -45,7 +45,7 @@ func (v *VoucherBiz) CmbOrder(ctx context.Context, req *bo.OrderCreateReqBo) (or
return 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 { 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("只支持微信") return fmt.Errorf("只支持微信")
} }
reps, err = v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo) wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo)
if err != nil { if err != nil {
return err 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 return nil
}) })

View File

@ -1,5 +1,6 @@
package vo package vo
// CmbFuncName . 招行接口名称
type CmbFuncName string type CmbFuncName string
const ( const (
@ -12,6 +13,7 @@ func (s CmbFuncName) GetValue() string {
return string(s) return string(s)
} }
// CmbStatus . 券通知状态
type CmbStatus string type CmbStatus string
const ( const (
@ -23,6 +25,7 @@ func (s CmbStatus) GetValue() string {
return string(s) return string(s)
} }
// CmbResponseStatus . 响应状态
type CmbResponseStatus string type CmbResponseStatus string
const ( const (
@ -33,3 +36,15 @@ const (
func (s CmbResponseStatus) GetValue() string { func (s CmbResponseStatus) GetValue() string {
return string(s) return string(s)
} }
// CmbAvailableType . 有效期形式0固定有效期1动态有效期
type CmbAvailableType string
const (
CmbAvailableTypeFixed CmbAvailableType = "0"
CmbAvailableTypeDynamic CmbAvailableType = "1"
)
func (s CmbAvailableType) GetValue() string {
return string(s)
}

View File

@ -111,21 +111,10 @@ func (s *VoucherService) cmbProductQuery(ctx http.Context) (*v1.CmbQueryProductR
return nil, err return nil, err
} }
wechatResp, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId) reply, err := s.VoucherBiz.CmbProductQuery(ctx, bizContent.ActivityId)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &v1.CmbQueryProductReply{ return reply, nil
ActivityName: *wechatResp.GoodsName,
ActivityId: "",
Amount: "",
MinAmount: "",
AvailableType: "",
AvailableDays: "",
StartTime: "",
EndTime: "",
AvailableStock: "",
Detail: "",
}, nil
} }