商品rpc数据格式及调用方法
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.5 KiB

  1. package productrpc
  2. import (
  3. "encoding/json"
  4. // "strconv"
  5. // "time"
  6. "github.com/golang/protobuf/proto"
  7. )
  8. /**
  9. * id获取商品sku信息
  10. * 2021/08/20
  11. * GZ
  12. */
  13. func GetSku(site_id, dbname, id string, field string, url ...string) (map[string]string, error) {
  14. conn, err := rpc_server_conn(url...)
  15. if err != nil {
  16. return nil, err
  17. }
  18. defer conn.Close()
  19. req := &GetRequest{proto.String(site_id), proto.String(dbname), proto.String(id), proto.String(field), nil}
  20. res := &GetResponse{}
  21. err = conn.GetSku(req, res)
  22. if err != nil {
  23. return nil, err
  24. }
  25. value := res.GetValue()
  26. var data map[string]string
  27. err = json.Unmarshal(value, &data)
  28. return data, err
  29. }
  30. /**
  31. * uuid获取商品sku信息
  32. * 2021/08/20
  33. * GZ
  34. */
  35. func GetSkuByUuid(site_id, dbname, uuid string, field string, url ...string) (map[string]string, error) {
  36. conn, err := rpc_server_conn(url...)
  37. if err != nil {
  38. return nil, err
  39. }
  40. defer conn.Close()
  41. req := &GetUuidRequest{proto.String(site_id), proto.String(dbname), proto.String(uuid), proto.String(field), nil}
  42. res := &GetResponse{}
  43. err = conn.GetSkuByUuid(req, res)
  44. if err != nil {
  45. return nil, err
  46. }
  47. value := res.GetValue()
  48. var data map[string]string
  49. err = json.Unmarshal(value, &data)
  50. return data, err
  51. }
  52. /**
  53. * product uuid获取商品sku信息
  54. * 2021/11/29
  55. * GZ
  56. */
  57. func GetSkuInfo(site_id, dbname, product_uuid string, sku_id string, field string, url ...string) (map[string]string, error) {
  58. conn, err := rpc_server_conn(url...)
  59. if err != nil {
  60. return nil, err
  61. }
  62. defer conn.Close()
  63. req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(sku_id), proto.String(field), nil}
  64. res := &GetResponse{}
  65. err = conn.GetSkuInfo(req, res)
  66. if err != nil {
  67. return nil, err
  68. }
  69. value := res.GetValue()
  70. var data map[string]string
  71. err = json.Unmarshal(value, &data)
  72. return data, err
  73. }
  74. /**
  75. * product uuid获取商品sku信息
  76. * 2021/11/29
  77. * GZ
  78. */
  79. func GetSkuList(site_id, dbname, product_uuid string, field string, url ...string) ([]map[string]string, error) {
  80. conn, err := rpc_server_conn(url...)
  81. if err != nil {
  82. return nil, err
  83. }
  84. defer conn.Close()
  85. req := &GetSkuRequest{proto.String(site_id), proto.String(dbname), proto.String(product_uuid), proto.String(""), proto.String(field), nil}
  86. res := &GetResponse{}
  87. err = conn.GetSkuList(req, res)
  88. if err != nil {
  89. return nil, err
  90. }
  91. value := res.GetValue()
  92. var data []map[string]string
  93. err = json.Unmarshal(value, &data)
  94. return data, err
  95. }