voucher/internal/data/wechatrepoimpl/bank_multi_activity.go

45 lines
1019 B
Go

package wechatrepoimpl
import (
"github.com/wechatpay-apiv3/wechatpay-go/core"
"voucher/internal/biz/bo"
"voucher/internal/biz/wechatrepo"
"voucher/internal/conf"
"voucher/internal/data"
"voucher/internal/pkg/wechat/srv/marketing"
)
type BankMultiActivityImpl struct {
bc *conf.Bootstrap
wx *data.Wx
}
func NewBankMultiActivityImpl(bc *conf.Bootstrap, wx *data.Wx) wechatrepo.BankMultiActivityRepo {
return &BankMultiActivityImpl{bc: bc, wx: wx}
}
func (w *BankMultiActivityImpl) Order(order *bo.OrderBo) (couponId string, err error) {
req := &marketing.SendReq{
ActivityId: core.String(order.ActivityId),
StockId: core.String(order.BatchNo),
OutRequestNo: core.String(order.OrderNo),
Appid: core.String(order.AppID),
StockCreatorMchId: core.String(order.MerchantNo),
}
t, err := w.wx.Get(w.bc.Wechat.MchID)
if err != nil {
return "", err
}
resp, err := t.Send(order.Account, req)
if err != nil {
return "", err
}
return *resp.CouponId, nil
}