|
|
@ -0,0 +1,121 @@ |
|
|
|
package orderrpcv2 |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"errors" |
|
|
|
"strconv" |
|
|
|
) |
|
|
|
|
|
|
|
func GetUserBuyNum(site_id, dbname string, product_id string, user_id string, url ...string) (int64, error) { |
|
|
|
|
|
|
|
if dbname == "" || product_id == "" || user_id == "" { |
|
|
|
return 0, errors.New("参数错误") |
|
|
|
} |
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
var data map[string]string = make(map[string]string) |
|
|
|
|
|
|
|
data["dbname"] = dbname |
|
|
|
data["site_id"] = site_id |
|
|
|
data["product_id"] = product_id |
|
|
|
data["user_id"] = user_id |
|
|
|
|
|
|
|
req, err := SetReqData(data) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
err = conn.GetUserBuyNum(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
if res_data_de == "" { |
|
|
|
return 0, errors.New("no data") |
|
|
|
} |
|
|
|
|
|
|
|
var res_arr map[string]string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := res_arr["Quantity"]; ok { |
|
|
|
return strconv.ParseInt(res_arr["Quantity"], 10, 64) |
|
|
|
} |
|
|
|
return 0, errors.New("failed") |
|
|
|
} |
|
|
|
|
|
|
|
func GetUserBuyTotal(site_id, dbname string, product_id string, user_id string, url ...string) (int64, error) { |
|
|
|
|
|
|
|
if dbname == "" || product_id == "" || user_id == "" { |
|
|
|
return 0, errors.New("参数错误") |
|
|
|
} |
|
|
|
|
|
|
|
conn, err := rpc_server_conn(url...) |
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
defer conn.Close() |
|
|
|
|
|
|
|
var data map[string]string = make(map[string]string) |
|
|
|
|
|
|
|
data["dbname"] = dbname |
|
|
|
data["site_id"] = site_id |
|
|
|
data["product_id"] = product_id |
|
|
|
data["user_id"] = user_id |
|
|
|
|
|
|
|
req, err := SetReqData(data) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
res := &Response{} |
|
|
|
|
|
|
|
err = conn.GetUserBuyTotal(req, res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
res_data_de, err := GetResData(res) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
if res_data_de == "" { |
|
|
|
return 0, errors.New("no data") |
|
|
|
} |
|
|
|
|
|
|
|
var res_arr map[string]string |
|
|
|
|
|
|
|
err = json.Unmarshal([]byte(res_data_de), &res_arr) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
return 0, err |
|
|
|
} |
|
|
|
|
|
|
|
if _, ok := res_arr["Total"]; ok { |
|
|
|
return strconv.ParseInt(res_arr["Total"], 10, 64) |
|
|
|
} |
|
|
|
return 0, errors.New("failed") |
|
|
|
} |