This commit is contained in:
李子铭 2025-03-06 16:12:33 +08:00
parent f51c470d66
commit 84927b7d30
11 changed files with 39 additions and 41 deletions

View File

@ -51,6 +51,8 @@ message CmbOrderRequest {
string activityId = 10 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
// openId
string cmbUid = 11 [json_name = "cmbUid", (validate.rules).string = {min_len: 1,max_len: 100}];
// id
string appId = 14 [json_name = "appId", (validate.rules).string = {min_len: 1,max_len: 50}];
// 0-1-openId
string cmbUidType = 12 [json_name = "cmbUidType", (validate.rules).string = {min_len: 1,max_len: 10}];
// 13

View File

@ -43,7 +43,7 @@ rocketMQ:
RetryCnt: 3 #重试次数,不配置默认38
wechat:
mchID: "1605446142" # 证书所属商户
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
mchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76"
cmb:

View File

@ -28,6 +28,7 @@ type OrderCreateReqBo struct {
OutBizNo string
ProductNo string
Account string
AppID string
AccountType vo.OrderAccountType
}

View File

@ -12,7 +12,6 @@ type ProductBo struct {
ProductNo string
BatchName string
BatchNo string
AppID string
MerchantNo string
Channel vo.Channel
CreateTime *time.Time

View File

@ -4,7 +4,6 @@ import (
"context"
"errors"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"gorm.io/gorm"
"time"
v1 "voucher/api/v1"
@ -60,7 +59,7 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
return fmt.Errorf("只支持微信")
}
wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo)
wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo, product.MerchantNo)
if err != nil {
return err
}
@ -69,35 +68,26 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
ActivityName: product.Name,
ActivityId: product.ProductNo,
StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime),
Detail: *wechatResp.DisplayPatternInfo.Description,
StartTime: *wechatResp.AvailableBeginTime,
EndTime: *wechatResp.AvailableEndTime,
Detail: *wechatResp.Description,
Amount: "",
MinAmount: "",
AvailableType: "",
AvailableDays: "",
AvailableStock: "",
AvailableType: "",
AvailableDays: "", // 动态有效期天数
}
availableStock := *wechatResp.StockSendRule.MaxCoupons - *wechatResp.SendCountInformation.TotalSendNum
reps.Amount = fmt.Sprintf("%d", *wechatResp.StockUseRule.FixedNormalCoupon.CouponAmount)
reps.MinAmount = fmt.Sprintf("%d", *wechatResp.StockUseRule.FixedNormalCoupon.TransactionMinimum)
availableStock := *wechatResp.StockUseRule.MaxCoupons - *wechatResp.DistributedCoupons
reps.AvailableStock = fmt.Sprintf("%d", availableStock)
if wechatResp.CouponUseRule.CouponAvailableTime.AvailableDayAfterReceive != nil {
reps.AvailableType = vo.CmbAvailableTypeDynamic.GetValue()
reps.AvailableDays = fmt.Sprintf("%d", *wechatResp.CouponUseRule.CouponAvailableTime.AvailableDayAfterReceive)
} else {
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
}
if *wechatResp.StockType == merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_NORMAL {
reps.Amount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.DiscountAmount)
reps.MinAmount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.TransactionMinimum)
} else if *wechatResp.StockType == merchantexclusivecoupon.BUSIFAVORSTOCKTYPE_DISCOUNT {
reps.Amount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.DiscountCoupon.DiscountPercent)
reps.MinAmount = fmt.Sprintf("%d", *wechatResp.CouponUseRule.FixedNormalCoupon.TransactionMinimum)
}
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
reps.AvailableDays = fmt.Sprintf("%d", *wechatResp.StockUseRule.FixedNormalCoupon.CouponAmount)
return nil
})

View File

@ -19,7 +19,7 @@ func (v *Cmb) Order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.P
OutBizNo: req.OutBizNo,
ProductNo: req.ProductNo,
Account: req.Account,
AppID: product.AppID,
AppID: req.AppID,
MerchantNo: product.MerchantNo,
Channel: product.Channel,
BatchNo: product.BatchNo,

View File

