package csjplatform import ( "code.fnuoos.com/go_rely_warehouse/zyos_go_third_party_api.git/tik_tok" 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 GoodsCate(args map[string]string) (string, error) { params := map[string]interface{}{"parent_id": zhios_third_party_utils.StrToInt(args["parent_id"])} send, err := Send(args["app_id"], args["app_secret"], "product/category", params) fmt.Println(send) fmt.Println(err) return send, err } //3.2.1 商品列表接口 func GoodsList(args map[string]string) []tik_tok.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 := Send(args["app_id"], args["app_secret"], "product/search", params) fmt.Println(send) var goodsList = make([]tik_tok.TikTokGoods, 0) product := gjson.Get(send, "data.products").String() if err != nil || product == "" { return goodsList } var lmData struct { Data struct { Products []tik_tok.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 := tik_tok.CommGoodsDetail(v) goodsList = append(goodsList, tmp) } return goodsList } //商品详情接口 func GoodsDetail(args map[string]string) tik_tok.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 := Send(args["app_id"], args["app_secret"], "product/detail", params) var goodsList = tik_tok.TikTokGoods{} product := gjson.Get(send, "data.products").String() if err != nil || product == "" { return goodsList } var lmData struct { Data struct { Products []tik_tok.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 := tik_tok.CommGoodsDetail(v) if tmp.GoodsID == args["product_ids"] { return tmp } } // return goodsList } //3.2.2 商品转链接口 func GoodsLink(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 := Send(args["app_id"], args["app_secret"], "product/link", params) fmt.Println(send) fmt.Println(err) return send, err }