package orderrpcv2
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
"log"
|
|
)
|
|
|
|
func Create(site_id, dbname string, data map[string]string, url ...string) (*OrderCreateRes, error) {
|
|
|
|
if dbname == "" || len(data) < 1 {
|
|
return nil, errors.New("参数错误")
|
|
}
|
|
|
|
conn, err := rpc_server_conn(url...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
data["dbname"] = dbname
|
|
data["site_id"] = site_id
|
|
|
|
req, err := SetReqData(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &Response{}
|
|
|
|
err = conn.Create(req, res)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res_data_de, err := GetResData(res)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if res_data_de == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
log.Println(res_data_de)
|
|
|
|
var res_arr OrderCreateRes
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &res_arr, nil
|
|
|
|
}
|
|
|
|
func CreateByCart(site_id, dbname string, data map[string]interface{}, url ...string) (*OrderCreateRes, error) {
|
|
|
|
if dbname == "" || len(data) < 1 {
|
|
return nil, errors.New("参数错误")
|
|
}
|
|
|
|
conn, err := rpc_server_conn(url...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer conn.Close()
|
|
|
|
data["dbname"] = dbname
|
|
data["site_id"] = site_id
|
|
|
|
req, err := SetReqData(data)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
res := &Response{}
|
|
|
|
err = conn.CreateByCart(req, res)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
res_data_de, err := GetResData(res)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if res_data_de == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
var res_arr OrderCreateRes
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr)
|
|
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &res_arr, nil
|
|
}
|