第三方api接口
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.

goods.go 4.5 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. package csjplatform
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok"
  4. zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
  5. "encoding/json"
  6. "fmt"
  7. "github.com/tidwall/gjson"
  8. "strings"
  9. )
  10. //商品类目
  11. func GoodsCate(args map[string]string) (string, error) {
  12. params := map[string]interface{}{"parent_id": zhios_third_party_utils.StrToInt(args["parent_id"])}
  13. send, err := Send(args["app_id"], args["app_secret"], "product/category", params)
  14. fmt.Println(send)
  15. fmt.Println(err)
  16. return send, err
  17. }
  18. //3.2.1 商品列表接口
  19. func GoodsList(args map[string]string) []tik_tok.TikTokGoods {
  20. params := map[string]interface{}{
  21. "page": zhios_third_party_utils.StrToInt(args["page"]),
  22. "page_size": zhios_third_party_utils.StrToInt(args["page_size"]),
  23. }
  24. if args["title"] != "" {
  25. params["title"] = args["title"]
  26. }
  27. if args["first_cids"] != "" {
  28. ex := strings.Split(args["first_cids"], ",")
  29. ids := make([]int, 0)
  30. for _, v := range ex {
  31. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  32. }
  33. params["first_cids"] = ids
  34. }
  35. if args["price_min"] != "" {
  36. params["price_min"] = int(zhios_third_party_utils.StrToFloat64(args["price_min"]) * 100)
  37. }
  38. if args["price_max"] != "" {
  39. params["price_max"] = int(zhios_third_party_utils.StrToFloat64(args["price_max"]) * 100)
  40. }
  41. if args["sell_num_min"] != "" {
  42. params["sell_num_min"] = zhios_third_party_utils.StrToInt(args["sell_num_min"])
  43. }
  44. if args["sell_num_max"] != "" {
  45. params["sell_num_max"] = zhios_third_party_utils.StrToInt(args["sell_num_max"])
  46. }
  47. if args["search_type"] != "" {
  48. params["search_type"] = zhios_third_party_utils.StrToInt(args["search_type"])
  49. }
  50. if args["order_type"] != "" {
  51. params["order_type"] = zhios_third_party_utils.StrToInt(args["order_type"])
  52. }
  53. if args["cos_fee_min"] != "" {
  54. params["cos_fee_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_min"]) * 100)
  55. }
  56. if args["cos_fee_max"] != "" {
  57. params["cos_fee_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_max"]) * 100)
  58. }
  59. if args["cos_ratio_min"] != "" {
  60. params["cos_ratio_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_min"]) * 100)
  61. }
  62. if args["cos_ratio_max"] != "" {
  63. params["cos_ratio_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_max"]) * 100)
  64. }
  65. if args["activity_id"] != "" {
  66. params["activity_id"] = zhios_third_party_utils.StrToInt(args["activity_id"])
  67. }
  68. send, err := Send(args["app_id"], args["app_secret"], "product/search", params)
  69. fmt.Println(send)
  70. var goodsList = make([]tik_tok.TikTokGoods, 0)
  71. product := gjson.Get(send, "data.products").String()
  72. if err != nil || product == "" {
  73. return goodsList
  74. }
  75. var lmData struct {
  76. Data struct {
  77. Products []tik_tok.TikTokGoodsLm `json:"products"`
  78. } `json:"data"`
  79. }
  80. err = json.Unmarshal([]byte(send), &lmData)
  81. if err != nil {
  82. fmt.Println("抖音商品1", err)
  83. return goodsList
  84. }
  85. for _, v := range lmData.Data.Products {
  86. tmp := tik_tok.CommGoodsDetail(v)
  87. goodsList = append(goodsList, tmp)
  88. }
  89. return goodsList
  90. }
  91. //商品详情接口
  92. func GoodsDetail(args map[string]string) tik_tok.TikTokGoods {
  93. params := map[string]interface{}{}
  94. if args["product_ids"] != "" {
  95. ex := strings.Split(args["product_ids"], ",")
  96. ids := make([]int, 0)
  97. for _, v := range ex {
  98. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  99. }
  100. params["product_ids"] = ids
  101. }
  102. send, err := Send(args["app_id"], args["app_secret"], "product/detail", params)
  103. var goodsList = tik_tok.TikTokGoods{}
  104. product := gjson.Get(send, "data.products").String()
  105. if err != nil || product == "" {
  106. return goodsList
  107. }
  108. var lmData struct {
  109. Data struct {
  110. Products []tik_tok.TikTokGoodsLm `json:"products"`
  111. } `json:"data"`
  112. }
  113. err = json.Unmarshal([]byte(send), &lmData)
  114. if err != nil {
  115. return goodsList
  116. }
  117. for _, v := range lmData.Data.Products {
  118. tmp := tik_tok.CommGoodsDetail(v)
  119. if tmp.GoodsID == args["product_ids"] {
  120. return tmp
  121. }
  122. }
  123. //
  124. return goodsList
  125. }
  126. //3.2.2 商品转链接口
  127. func GoodsLink(args map[string]string) (string, error) {
  128. params := map[string]interface{}{
  129. "product_url": args["product_url"],
  130. "product_ext": args["product_ext"],
  131. "external_info": args["external_info"],
  132. }
  133. if args["share_type"] != "" {
  134. ex := strings.Split(args["share_type"], ",")
  135. ids := make([]int, 0)
  136. for _, v := range ex {
  137. ids = append(ids, zhios_third_party_utils.StrToInt(v))
  138. }
  139. params["share_type"] = ids
  140. }
  141. send, err := Send(args["app_id"], args["app_secret"], "product/link", params)
  142. fmt.Println(send)
  143. fmt.Println(err)
  144. return send, err
  145. }