2.0订单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.

121 lines
2.1 KiB

  1. package orderrpcv2
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "strconv"
  6. )
  7. func GetUserBuyNum(site_id, dbname string, product_id string, user_id string, url ...string) (int64, error) {
  8. if dbname == "" || product_id == "" || user_id == "" {
  9. return 0, errors.New("参数错误")
  10. }
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return 0, err
  14. }
  15. defer conn.Close()
  16. var data map[string]string = make(map[string]string)
  17. data["dbname"] = dbname
  18. data["site_id"] = site_id
  19. data["product_id"] = product_id
  20. data["user_id"] = user_id
  21. req, err := SetReqData(data)
  22. if err != nil {
  23. return 0, err
  24. }
  25. res := &Response{}
  26. err = conn.GetUserBuyNum(req, res)
  27. if err != nil {
  28. return 0, err
  29. }
  30. res_data_de, err := GetResData(res)
  31. if err != nil {
  32. return 0, err
  33. }
  34. if res_data_de == "" {
  35. return 0, errors.New("no data")
  36. }
  37. var res_arr map[string]string
  38. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  39. if err != nil {
  40. return 0, err
  41. }
  42. if _, ok := res_arr["Quantity"]; ok {
  43. return strconv.ParseInt(res_arr["Quantity"], 10, 64)
  44. }
  45. return 0, errors.New("failed")
  46. }
  47. func GetUserBuyTotal(site_id, dbname string, product_id string, user_id string, url ...string) (int64, error) {
  48. if dbname == "" || product_id == "" || user_id == "" {
  49. return 0, errors.New("参数错误")
  50. }
  51. conn, err := rpc_server_conn(url...)
  52. if err != nil {
  53. return 0, err
  54. }
  55. defer conn.Close()
  56. var data map[string]string = make(map[string]string)
  57. data["dbname"] = dbname
  58. data["site_id"] = site_id
  59. data["product_id"] = product_id
  60. data["user_id"] = user_id
  61. req, err := SetReqData(data)
  62. if err != nil {
  63. return 0, err
  64. }
  65. res := &Response{}
  66. err = conn.GetUserBuyTotal(req, res)
  67. if err != nil {
  68. return 0, err
  69. }
  70. res_data_de, err := GetResData(res)
  71. if err != nil {
  72. return 0, err
  73. }
  74. if res_data_de == "" {
  75. return 0, errors.New("no data")
  76. }
  77. var res_arr map[string]string
  78. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  79. if err != nil {
  80. return 0, err
  81. }
  82. if _, ok := res_arr["Total"]; ok {
  83. return strconv.ParseInt(res_arr["Total"], 10, 64)
  84. }
  85. return 0, errors.New("failed")
  86. }