feat: 发货通知接口
This commit is contained in:
parent
7aace0acfa
commit
86b9079ffc
|
|
@ -2,8 +2,11 @@ package yl
|
|||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/bytedance/sonic"
|
||||
"rs/untils/sign"
|
||||
|
||||
"rs/cmd/api/internal/logic/vo"
|
||||
"rs/rpc/transfer"
|
||||
"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())
|
||||
}
|
||||
|
||||
var status = 1
|
||||
if result.ErrCode != vo.RES_SUCCESS {
|
||||
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)
|
||||
}
|
||||
|
||||
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{
|
||||
Msg: "",
|
||||
Status: status,
|
||||
SupplierOrderNo: l.getExchangeCode(result.Data.VoucherCode),
|
||||
Status: 0,
|
||||
SupplierOrderNo: supplierOrderNo,
|
||||
}, nil
|
||||
|
||||
}
|
||||
|
|
@ -97,22 +109,52 @@ func (l *YlAsyncLogic) getExchangeCode(voucherCode string) string {
|
|||
}
|
||||
|
||||
// 往营销系统下单,返回数据,通知下游系统
|
||||
func (l *YlAsyncLogic) asyncSendMarket(req *types.NotifyReq) (result *types.NotifyResp, err error) {
|
||||
targetUrl := l.svcCtx.Config.YouleHost + "/supplier/order/sendResultNotify"
|
||||
var header = map[string]string{"Content-Type": "application/json;charset=UTF-8"}
|
||||
func (l *YlAsyncLogic) asyncSendMarket(supplierOrderNo string, asyncReq *types.AsyncReq, data *transfer.MarketKeySendRes_Data) {
|
||||
var (
|
||||
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)
|
||||
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)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("请求失败:%v", err.Error())
|
||||
l.Logger.Errorf("请求失败:%v", err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
result = &types.NotifyResp{}
|
||||
// todo 解析返回数据
|
||||
err = sonic.Unmarshal(resp, result)
|
||||
l.Logger.Infof("发货通知完成:url=%s,请求数据:%v 请求返回数据:%v", targetUrl, string(body), string(resp))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue