transfer_yl/cmd/api/internal/logic/yl/ylLogic.go

82 lines
2.2 KiB
Go

package yl
import (
"context"
"fmt"
"github.com/bytedance/sonic"
"rs/cmd/api/internal/logic/vo"
"rs/rpc/transfer"
"time"
"rs/cmd/api/internal/svc"
"rs/cmd/api/internal/types"
"github.com/zeromicro/go-zero/core/logx"
)
type YlLogic struct {
logx.Logger
ctx context.Context
svcCtx *svc.ServiceContext
}
// 卡密同步发放接口
func NewYlLogic(ctx context.Context, svcCtx *svc.ServiceContext) *YlLogic {
return &YlLogic{
Logger: logx.WithContext(ctx),
ctx: ctx,
svcCtx: svcCtx,
}
}
func (l *YlLogic) Yl(req *types.Req) (resp *types.Resp, err error) {
var (
reqData transfer.MarketKeySendReq
extendParam types.KeySendExtendParam
)
err = sonic.Unmarshal([]byte(req.ExtendParams), &extendParam)
if err != nil {
return nil, fmt.Errorf("extendParam 格式错误")
}
reqData = transfer.MarketKeySendReq{
AppId: extendParam.AppId,
ReqCode: "voucher.create",
MemId: fmt.Sprintf("%d", req.SupplierId),
ReqSerialNo: req.DeliverOrderNo,
Timestamp: time.Unix(req.CreateTime, 0).Format("20060102150405"),
PosId: extendParam.PosId,
VoucherId: req.ThirdSkuId,
VoucherNum: extendParam.Num,
MobileNo: extendParam.MobileNo,
SendMsg: extendParam.SendMsg,
}
if reqData.SendMsg == "" {
reqData.SendMsg = "2"
}
reqData.Sign = l.svcCtx.Config.Sys.PrimaryKey
result, err := l.svcCtx.TransferRpc.MarketKeySend(l.ctx, &reqData)
if err != nil {
return nil, fmt.Errorf("请求失败:%v", err)
}
if result.ErrCode != vo.RES_SUCCESS {
return nil, fmt.Errorf("请求失败:%v", result.Msg)
}
startTime, err := time.Parse("20060102", result.Data.VoucherSdate)
if err != nil {
startTime = time.Now()
}
endTime, err := time.Parse("20060102", result.Data.VoucherEdate)
if err != nil {
endTime = startTime.AddDate(0, 0, 30).Add(23*time.Hour + 59*time.Minute + 59*time.Second)
}
return &types.Resp{
CdKey: result.Data.VoucherCode,
CdNum: "",
ExchangeUrl: fmt.Sprintf("%s%s", l.svcCtx.Config.Sys.Url, result.Data.VoucherCode),
SupplierOrderNo: req.DeliverOrderNo,
StartTime: startTime.Format(time.DateTime),
EndTime: endTime.Add(23*time.Hour + 59*time.Minute + 59*time.Second).Format(time.DateTime),
}, nil
}