feat: 发货通知接口

This commit is contained in:
wolter 2024-11-05 18:14:44 +08:00
parent 7aace0acfa
commit 86b9079ffc
1 changed files with 53 additions and 11 deletions

View File

@ -2,8 +2,11 @@ package yl
import ( import (
"context" "context"
"encoding/json"
"fmt" "fmt"
"github.com/bytedance/sonic" "github.com/bytedance/sonic"
"rs/untils/sign"
"rs/cmd/api/internal/logic/vo" "rs/cmd/api/internal/logic/vo"
"rs/rpc/transfer" "rs/rpc/transfer"
"rs/untils/httpclient" "rs/untils/httpclient"
@ -71,7 +74,6 @@ func (l *YlAsyncLogic) YlAsync(req *types.AsyncReq) (resp *types.AsyncResp, err
return nil, fmt.Errorf("rpc请求失败:%v", err.Error()) return nil, fmt.Errorf("rpc请求失败:%v", err.Error())
} }
var status = 1
if result.ErrCode != vo.RES_SUCCESS { if result.ErrCode != vo.RES_SUCCESS {
return nil, fmt.Errorf("请求失败:%v", result.Msg) return nil, fmt.Errorf("请求失败:%v", result.Msg)
} }
@ -80,10 +82,20 @@ func (l *YlAsyncLogic) YlAsync(req *types.AsyncReq) (resp *types.AsyncResp, err
return nil, fmt.Errorf("请求失败:%v", result.Msg) return nil, fmt.Errorf("请求失败:%v", result.Msg)
} }
supplierOrderNo := l.getExchangeCode(result.Data.VoucherCode)
if supplierOrderNo == "" {
return nil, fmt.Errorf("请求失败未取到数据:%v", result.Msg)
}
// 异步通知
go func() {
time.Sleep(2 * time.Second)
l.asyncSendMarket(supplierOrderNo, req, result.Data)
}()
return &types.AsyncResp{ return &types.AsyncResp{
Msg: "", Msg: "",
Status: status, Status: 0,
SupplierOrderNo: l.getExchangeCode(result.Data.VoucherCode), SupplierOrderNo: supplierOrderNo,
}, nil }, nil
} }
@ -97,22 +109,52 @@ func (l *YlAsyncLogic) getExchangeCode(voucherCode string) string {
} }
// 往营销系统下单,返回数据,通知下游系统 // 往营销系统下单,返回数据,通知下游系统
func (l *YlAsyncLogic) asyncSendMarket(req *types.NotifyReq) (result *types.NotifyResp, err error) { func (l *YlAsyncLogic) asyncSendMarket(supplierOrderNo string, asyncReq *types.AsyncReq, data *transfer.MarketKeySendRes_Data) {
targetUrl := l.svcCtx.Config.YouleHost + "/supplier/order/sendResultNotify" var (
var header = map[string]string{"Content-Type": "application/json;charset=UTF-8"} reqDataMap map[string]interface{}
header = map[string]string{"Content-Type": "application/json;charset=UTF-8"}
targetUrl = l.svcCtx.Config.YouleHost + "/supplier/order/sendResultNotify"
req = &types.NotifyReq{
DeliverOrderNo: asyncReq.DeliverOrderNo,
SupplierOrderNo: supplierOrderNo,
SupplierSkuId: asyncReq.SupplierSkuId,
RequestTime: time.Now().Unix(),
Account: asyncReq.Account,
Status: 2,
Msg: "",
Price: asyncReq.Price,
SupplierId: asyncReq.SupplierId,
CardNo: "",
CardKey: "",
CardExpireTime: "",
CardExchangeUrl: data.ShortUrl,
Sign: "",
}
)
b, _ := json.Marshal(req)
err := json.Unmarshal(b, &reqDataMap)
if err != nil {
return
}
req.Sign, err = sign.GetSign(reqDataMap, l.svcCtx.Config.Sys.PrimaryKey)
if err != nil {
l.Logger.Errorf("签名失败:%v", err.Error())
return
}
body, err := sonic.Marshal(req) body, err := sonic.Marshal(req)
if err != nil { if err != nil {
return nil, fmt.Errorf("请求失败:%v", err.Error()) l.Logger.Errorf("解析json失败:%v", err.Error())
return
} }
resp, err := httpclient.FastHttpPost(targetUrl, header, body, 0) resp, err := httpclient.FastHttpPost(targetUrl, header, body, 0)
if err != nil { if err != nil {
return nil, fmt.Errorf("请求失败:%v", err.Error()) l.Logger.Errorf("请求失败:%v", err.Error())
return
} }
result = &types.NotifyResp{} l.Logger.Infof("发货通知完成url=%s,请求数据:%v 请求返回数据:%v", targetUrl, string(body), string(resp))
// todo 解析返回数据
err = sonic.Unmarshal(resp, result)
return return
} }