7 Commits

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
10 changed files with 346 additions and 27 deletions
Split View
  1. +53
    -0
      client.getinfo.go
  2. +10
    -2
      client.getinfo_test.go
  3. +35
    -25
      client_test.go
  4. +12
    -0
      order.pb.go
  5. +3
    -0
      order.proto
  6. +53
    -0
      payed.go
  7. +25
    -0
      payed_test.go
  8. +121
    -0
      statistics.go
  9. +33
    -0
      statistics_test.go
  10. +1
    -0
      variable.go

+ 53
- 0
client.getinfo.go View File

@ -23,6 +23,59 @@ func GetInfo(site_id, dbname string, order_id string, field string, url ...strin
data["site_id"] = site_id
data["order_id"] = order_id
data["field"] = field
data["condition"] = "order_id"
req, err := SetReqData(data)
if err != nil {
return nil, err
}
res := &Response{}
err = conn.Get(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 map[string]string
err = json.Unmarshal([]byte(res_data_de), &res_arr)
if err != nil {
return nil, err
}
return res_arr, nil
}
func GetInfoByOrderSn(site_id, dbname string, order_sn string, field string, url ...string) (map[string]string, error) {
if dbname == "" || order_sn == "" {
return nil, errors.New("参数错误")
}
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
var data map[string]string = make(map[string]string)
data["dbname"] = dbname
data["site_id"] = site_id
data["order_sn"] = order_sn
data["field"] = field
data["condition"] = "order_sn"
req, err := SetReqData(data)
if err != nil {


+ 10
- 2
client.getinfo_test.go View File

@ -2,12 +2,20 @@ package orderrpcv2
import (
"testing"
"git.tetele.net/tgo/crypter"
)
func Test_GetInfo(t *testing.T) {
ret, err := GetInfo("100064", "shop_v2", "1", "id,order_sn")
// ret, err := GetInfoByOrderSn("100064", "shop_v2", "2021000121222", "id,order_sn")
// t.Log(ret)
// t.Log(err)
data := "1DD5556CC3F069F517419E4BAA490CFBE0BB2D0027C59249B641A0D1AF05E2A3076F605D22044171D5552BF856B6448807F7B08063421E0C263CC47B3ECB0763193D704A0B4A30018F980E5D2F8A7196A7B0EAE7D7FF3E6F20BA573EAB2A3A196CC4ECE6095A76B1E2F9660AB4AAC04C0FF7C74C3CEAEF0E82D0357E67C2549AA754B1DFE3F1F195F075CFBCCB59A8A4"
ret := crypter.DesDe(data, DES_KEY)
t.Log(ret)
t.Log(err)
}

+ 35
- 25
client_test.go
File diff suppressed because it is too large
View File


+ 12
- 0
order.pb.go View File

@ -103,6 +103,9 @@ type OrderService interface {
Cancel(in *Request, out *Response) error
AutoReceive(in *Request, out *Response) error
Get(in *Request, out *Response) error
GetUserBuyTotal(in *Request, out *Response) error
GetUserBuyNum(in *Request, out *Response) error
Payed(in *Request, out *Response) error
}
// AcceptOrderServiceClient accepts connections on the listener and serves requests
@ -189,6 +192,15 @@ func (c *OrderServiceClient) AutoReceive(in *Request, out *Response) error {
func (c *OrderServiceClient) Get(in *Request, out *Response) error {
return c.Call("OrderService.Get", in, out)
}
func (c *OrderServiceClient) GetUserBuyTotal(in *Request, out *Response) error {
return c.Call("OrderService.GetUserBuyTotal", in, out)
}
func (c *OrderServiceClient) GetUserBuyNum(in *Request, out *Response) error {
return c.Call("OrderService.GetUserBuyNum", in, out)
}
func (c *OrderServiceClient) Payed(in *Request, out *Response) error {
return c.Call("OrderService.Payed", in, out)
}
// DialOrderService connects to an OrderService at the specified network address.
func DialOrderService(network, addr string) (*OrderServiceClient, *rpc.Client, error) {


+ 3
- 0
order.proto View File

@ -22,4 +22,7 @@ service OrderService {
rpc cancel (Request) returns (Response); //
rpc autoReceive(Request) returns(Response); //
rpc Get (Request) returns (Response); // 使id查询
rpc GetUserBuyTotal (Request) returns (Response); //
rpc GetUserBuyNum (Request) returns (Response); //
rpc Payed (Request) returns (Response); //
}

+ 53
- 0
payed.go View File

@ -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
}

+ 25
- 0
payed_test.go View File

@ -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)
}

+ 121
- 0
statistics.go View File

@ -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")
}

+ 33
- 0
statistics_test.go View File

@ -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)
}

+ 1
- 0
variable.go View File

@ -4,6 +4,7 @@ const DES_KEY = "ordernew"
type OrderCreateRes struct {
OrderSn string
OrderId string
}
type OrderCancelRes struct {


Loading…
Cancel
Save