@ -0,0 +1,55 @@ | |||
package orderrpcv2 | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
) | |||
func Cancel(site_id, dbname string, order_id string, url ...string) (*OrderCancelRes, error) { | |||
if dbname == "" || order_id == "" { | |||
return nil, errors.New("参数错误") | |||
} | |||
conn, err := rpc_server_conn(url...) | |||
if err != nil { | |||
return nil, err | |||
} | |||
defer conn.Close() | |||
data := make(map[string]string) | |||
data["dbname"] = dbname | |||
data["site_id"] = site_id | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.Cancel(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 OrderCancelRes | |||
err = json.Unmarshal([]byte(res_data_de), &res_arr) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return &res_arr, nil | |||
} |
@ -0,0 +1,13 @@ | |||
package orderrpcv2 | |||
import ( | |||
"testing" | |||
) | |||
func Test_Cancel(t *testing.T) { | |||
ret, err := Cancel("jianfan", "100064", "2") | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,102 @@ | |||
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(dbname, site_id 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 | |||
} |
@ -0,0 +1,35 @@ | |||
package orderrpcv2 | |||
import ( | |||
"testing" | |||
) | |||
func Test_Create(t *testing.T) { | |||
// products := []map[string]string{ | |||
// map[string]string{ | |||
// "product_id": "18", | |||
// "sku_id": "6", | |||
// "quantity": "3", | |||
// }, | |||
// map[string]string{ | |||
// "product_id": "6", | |||
// "sku_id": "7", | |||
// "quantity": "2", | |||
// }, | |||
// } | |||
data := map[string]string{ | |||
"product_id": "19", | |||
"name": "5BC02AB31C", | |||
"mobile": "326598744", | |||
"user_id": "2", | |||
"quantity": "3", | |||
"business_id": "1", | |||
"sku_id": "5", | |||
} | |||
ret, err := Create("100064", "shop_v2", data) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -0,0 +1,23 @@ | |||
package orderrpcv2 | |||
import ( | |||
"git.tetele.net/tgo/conf" | |||
) | |||
func rpc_server_conn(url ...string) (*OrderServiceClient, error) { | |||
var rpc_url string | |||
if len(url) > 0 && url[0] != "" { | |||
rpc_url = url[0] | |||
} else if conf.ORDER_RPC_V2_URL != "" { | |||
rpc_url = conf.ORDER_RPC_V2_URL | |||
} else { | |||
rpc_url = "127.0.0.1:" + conf.ORDER_RPC_V2_PORT | |||
} | |||
conn, _, err := DialOrderService("tcp", rpc_url) | |||
if err != nil { | |||
return nil, err | |||
} | |||
return conn, nil | |||
} |
@ -1,3 +1,11 @@ | |||
module git.tetele.net/tgo/orderrpcv2 | |||
go 1.14 | |||
require ( | |||
git.tetele.net/tgo/conf v0.35.1 // indirect | |||
git.tetele.net/tgo/crypter v0.2.2 // indirect | |||
github.com/chai2010/protorpc v1.1.3 // indirect | |||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect | |||
) |
@ -0,0 +1,20 @@ | |||
git.tetele.net/tgo/conf v0.35.1 h1:1f/mzITBHCOPzu1SuYnbL4oHpNEIZewSaAwlI3vNoOQ= | |||
git.tetele.net/tgo/conf v0.35.1/go.mod h1:AWVIBEDE5dtotthUgR0SWaR2Qa6/f+O5WQ3s7Tj8q7A= | |||
git.tetele.net/tgo/crypter v0.2.2 h1:YMQJh2Gj5Po4ZfelJUmXBKi01UbmtiSy3bmqRfnYQMo= | |||
git.tetele.net/tgo/crypter v0.2.2/go.mod h1:vfvRLZA8+lHNgNXneOcgvVhDyuv25ZRb+C6xHOmXNx0= | |||
github.com/chai2010/protorpc v1.1.3 h1:VJK5hIoZn0XCGol0GmbxZkUG6FbTI5LP2Lam6RVd15w= | |||
github.com/chai2010/protorpc v1.1.3/go.mod h1:/wO0kiyVdu7ug8dCMrA2yDr2vLfyhsLEuzLa9J2HJ+I= | |||
github.com/golang/protobuf v1.0.0 h1:lsek0oXi8iFE9L+EXARyHIjU5rlWIhhTkjDz3vHhWWQ= | |||
github.com/golang/protobuf v1.0.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= | |||
github.com/golang/snappy v0.0.3 h1:fHPg5GQYlCeLIPB9BZqMVR5nR9A+IM5zcgeTdjMYmLA= | |||
github.com/golang/snappy v0.0.3/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= | |||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 h1:HWj/xjIHfjYU5nVXpTM0s39J9CbLn7Cc5a7IC5rwsMQ= | |||
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | |||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ= | |||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | |||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | |||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | |||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | |||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | |||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= |