|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- package tik_tok
-
- import (
- zhios_third_party_utils "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/utils"
- "encoding/json"
- "fmt"
- "github.com/tidwall/gjson"
- "strings"
- )
-
- //商品类目
- func CsjpGoodsCate(args map[string]string) (string, error) {
- params := map[string]interface{}{"parent_id": zhios_third_party_utils.StrToInt(args["parent_id"])}
- send, err := CsjpSend(args["app_id"], args["app_secret"], "product/category", params)
- fmt.Println(send)
- fmt.Println(err)
- return send, err
- }
-
- //3.2.1 商品列表接口
- func CsjpGoodsList(args map[string]string) []TikTokGoods {
- params := map[string]interface{}{
- "page": zhios_third_party_utils.StrToInt(args["page"]),
- "page_size": zhios_third_party_utils.StrToInt(args["page_size"]),
- }
- if args["title"] != "" {
- params["title"] = args["title"]
- }
- if args["first_cids"] != "" {
- ex := strings.Split(args["first_cids"], ",")
- ids := make([]int, 0)
- for _, v := range ex {
- ids = append(ids, zhios_third_party_utils.StrToInt(v))
- }
- params["first_cids"] = ids
- }
- if args["price_min"] != "" {
- params["price_min"] = int(zhios_third_party_utils.StrToFloat64(args["price_min"]) * 100)
- }
- if args["price_max"] != "" {
- params["price_max"] = int(zhios_third_party_utils.StrToFloat64(args["price_max"]) * 100)
- }
- if args["sell_num_min"] != "" {
- params["sell_num_min"] = zhios_third_party_utils.StrToInt(args["sell_num_min"])
- }
- if args["sell_num_max"] != "" {
- params["sell_num_max"] = zhios_third_party_utils.StrToInt(args["sell_num_max"])
- }
- if args["search_type"] != "" {
- params["search_type"] = zhios_third_party_utils.StrToInt(args["search_type"])
- }
- if args["order_type"] != "" {
- params["order_type"] = zhios_third_party_utils.StrToInt(args["order_type"])
- }
-
- if args["cos_fee_min"] != "" {
- params["cos_fee_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_min"]) * 100)
- }
- if args["cos_fee_max"] != "" {
- params["cos_fee_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_fee_max"]) * 100)
- }
- if args["cos_ratio_min"] != "" {
- params["cos_ratio_min"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_min"]) * 100)
- }
- if args["cos_ratio_max"] != "" {
- params["cos_ratio_max"] = int(zhios_third_party_utils.StrToFloat64(args["cos_ratio_max"]) * 100)
- }
- if args["activity_id"] != "" {
- params["activity_id"] = zhios_third_party_utils.StrToInt(args["activity_id"])
- }
- send, err := CsjpSend(args["app_id"], args["app_secret"], "product/search", params)
- fmt.Println(send)
- var goodsList = make([]TikTokGoods, 0)
- product := gjson.Get(send, "data.products").String()
- if err != nil || product == "" {
- return goodsList
- }
- var lmData struct {
- Data struct {
- Products []TikTokGoodsLm `json:"products"`
- } `json:"data"`
- }
- err = json.Unmarshal([]byte(send), &lmData)
- if err != nil {
- fmt.Println("抖音商品1", err)
-
- return goodsList
- }
- for _, v := range lmData.Data.Products {
- v.CosRatio = v.CosRatio / 100
- tmp := CommGoodsDetail(v)
- goodsList = append(goodsList, tmp)
- }
- return goodsList
- }
-
- //商品详情接口
- func CsjpGoodsDetail(args map[string]string) TikTokGoods {
-
- params := map[string]interface{}{}
- if args["product_ids"] != "" {
- ex := strings.Split(args["product_ids"], ",")
- ids := make([]int, 0)
- for _, v := range ex {
- ids = append(ids, zhios_third_party_utils.StrToInt(v))
- }
- params["product_ids"] = ids
- }
- send, err := CsjpSend(args["app_id"], args["app_secret"], "product/detail", params)
- var goodsList = TikTokGoods{}
- product := gjson.Get(send, "data.products").String()
- if err != nil || product == "" {
- return goodsList
- }
- var lmData struct {
- Data struct {
- Products []TikTokGoodsLm `json:"products"`
- } `json:"data"`
- }
- err = json.Unmarshal([]byte(send), &lmData)
- if err != nil {
- return goodsList
- }
- for _, v := range lmData.Data.Products {
- v.CosRatio = v.CosRatio / 100
- tmp := CommGoodsDetail(v)
- if tmp.GoodsID == args["product_ids"] {
- return tmp
- }
- }
- //
- return goodsList
- }
-
- //3.2.2 商品转链接口
- func CsjpGoodsLink(args map[string]string) (string, error) {
- params := map[string]interface{}{
- "product_url": args["product_url"],
- "product_ext": args["product_ext"],
- "external_info": args["external_info"],
- }
- if args["share_type"] != "" {
- ex := strings.Split(args["share_type"], ",")
- ids := make([]int, 0)
- for _, v := range ex {
- ids = append(ids, zhios_third_party_utils.StrToInt(v))
- }
- params["share_type"] = ids
- }
- send, err := CsjpSend(args["app_id"], args["app_secret"], "product/link", params)
- fmt.Println(send)
- fmt.Println(err)
- return send, err
- }
|