Author | SHA1 | Message | Date |
---|---|---|---|
guzeng | 357bf1c377 | 支付调用方法 | 3 years ago |
guzeng | 3d93dcc397 | 增加订单支付写入 | 3 years ago |
guzeng | 99a1ea238c | 增加查询限购公共调用方法 | 3 years ago |
guzeng | a477ea1dd3 | 修改查询用户订单统计 | 3 years ago |
guzeng | b67bc66cfd | 增加查询用户订单统计 | 3 years ago |
guzeng | 0f4871a490 | 修改订单创建成功参数 | 3 years ago |
guzeng | 9d598a9833 | 增加查询方法 | 3 years ago |
@ -0,0 +1,53 @@ | |||
package orderrpcv2 | |||
import ( | |||
"encoding/json" | |||
"errors" | |||
) | |||
func Payed(dbname, platform string, data map[string]interface{}, url ...string) (*OrderCancelRes, 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["platform"] = platform | |||
req, err := SetReqData(data) | |||
if err != nil { | |||
return nil, err | |||
} | |||
res := &Response{} | |||
err = conn.Payed(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,25 @@ | |||
package orderrpcv2 | |||
import ( | |||
"testing" | |||
) | |||
func Test_Payed(t *testing.T) { | |||
payData := map[string]interface{}{ | |||
"pay_type": "wechat", | |||
"pay_method": "jsapi", | |||
"order_sn": "2163040248896658", | |||
"payment_sn": "ddddd", | |||
"payer_total": 17.66, | |||
"total": 33.33, //单位转为元 | |||
"user_openid": "adfawrkepoieirpwoer", | |||
"user_id": "55", | |||
"success_time": "2021-10-12 10:20:30", | |||
} | |||
ret, err := Payed("shop_v2", "miniapp", payData) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |
@ -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") | |||
} |
@ -0,0 +1,33 @@ | |||
package orderrpcv2 | |||
import ( | |||
"testing" | |||
) | |||
func Test_GetUserBuyNum(t *testing.T) { | |||
site_id := "10110" | |||
dbname := "shop_v2" | |||
product_id := "51" | |||
user_id := "2" | |||
ret, err := GetUserBuyNum(site_id, dbname, product_id, user_id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} | |||
func Test_GetUserBuyTotal(t *testing.T) { | |||
site_id := "10110" | |||
dbname := "shop_v2" | |||
product_id := "51" | |||
user_id := "2" | |||
ret, err := GetUserBuyTotal(site_id, dbname, product_id, user_id) | |||
t.Log(ret) | |||
t.Log(err) | |||
} |