cmb
This commit is contained in:
parent
f51c470d66
commit
84927b7d30
|
|
@ -51,6 +51,8 @@ message CmbOrderRequest {
|
||||||
string activityId = 10 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
string activityId = 10 [json_name = "activityId", (validate.rules).string = {min_len: 1,max_len: 32}];
|
||||||
// 招商银行用户号 用户标识,比如手机号、支付宝openId
|
// 招商银行用户号 用户标识,比如手机号、支付宝openId
|
||||||
string cmbUid = 11 [json_name = "cmbUid", (validate.rules).string = {min_len: 1,max_len: 100}];
|
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
|
// 用户标识类型,0-手机号,1-支付宝openId
|
||||||
string cmbUidType = 12 [json_name = "cmbUidType", (validate.rules).string = {min_len: 1,max_len: 10}];
|
string cmbUidType = 12 [json_name = "cmbUidType", (validate.rules).string = {min_len: 1,max_len: 10}];
|
||||||
// 时间戳,长度为13位,精度为毫秒
|
// 时间戳,长度为13位,精度为毫秒
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ rocketMQ:
|
||||||
RetryCnt: 3 #重试次数,不配置默认38
|
RetryCnt: 3 #重试次数,不配置默认38
|
||||||
|
|
||||||
wechat:
|
wechat:
|
||||||
mchID: "1605446142" # 证书所属商户
|
mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置
|
||||||
mchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76"
|
mchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76"
|
||||||
|
|
||||||
cmb:
|
cmb:
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,7 @@ type OrderCreateReqBo struct {
|
||||||
OutBizNo string
|
OutBizNo string
|
||||||
ProductNo string
|
ProductNo string
|
||||||
Account string
|
Account string
|
||||||
|
AppID string
|
||||||
AccountType vo.OrderAccountType
|
AccountType vo.OrderAccountType
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,6 @@ type ProductBo struct {
|
||||||
ProductNo string
|
ProductNo string
|
||||||
BatchName string
|
BatchName string
|
||||||
BatchNo string
|
BatchNo string
|
||||||
AppID string
|
|
||||||
MerchantNo string
|
MerchantNo string
|
||||||
Channel vo.Channel
|
Channel vo.Channel
|
||||||
CreateTime *time.Time
|
CreateTime *time.Time
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ 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"
|
v1 "voucher/api/v1"
|
||||||
|
|
@ -60,7 +59,7 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
||||||
return fmt.Errorf("只支持微信")
|
return fmt.Errorf("只支持微信")
|
||||||
}
|
}
|
||||||
|
|
||||||
wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo)
|
wechatResp, err := v.WechatCpnRepo.QueryProduct(ctx, product.BatchNo, product.MerchantNo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -69,35 +68,26 @@ func (v *VoucherBiz) CmbProductQuery(ctx context.Context, productNo string) (rep
|
||||||
ActivityName: product.Name,
|
ActivityName: product.Name,
|
||||||
ActivityId: product.ProductNo,
|
ActivityId: product.ProductNo,
|
||||||
|
|
||||||
StartTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableBeginTime.Format(time.DateTime),
|
StartTime: *wechatResp.AvailableBeginTime,
|
||||||
EndTime: wechatResp.CouponUseRule.CouponAvailableTime.AvailableEndTime.Format(time.DateTime),
|
EndTime: *wechatResp.AvailableEndTime,
|
||||||
Detail: *wechatResp.DisplayPatternInfo.Description,
|
Detail: *wechatResp.Description,
|
||||||
|
|
||||||
Amount: "",
|
Amount: "",
|
||||||
MinAmount: "",
|
MinAmount: "",
|
||||||
|
|
||||||
AvailableType: "",
|
|
||||||
AvailableDays: "",
|
|
||||||
AvailableStock: "",
|
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)
|
reps.AvailableStock = fmt.Sprintf("%d", availableStock)
|
||||||
|
|
||||||
if wechatResp.CouponUseRule.CouponAvailableTime.AvailableDayAfterReceive != nil {
|
reps.AvailableType = vo.CmbAvailableTypeFixed.GetValue()
|
||||||
reps.AvailableType = vo.CmbAvailableTypeDynamic.GetValue()
|
reps.AvailableDays = fmt.Sprintf("%d", *wechatResp.StockUseRule.FixedNormalCoupon.CouponAmount)
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ func (v *Cmb) Order(ctx context.Context, req *bo.OrderCreateReqBo, product *bo.P
|
||||||
OutBizNo: req.OutBizNo,
|
OutBizNo: req.OutBizNo,
|
||||||
ProductNo: req.ProductNo,
|
ProductNo: req.ProductNo,
|
||||||
Account: req.Account,
|
Account: req.Account,
|
||||||
AppID: product.AppID,
|
AppID: req.AppID,
|
||||||
MerchantNo: product.MerchantNo,
|
MerchantNo: product.MerchantNo,
|
||||||
Channel: product.Channel,
|
Channel: product.Channel,
|
||||||
BatchNo: product.BatchNo,
|
BatchNo: product.BatchNo,
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ package wechatrepo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
)
|
)
|
||||||
|
|
@ -10,5 +10,5 @@ import (
|
||||||
type WechatCpnRepo interface {
|
type WechatCpnRepo interface {
|
||||||
Order(ctx context.Context, orderWechat *bo.OrderWechatBo) (couponId string, err error)
|
Order(ctx context.Context, orderWechat *bo.OrderWechatBo) (couponId string, err error)
|
||||||
Query(ctx context.Context, orderWechat *bo.OrderWechatBo) (vo.OrderWechatStatus, 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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ type Product struct {
|
||||||
ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号
|
ProductNo string `gorm:"column:product_no;not null;comment:商品编号" json:"product_no"` // 商品编号
|
||||||
BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称
|
BatchName string `gorm:"column:batch_name;not null;comment:批次名称" json:"batch_name"` // 批次名称
|
||||||
BatchNo string `gorm:"column:batch_no;not null;comment:立减金批次号" json:"batch_no"` // 立减金批次号
|
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"` // 商户号,创建批次的商户号
|
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:支付宝
|
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"`
|
CreateTime *time.Time `gorm:"column:create_time;not null" json:"create_time"`
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,17 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetClient(t *testing.T) {
|
func TestGetClient(t *testing.T) {
|
||||||
server := &Server{
|
server := &Server{
|
||||||
MchID: "",
|
MchID: "1605446142", // 证书所属商户 蓝色兄弟服务商立减金配置
|
||||||
MchCertificateSerialNumber: "",
|
MchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76",
|
||||||
}
|
}
|
||||||
stockId := ""
|
stockId := ""
|
||||||
|
stockCreatorMchid := ""
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
|
|
@ -23,10 +24,11 @@ func TestGetClient(t *testing.T) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
svc := merchantexclusivecoupon.BusiFavorApiService{Client: client}
|
svc := cashcoupons.StockApiService{Client: client}
|
||||||
|
|
||||||
response, result, err := svc.QueryStock(ctx, merchantexclusivecoupon.QueryStockRequest{
|
response, result, err := svc.QueryStock(ctx, cashcoupons.QueryStockRequest{
|
||||||
StockId: core.String(stockId),
|
StockId: core.String(stockId),
|
||||||
|
StockCreatorMchid: core.String(stockCreatorMchid),
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
"github.com/wechatpay-apiv3/wechatpay-go/core"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
"github.com/wechatpay-apiv3/wechatpay-go/services/cashcoupons"
|
||||||
"github.com/wechatpay-apiv3/wechatpay-go/services/merchantexclusivecoupon"
|
|
||||||
"voucher/internal/biz/bo"
|
"voucher/internal/biz/bo"
|
||||||
"voucher/internal/biz/vo"
|
"voucher/internal/biz/vo"
|
||||||
"voucher/internal/biz/wechatrepo"
|
"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) {
|
func (c *CpnRepoImpl) Order(ctx context.Context, orderWechat *bo.OrderWechatBo) (couponId string, err error) {
|
||||||
|
|
||||||
req := cashcoupons.SendCouponRequest{
|
req := cashcoupons.SendCouponRequest{
|
||||||
Openid: core.String(orderWechat.OpenID),
|
Openid: core.String(orderWechat.OpenID),
|
||||||
StockId: core.String(orderWechat.StockID),
|
StockId: core.String(orderWechat.StockID),
|
||||||
OutRequestNo: core.String(orderWechat.OutRequestNo),
|
OutRequestNo: core.String(orderWechat.OutRequestNo),
|
||||||
|
// 微信为发券方商户分配的公众账号ID,接口传入的所有appid应该为公众号的appid(在mp.weixin.qq.com申请的),不能为APP的appid(在open.weixin.qq.com申请的)。
|
||||||
Appid: core.String(orderWechat.AppID),
|
Appid: core.String(orderWechat.AppID),
|
||||||
StockCreatorMchid: core.String(orderWechat.StockCreatorMchid),
|
StockCreatorMchid: core.String(orderWechat.StockCreatorMchid),
|
||||||
}
|
}
|
||||||
|
|
@ -90,16 +90,20 @@ func (c *CpnRepoImpl) Query(ctx context.Context, orderWechat *bo.OrderWechatBo)
|
||||||
return CpnStatus(*resp.Status).GetStatus()
|
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)
|
client, err := data.GetClient(ctx, c.Server)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ func (s *VoucherService) cmbOrder(ctx http.Context) (*v1.CmbOrderReply, error) {
|
||||||
OutBizNo: bizContent.TransactionId,
|
OutBizNo: bizContent.TransactionId,
|
||||||
ProductNo: bizContent.ActivityId,
|
ProductNo: bizContent.ActivityId,
|
||||||
Account: bizContent.CmbUid,
|
Account: bizContent.CmbUid,
|
||||||
|
AppID: bizContent.AppId,
|
||||||
AccountType: vo.OrderAccountTypeOpenId,
|
AccountType: vo.OrderAccountTypeOpenId,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue