From 5dcf9317412e9422b23848412837f4fc44b7e0b3 Mon Sep 17 00:00:00 2001 From: guzeng Date: Wed, 6 Oct 2021 21:34:50 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=B4=BB=E5=8A=A8=E6=9F=A5?= =?UTF-8?q?=E8=AF=A2=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- activity.go | 142 +++++++++++++++++++++++++++++++++++++++++++++++ activity_test.go | 17 ++++++ go.mod | 2 + go.sum | 10 ++++ variable.go | 9 ++- 5 files changed, 175 insertions(+), 5 deletions(-) create mode 100644 activity.go create mode 100644 activity_test.go diff --git a/activity.go b/activity.go new file mode 100644 index 0000000..2af910b --- /dev/null +++ b/activity.go @@ -0,0 +1,142 @@ +package productrpc + +import ( + "encoding/json" + // "strconv" + // "time" +) + +/** + * 获取商品进行中活动 + * 2021/10/06 + * GZ + */ +func GetActivity(site_id, dbname, id string, sku_id string, url ...string) ([]map[string]string, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() + + arg := GetActivityParam{site_id, dbname, id, sku_id} + + req, err := SetReqData(arg) + if err != nil { + return nil, err + } + + res := &Response{} + + err = conn.GetActivity(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 +} + +/** + * 获取商品预热中活动 + * 2021/10/06 + * GZ + */ +func GetWarmingActivity(site_id, dbname, id string, sku_id string, url ...string) ([]map[string]string, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() + + arg := GetActivityParam{site_id, dbname, id, sku_id} + + req, err := SetReqData(arg) + if err != nil { + return nil, err + } + + res := &Response{} + + err = conn.GetWarmingActivity(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 +} + +/** + * 获取商品进行中活动 + * 2021/10/06 + * GZ + */ +func GetAllActivity(site_id, dbname, id string, sku_id string, url ...string) ([]map[string]string, error) { + + conn, err := rpc_server_conn(url...) + if err != nil { + return nil, err + } + defer conn.Close() + + arg := GetActivityParam{site_id, dbname, id, sku_id} + + req, err := SetReqData(arg) + if err != nil { + return nil, err + } + + res := &Response{} + + err = conn.GetAllActivity(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 +} diff --git a/activity_test.go b/activity_test.go new file mode 100644 index 0000000..3e88704 --- /dev/null +++ b/activity_test.go @@ -0,0 +1,17 @@ +package productrpc + +import ( + "testing" +) + +func Test_GetAllActivity(t *testing.T) { + dbname := "shop_v2" + id := "10248" + site_id := "10248" + sku_id := "10248" + + ret, err := GetAllActivity(site_id, dbname, id, sku_id) + + t.Log(ret) + t.Log(err) +} diff --git a/go.mod b/go.mod index 894dd42..fe2c9b0 100644 --- a/go.mod +++ b/go.mod @@ -4,6 +4,8 @@ go 1.14 require ( git.tetele.net/tgo/conf v0.33.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-20210921155107-089bfa567519 // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect ) diff --git a/go.sum b/go.sum index 9625c61..779d8fe 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,20 @@ git.tetele.net/tgo/conf v0.33.1 h1:ZEIv3Vq35RCv5f3T3Uz97s2mkZLl7W5OlmXvzI3/sS8= git.tetele.net/tgo/conf v0.33.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-20210921155107-089bfa567519 h1:7I4JAnoQBe7ZtJcBaYHi5UtiO8tQHbUSXxL+pnGRANg= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/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= diff --git a/variable.go b/variable.go index e5ed754..3af80a1 100644 --- a/variable.go +++ b/variable.go @@ -1,11 +1,10 @@ package productrpc type GetActivityParam struct { - SiteId string `json:"site_id"` - Dbname string `json:"database"` - Id string `json:"id"` - SkuId string `json:"sku_id"` - ActivityStatus string `json:"activity_status"` + SiteId string `json:"site_id"` + Dbname string `json:"database"` + Id string `json:"id"` + SkuId string `json:"sku_id"` } type GetUuidParam struct {