@ -2,7 +2,7 @@ package wechatrepo
import (
"context"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"voucher/internal/biz/bo"
"voucher/internal/biz/vo"
)
@ -10,5 +10,5 @@ import (
type WechatCpnRepo interface {
Order(ctx context.Context, orderWechat *bo.OrderWechatBo) (couponId string, err error)
Query(ctx context.Context, orderWechat *bo.OrderWechatBo) (vo.OrderWechatStatus, error)
QueryProduct(ctx context.Context, stockId string) (*merchantexclusivecoupon.StockGetResponse, error)
QueryProduct(ctx context.Context, stockCreatorMchId, stockId string) (*cashcoupons.Stock, error)
}

View File

@ -17,7 +17,6 @@ type Product struct {
ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号
BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称
BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号
AppID string `gorm:"column:app_id;not null;comment:批次所属应用" json:"app_id"` // 批次所属应用
MerchantNo string `gorm:"column:merchant_no;not null;comment:商户号,创建批次的商户号" json:"merchant_no"` // 商户号,创建批次的商户号
Channel uint8 `gorm:"column:channel;not null;comment:1:微信 2:支付宝" json:"channel"` // 1:微信 2:支付宝
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`

View File

@ -4,16 +4,17 @@ import (
"context"
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"testing"
)
func TestGetClient(t *testing.T) {
server := &Server{
MchID: "",
MchCertificateSerialNumber: "",
MchID: "1605446142", // 证书所属商户 蓝色兄弟服务商立减金配置
MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76",
}
stockId := ""
stockCreatorMchid := ""
ctx := context.Background()
@ -23,10 +24,11 @@ func TestGetClient(t *testing.T) {
return
}
svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
svc := cashcoupons.StockApiService{Client: client}
response, result, err := svc.QueryStock(ctx, merchantexclusivecoupon.QueryStockRequest{
StockId: core.String(stockId),
response, result, err := svc.QueryStock(ctx, cashcoupons.QueryStockRequest{
StockId: core.String(stockId),
StockCreatorMchid: core.String(stockCreatorMchid),
})
if err != nil {

View File

@ -5,7 +5,6 @@ import (
"fmt"
"github.com/wechatpay-apiv3/wechatpay-go/core"
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
"voucher/internal/biz/bo"
"voucher/internal/biz/vo"
"voucher/internal/biz/wechatrepo"
@ -33,9 +32,10 @@ func NewCpnRepoImpl(bc *conf.Bootstrap) (wechatrepo.WechatCpnRepo, error) {
func (c *CpnRepoImpl) Order(ctx context.Context, orderWechat *bo.OrderWechatBo) (couponId string, err error) {
req := cashcoupons.SendCouponRequest{
Openid: core.String(orderWechat.OpenID),
StockId: core.String(orderWechat.StockID),
OutRequestNo: core.String(orderWechat.OutRequestNo),
Openid: core.String(orderWechat.OpenID),
StockId: core.String(orderWechat.StockID),
OutRequestNo: core.String(orderWechat.OutRequestNo),
// 微信为发券方商户分配的公众账号ID接口传入的所有appid应该为公众号的appid在mp.weixin.qq.com申请的不能为APP的appid在open.weixin.qq.com申请的
Appid: core.String(orderWechat.AppID),
StockCreatorMchid: core.String(orderWechat.StockCreatorMchid),
}
@ -90,16 +90,20 @@ func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderWechatBo)
return CpnStatus(*resp.Status).GetStatus()
}
func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockId string) (*merchantexclusivecoupon.StockGetResponse, error) {
func (c *CpnRepoImpl) QueryProduct(ctx context.Context, stockCreatorMchId, stockId string) (*cashcoupons.Stock, error) {
client, err := data.GetClient(ctx, c.Server)
if err != nil {
return nil, err
}
svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
svc := cashcoupons.StockApiService{Client: client}
response, result, err := svc.QueryStock(ctx, cashcoupons.QueryStockRequest{
StockId: core.String(stockId),
StockCreatorMchid: core.String(stockCreatorMchId),
})
response, result, err := svc.QueryStock(ctx, merchantexclusivecoupon.QueryStockRequest{StockId: core.String(stockId)})
if err != nil {
return nil, err
}

View File

@ -56,6 +56,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
OutBizNo: bizContent.TransactionId,
ProductNo: bizContent.ActivityId,
Account: bizContent.CmbUid,
AppID: bizContent.AppId,
AccountType: vo.OrderAccountTypeOpenId,
}