2 Commits

Author SHA1 Message Date
  guzeng 4708e7d381 增加sku缓存查询 3 years ago
  guzeng 709392fb99 增加取sku方法 3 years ago
4 changed files with 138 additions and 3 deletions
Split View
  1. +66
    -0
      getskuinfo.go
  2. +5
    -3
      getskuinfo_test.go
  3. +57
    -0
      product.pb.go
  4. +10
    -0
      product.proto

+ 66
- 0
getskuinfo.go View File

@ -72,3 +72,69 @@ func GetSkuByUuid(site_id, dbname, uuid string, field string, url ...string) (ma
return data, err
}
/**
* product uuid获取商品sku信息
* 2021/11/29
* GZ
*/
func GetSkuInfo(site_id, dbname, product_uuid string, sku_id string, field string, url ...string) (map[string]string, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(sku_id), proto.String(field), nil}
res := &GetResponse{}
err = conn.GetSkuInfo(req, res)
if err != nil {
return nil, err
}
value := res.GetValue()
var data map[string]string
err = json.Unmarshal(value, &data)
return data, err
}
/**
* product uuid获取商品sku信息
* 2021/11/29
* GZ
*/
func GetSkuList(site_id, dbname, product_uuid string, field string, url ...string) ([]map[string]string, error) {
conn, err := rpc_server_conn(url...)
if err != nil {
return nil, err
}
defer conn.Close()
req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(""), proto.String(field), nil}
res := &GetResponse{}
err = conn.GetSkuList(req, res)
if err != nil {
return nil, err
}
value := res.GetValue()
var data []map[string]string
err = json.Unmarshal(value, &data)
return data, err
}

+ 5
- 3
getskuinfo_test.go View File

@ -4,11 +4,13 @@ import (
"testing"
)
func Test_GetSku(t *testing.T) {
func Test_GetSkuInfo(t *testing.T) {
dbname := "shop_v2"
id := "10"
product_uuid := "39034"
site_id := "1058278"
sku_id := "39814"
ret, err := GetSku(dbname, id)
ret, err := GetSkuInfo(site_id, dbname, product_uuid, sku_id, "")
t.Log(ret)
t.Log(err)


+ 57
- 0
product.pb.go View File

@ -11,6 +11,7 @@ It is generated from these files:
It has these top-level messages:
GetRequest
GetUuidRequest
GetSkuRequest
GetResponse
Request
Response
@ -112,6 +113,54 @@ func (m *GetUuidRequest) GetField() string {
return ""
}
type GetSkuRequest struct {
SiteId *string `protobuf:"bytes,1,opt,name=site_id" json:"site_id,omitempty"`
Dbname *string `protobuf:"bytes,2,opt,name=dbname" json:"dbname,omitempty"`
ProductUuid *string `protobuf:"bytes,3,opt,name=product_uuid" json:"product_uuid,omitempty"`
SkuId *string `protobuf:"bytes,4,opt,name=sku_id" json:"sku_id,omitempty"`
Field *string `protobuf:"bytes,5,opt,name=field" json:"field,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *GetSkuRequest) Reset() { *m = GetSkuRequest{} }
func (m *GetSkuRequest) String() string { return proto.CompactTextString(m) }
func (*GetSkuRequest) ProtoMessage() {}
func (m *GetSkuRequest) GetSiteId() string {
if m != nil && m.SiteId != nil {
return *m.SiteId
}
return ""
}
func (m *GetSkuRequest) GetDbname() string {
if m != nil && m.Dbname != nil {
return *m.Dbname
}
return ""
}
func (m *GetSkuRequest) GetProductUuid() string {
if m != nil && m.ProductUuid != nil {
return *m.ProductUuid
}
return ""
}
func (m *GetSkuRequest) GetSkuId() string {
if m != nil && m.SkuId != nil {
return *m.SkuId
}
return ""
}
func (m *GetSkuRequest) GetField() string {
if m != nil && m.Field != nil {
return *m.Field
}
return ""
}
// 使用key查询响应结构
type GetResponse struct {
Value []byte `protobuf:"bytes,1,opt,name=value" json:"value,omitempty"`
@ -210,6 +259,8 @@ type ProductService interface {
GetProductActivity(in *Request, out *Response) error
GetProductAllActivity(in *Request, out *Response) error
GetProductWarmingActivity(in *Request, out *Response) error
GetSkuInfo(in *GetSkuRequest, out *GetResponse) error
GetSkuList(in *GetSkuRequest, out *GetResponse) error
}
// AcceptProductServiceClient accepts connections on the listener and serves requests
@ -314,6 +365,12 @@ func (c *ProductServiceClient) GetProductAllActivity(in *Request, out *Response)
func (c *ProductServiceClient) GetProductWarmingActivity(in *Request, out *Response) error {
return c.Call("ProductService.GetProductWarmingActivity", in, out)
}
func (c *ProductServiceClient) GetSkuInfo(in *GetSkuRequest, out *GetResponse) error {
return c.Call("ProductService.GetSkuInfo", in, out)
}
func (c *ProductServiceClient) GetSkuList(in *GetSkuRequest, out *GetResponse) error {
return c.Call("ProductService.GetSkuList", in, out)
}
// DialProductService connects to an ProductService at the specified network address.
func DialProductService(network, addr string) (*ProductServiceClient, *rpc.Client, error) {


+ 10
- 0
product.proto View File

@ -16,6 +16,14 @@ message GetUuidRequest {
string field = 4;
}
message GetSkuRequest {
string site_id = 1;
string dbname = 2;
string product_uuid = 3;
string sku_id = 4;
string field = 5;
}
// 使key查询响应结构
message GetResponse {
bytes value = 1;
@ -49,4 +57,6 @@ service ProductService {
rpc GetProductActivity(Request) returns (Response); //
rpc GetProductAllActivity(Request) returns (Response); //
rpc GetProductWarmingActivity(Request) returns (Response); //
rpc GetSkuInfo (GetSkuRequest) returns (GetResponse); // 使uuid查询
rpc GetSkuList (GetSkuRequest) returns (GetResponse); // 使uuid查询
}

Loading…
Cancel
Save