2024-06-18 18:14:57 +08:00
|
|
|
package transfer
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2024-06-19 18:05:50 +08:00
|
|
|
"encoding/json"
|
2024-06-18 18:14:57 +08:00
|
|
|
"rs/rpc/transfer"
|
2024-06-19 18:05:50 +08:00
|
|
|
"rs/untils/rsa"
|
2024-06-18 18:14:57 +08:00
|
|
|
|
|
|
|
"github.com/jinzhu/copier"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
|
|
"rs/cmd/api/internal/svc"
|
|
|
|
"rs/cmd/api/internal/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
type MarketLogic struct {
|
|
|
|
logx.Logger
|
|
|
|
ctx context.Context
|
|
|
|
svcCtx *svc.ServiceContext
|
|
|
|
}
|
|
|
|
|
|
|
|
// 荣数立减金发放
|
|
|
|
func NewMarketLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MarketLogic {
|
|
|
|
return &MarketLogic{
|
|
|
|
Logger: logx.WithContext(ctx),
|
|
|
|
ctx: ctx,
|
|
|
|
svcCtx: svcCtx,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (l *MarketLogic) Market(req *types.Req) (resp *types.Resp, err error) {
|
|
|
|
var (
|
|
|
|
reqData transfer.RsCouponGrantReq
|
|
|
|
res types.Resp
|
|
|
|
)
|
2024-06-19 18:05:50 +08:00
|
|
|
|
|
|
|
DecryptData, _ := l.Decrypt(req.VendorNo, req.Data)
|
2024-06-18 18:14:57 +08:00
|
|
|
_ = copier.Copy(&reqData, &req)
|
2024-06-19 18:05:50 +08:00
|
|
|
tagLen := len(DecryptData.VoucherTag)
|
2024-06-20 16:59:44 +08:00
|
|
|
if tagLen < 6 {
|
2024-06-19 18:05:50 +08:00
|
|
|
//如果没有解析出来,直接投递给荣数,让荣数自行处理转发
|
2024-06-18 18:14:57 +08:00
|
|
|
result, _err := l.svcCtx.TransferRpc.RsCouponGrant(l.ctx, &reqData)
|
|
|
|
if _err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
_ = copier.Copy(&res, &result)
|
|
|
|
} else {
|
2024-06-19 18:05:50 +08:00
|
|
|
prefix := DecryptData.VoucherTag[0:6]
|
|
|
|
prefixData, err := l.svcCtx.ProductRedirectConf.FindOneByProductNoPrefix(l.ctx, prefix)
|
|
|
|
if err != nil {
|
2024-06-18 18:14:57 +08:00
|
|
|
return nil, err
|
|
|
|
}
|
2024-06-19 18:05:50 +08:00
|
|
|
if prefixData == nil {
|
|
|
|
result, _err := l.svcCtx.TransferRpc.RsCouponGrant(l.ctx, &reqData)
|
|
|
|
if _err != nil {
|
|
|
|
return nil, _err
|
|
|
|
}
|
|
|
|
_ = copier.Copy(&res, &result)
|
|
|
|
} else {
|
|
|
|
result, _err := l.svcCtx.TransferRpc.ZltxRsMiXue(l.ctx, &reqData)
|
|
|
|
if _err != nil {
|
|
|
|
return nil, _err
|
|
|
|
}
|
|
|
|
_ = copier.Copy(&res, &result)
|
|
|
|
}
|
2024-06-18 18:14:57 +08:00
|
|
|
}
|
|
|
|
return &res, nil
|
|
|
|
}
|
2024-06-19 18:05:50 +08:00
|
|
|
|
|
|
|
func (l *MarketLogic) Decrypt(vendorNo string, encryptData string) (types.DecryptReqData, error) {
|
|
|
|
var (
|
|
|
|
decryptData types.DecryptReqData
|
|
|
|
deCrypt []byte
|
|
|
|
)
|
|
|
|
merchantInfo, err := l.svcCtx.Merchant.FindOneByMerchantId(l.ctx, vendorNo)
|
|
|
|
if err != nil {
|
|
|
|
return decryptData, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// 修改请求体
|
|
|
|
switch merchantInfo.SignatureMethod {
|
|
|
|
default:
|
|
|
|
privateKeyPEM := `-----BEGIN RSA PRIVATE KEY-----
|
|
|
|
` + merchantInfo.RsaPrivateKey.String + `
|
|
|
|
-----END RSA PRIVATE KEY-----`
|
|
|
|
deCrypt, err = rsa.Decrypt(privateKeyPEM, encryptData)
|
|
|
|
if err != nil {
|
|
|
|
return decryptData, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ = json.Unmarshal(deCrypt, &decryptData)
|
|
|
|
return decryptData, nil
|
|
|
|
}
|