71 lines
1.9 KiB
Go
71 lines
1.9 KiB
Go
|
package do
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"strconv"
|
||
|
"trasfer_middleware/cmd/rpc/internal/logic/vo"
|
||
|
"trasfer_middleware/genModel"
|
||
|
)
|
||
|
|
||
|
type OrderSetter interface {
|
||
|
SetData(resq string, resp string) error
|
||
|
// 可以根据需要添加更多方法
|
||
|
}
|
||
|
|
||
|
type ZltxRsData struct {
|
||
|
Order *genModel.ServerOrderZltx
|
||
|
}
|
||
|
|
||
|
func (z *ZltxRsData) SetData(resq string, resp string) error {
|
||
|
orderInfoReq, orderInfoRes, err := getOrderMap(resq, resp)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
z.Order.Num, err = strconv.ParseInt(orderInfoReq["num"].(string), 16, 64)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
z.Order.VoucherNum = orderInfoReq["vendorNo"].(string)
|
||
|
z.Order.OutBizNo = orderInfoRes["data"].(map[string]interface{})["sipOrderNo"].(string)
|
||
|
z.Order.OrderNum = orderInfoRes["data"].(map[string]interface{})["vendorOrderNo"].(string)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
type RsData struct {
|
||
|
Order *genModel.ServerOrderRs
|
||
|
}
|
||
|
|
||
|
func (z *RsData) SetData(resq string, resp string) error {
|
||
|
orderInfoReq, orderInfoRes, err := getOrderMap(resq, resp)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
z.Order.Num, err = strconv.ParseInt(orderInfoReq["num"].(string), 16, 64)
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
z.Order.VoucherNum = orderInfoReq["vendorNo"].(string)
|
||
|
z.Order.OutBizNo = orderInfoRes["data"].(map[string]interface{})["sipOrderNo"].(string)
|
||
|
z.Order.OrderNum = orderInfoRes["data"].(map[string]interface{})["vendorOrderNo"].(string)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func getOrderMap(resq string, resp string) (orderInfoReq map[string]interface{}, orderInfoRes map[string]interface{}, err error) {
|
||
|
err = json.Unmarshal([]byte(resq), &orderInfoReq)
|
||
|
if err != nil {
|
||
|
return nil, nil, err
|
||
|
}
|
||
|
err = json.Unmarshal([]byte(resp), &orderInfoRes)
|
||
|
if err != nil {
|
||
|
return nil, nil, err
|
||
|
}
|
||
|
if orderInfoRes["code"].(string) != vo.ZLTX_RS_RESP_SUCCESS {
|
||
|
return nil, nil, fmt.Errorf("订单已存在")
|
||
|
}
|
||
|
if orderInfoRes["data"] == nil {
|
||
|
return nil, nil, err
|
||
|
}
|
||
|
return orderInfoReq, orderInfoRes, err
|
||
|
}
|