diff --git a/api/v1/cmb_cpn.proto b/api/v1/cmb_cpn.proto index 55ba048..2b54cce 100644 --- a/api/v1/cmb_cpn.proto +++ b/api/v1/cmb_cpn.proto @@ -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位,精度为毫秒 diff --git a/configs/config.yaml b/configs/config.yaml index d3fb0b5..b43938a 100644 --- a/configs/config.yaml +++ b/configs/config.yaml @@ -43,7 +43,7 @@ rocketMQ: RetryCnt: 3 #重试次数,不配置默认38 wechat: - mchID: "1605446142" # 证书所属商户 + mchID: "1605446142" # 证书所属商户 蓝色兄弟服务商立减金配置 mchCertificateSerialNumber: "4D081089DEB385316CBDCB55C070287E4920AC76" cmb: diff --git a/internal/biz/bo/order_bo.go b/internal/biz/bo/order_bo.go index cacc0b5..c14396b 100644 --- a/internal/biz/bo/order_bo.go +++ b/internal/biz/bo/order_bo.go @@ -28,6 +28,7 @@ type OrderCreateReqBo struct { OutBizNo string ProductNo string Account string + AppID string AccountType vo.OrderAccountType } diff --git a/internal/biz/bo/product_bo.go b/internal/biz/bo/product_bo.go index c17310f..39692a5 100644 --- a/internal/biz/bo/product_bo.go +++ b/internal/biz/bo/product_bo.go @@ -12,7 +12,6 @@ type ProductBo struct { ProductNo string BatchName string BatchNo string - AppID string MerchantNo string Channel vo.Channel CreateTime *time.Time diff --git a/internal/biz/cmb.go b/internal/biz/cmb.go index 17b2cfe..d497677 100644 --- a/internal/biz/cmb.go +++ b/internal/biz/cmb.go @@ -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 }) diff --git a/internal/biz/cmb/voucher.go b/internal/biz/cmb/voucher.go index 5cc450d..9ba42ec 100644 --- a/internal/biz/cmb/voucher.go +++ b/internal/biz/cmb/voucher.go @@ -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, diff --git a/internal/biz/wechatrepo/cpn.go b/internal/biz/wechatrepo/cpn.go index 36e7751..23b588a 100644 --- a/internal/biz/wechatrepo/cpn.go +++ b/internal/biz/wechatrepo/cpn.go @@ -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) } diff --git a/internal/data/model/product.gen.go b/internal/data/model/product.gen.go index a10afb1..ae94104 100644 --- a/internal/data/model/product.gen.go +++ b/internal/data/model/product.gen.go @@ -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"` diff --git a/internal/data/wechat_test.go b/internal/data/wechat_test.go index 1549a08..28b59bc 100644 --- a/internal/data/wechat_test.go +++ b/internal/data/wechat_test.go @@ -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 { diff --git a/internal/data/wechatrepoimpl/cpn.go b/internal/data/wechatrepoimpl/cpn.go index 5410c6f..d9a7f05 100644 --- a/internal/data/wechatrepoimpl/cpn.go +++ b/internal/data/wechatrepoimpl/cpn.go @@ -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 } diff --git a/internal/service/cmb.go b/internal/service/cmb.go index 77263f8..472fb01 100644 --- a/internal/service/cmb.go +++ b/internal/service/cmb.go @@ -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, }