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.

102 lines
1.6 KiB

  1. package orderrpcv2
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "log"
  6. )
  7. func Create(site_id, dbname string, data map[string]string, url ...string) (*OrderCreateRes, error) {
  8. if dbname == "" || len(data) < 1 {
  9. return nil, errors.New("参数错误")
  10. }
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return nil, err
  14. }
  15. defer conn.Close()
  16. data["dbname"] = dbname
  17. data["site_id"] = site_id
  18. req, err := SetReqData(data)
  19. if err != nil {
  20. return nil, err
  21. }
  22. res := &Response{}
  23. err = conn.Create(req, res)
  24. if err != nil {
  25. return nil, err
  26. }
  27. res_data_de, err := GetResData(res)
  28. if err != nil {
  29. return nil, err
  30. }
  31. if res_data_de == "" {
  32. return nil, nil
  33. }
  34. log.Println(res_data_de)
  35. var res_arr OrderCreateRes
  36. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  37. if err != nil {
  38. return nil, err
  39. }
  40. return &res_arr, nil
  41. }
  42. func CreateByCart(site_id, dbname string, data map[string]interface{}, url ...string) (*OrderCreateRes, error) {
  43. if dbname == "" || len(data) < 1 {
  44. return nil, errors.New("参数错误")
  45. }
  46. conn, err := rpc_server_conn(url...)
  47. if err != nil {
  48. return nil, err
  49. }
  50. defer conn.Close()
  51. data["dbname"] = dbname
  52. data["site_id"] = site_id
  53. req, err := SetReqData(data)
  54. if err != nil {
  55. return nil, err
  56. }
  57. res := &Response{}
  58. err = conn.CreateByCart(req, res)
  59. if err != nil {
  60. return nil, err
  61. }
  62. res_data_de, err := GetResData(res)
  63. if err != nil {
  64. return nil, err
  65. }
  66. if res_data_de == "" {
  67. return nil, nil
  68. }
  69. var res_arr OrderCreateRes
  70. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  71. if err != nil {
  72. return nil, err
  73. }
  74. return &res_arr, nil
  75. }