1
This commit is contained in:
@@ -440,9 +440,9 @@ func (a *API) GetProductAuditList(page, pageSize, status int64) ([]product_audit
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetRecommendCategory 根据图片预测商品类目,优先四级>三级>二级>1级
|
// GetRecommendCategory 根据图片预测商品类目,优先四级>三级>二级>1级
|
||||||
func (a *API) GetRecommendCategory(picParams []string) int64 {
|
func (a *API) GetRecommendCategory(picParams []string) (int64, error) {
|
||||||
if len(picParams) == 0 {
|
if len(picParams) == 0 {
|
||||||
return 0
|
return 0, errors.New("抖音根据图片预测分类,图片不能为空")
|
||||||
}
|
}
|
||||||
request := product_GetRecommendCategory_request.New()
|
request := product_GetRecommendCategory_request.New()
|
||||||
request.Param.Scene = "smart_publish" // 根据图片获取分类属性
|
request.Param.Scene = "smart_publish" // 根据图片获取分类属性
|
||||||
@@ -454,10 +454,14 @@ func (a *API) GetRecommendCategory(picParams []string) int64 {
|
|||||||
|
|
||||||
result, err := request.Execute(a.accessTokenObj)
|
result, err := request.Execute(a.accessTokenObj)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0
|
return 0, err
|
||||||
}
|
}
|
||||||
if result.Code != RequestSuccessCode {
|
if result.Code != RequestSuccessCode {
|
||||||
return 0
|
return 0, errors.New(result.SubMsg)
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(result.Data.CategoryDetails) == 0 {
|
||||||
|
return 0, errors.New("抖音根据图片获取分类,返回值为0")
|
||||||
}
|
}
|
||||||
|
|
||||||
var firstCid int64
|
var firstCid int64
|
||||||
@@ -465,33 +469,31 @@ func (a *API) GetRecommendCategory(picParams []string) int64 {
|
|||||||
var thirdCid int64
|
var thirdCid int64
|
||||||
var fourthCid int64
|
var fourthCid int64
|
||||||
|
|
||||||
for _, v := range result.Data.CategoryDetails {
|
if result.Data.CategoryDetails[0].CategoryDetail.FirstCid != 0 {
|
||||||
if v.CategoryDetail.FirstCid != 0 {
|
firstCid = result.Data.CategoryDetails[0].CategoryDetail.FirstCid
|
||||||
firstCid = v.CategoryDetail.FirstCid
|
}
|
||||||
}
|
if result.Data.CategoryDetails[0].CategoryDetail.SecondCid != 0 {
|
||||||
if v.CategoryDetail.SecondCid != 0 {
|
secondCid = result.Data.CategoryDetails[0].CategoryDetail.SecondCid
|
||||||
secondCid = v.CategoryDetail.SecondCid
|
}
|
||||||
}
|
if result.Data.CategoryDetails[0].CategoryDetail.ThirdCid != 0 {
|
||||||
if v.CategoryDetail.ThirdCid != 0 {
|
thirdCid = result.Data.CategoryDetails[0].CategoryDetail.ThirdCid
|
||||||
thirdCid = v.CategoryDetail.ThirdCid
|
}
|
||||||
}
|
if result.Data.CategoryDetails[0].CategoryDetail.FourthCid != 0 {
|
||||||
if v.CategoryDetail.FourthCid != 0 {
|
fourthCid = result.Data.CategoryDetails[0].CategoryDetail.FourthCid
|
||||||
fourthCid = v.CategoryDetail.FourthCid
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if fourthCid != 0 {
|
if fourthCid != 0 {
|
||||||
return fourthCid
|
return fourthCid, nil
|
||||||
}
|
}
|
||||||
if thirdCid != 0 {
|
if thirdCid != 0 {
|
||||||
return thirdCid
|
return thirdCid, nil
|
||||||
}
|
}
|
||||||
if secondCid != 0 {
|
if secondCid != 0 {
|
||||||
return secondCid
|
return secondCid, nil
|
||||||
}
|
}
|
||||||
if firstCid != 0 {
|
if firstCid != 0 {
|
||||||
return firstCid
|
return firstCid, nil
|
||||||
}
|
}
|
||||||
return 0
|
return 0, errors.New("抖音获取推荐分类异常")
|
||||||
}
|
}
|
||||||
|
|
||||||
/*--------------------------------方案二 将住上铺平铺到所有门店店中,不在使用子商品------------------------------------------------------------------------------------*/
|
/*--------------------------------方案二 将住上铺平铺到所有门店店中,不在使用子商品------------------------------------------------------------------------------------*/
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
package tiktok_api
|
package tiktok_api
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/baseapi"
|
"git.rosy.net.cn/baseapi"
|
||||||
product_addV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_addV2/request"
|
|
||||||
product_editV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_editV2/request"
|
product_editV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_editV2/request"
|
||||||
product_editV2_commit_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_editV2_commit/request"
|
product_editV2_commit_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_editV2_commit/request"
|
||||||
product_listV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_listV2/request"
|
product_listV2_request "git.rosy.net.cn/baseapi/platformapi/tiktok_shop/sdk-golang/api/product_listV2/request"
|
||||||
@@ -44,180 +42,6 @@ func TestGetCatePropertyV2(t *testing.T) {
|
|||||||
fmt.Println("data====", data) // 202209281558450102081001701D7B32C5
|
fmt.Println("data====", data) // 202209281558450102081001701D7B32C5
|
||||||
}
|
}
|
||||||
|
|
||||||
// 新增总部商品
|
|
||||||
func TestCreateStoreCommodity(t *testing.T) {
|
|
||||||
param := &product_addV2_request.ProductAddV2Param{
|
|
||||||
//ProductType: 0,
|
|
||||||
CategoryLeafId: 29146,
|
|
||||||
ProductFormat: "",
|
|
||||||
Name: "精华补水液-1",
|
|
||||||
RecommendRemark: "商家推荐话术-1",
|
|
||||||
Pic: "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/mXJgSMMc_m_b3dbe91196472e0f4bb05e779a21bf81_sx_112313_www800-800|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/mXJgSMMc_m_8433e90bec56f791d4bfa4d47ee1e12c_sx_206128_www800-800", //轮播图,第一张为主图
|
|
||||||
Description: "https://p3-aio.ecombdimg.com/obj/ecom-shop-material/mXJgSMMc_m_b3dbe91196472e0f4bb05e779a21bf81_sx_112313_www800-800|https://p3-aio.ecombdimg.com/obj/ecom-shop-material/mXJgSMMc_m_8433e90bec56f791d4bfa4d47ee1e12c_sx_206128_www800-800", //商品描述图
|
|
||||||
//PayType: 0,
|
|
||||||
//DeliveryMethod: 0,
|
|
||||||
//CdfCategory: "",
|
|
||||||
ReduceType: SkuReduceTypePayMakeOrder, //1 减库存类型:1-拍下减库存 2-付款减库存
|
|
||||||
//AssocIds: "",
|
|
||||||
FreightId: 11111, // 运费模板id
|
|
||||||
//Weight: 0,
|
|
||||||
//WeightUnit: 0,
|
|
||||||
DeliveryDelayDay: DeliveryDelayDayTomorrow, // 现货发货(presell_type=0)和阶梯发货模式(presell_type=2)时必填
|
|
||||||
PresellType: 1, // 0现发货/1预售发货/2阶梯发货
|
|
||||||
PresellConfigLevel: 1, // 0现发货/1预售发货/2阶梯发货
|
|
||||||
//PresellDelay: 0,
|
|
||||||
//PresellEndTime: "",
|
|
||||||
//Supply7dayReturn: 0,
|
|
||||||
Mobile: "18981810340",
|
|
||||||
Commit: false,
|
|
||||||
//BrandId: 0,
|
|
||||||
Remark: "商家备注",
|
|
||||||
//OutProductId: 0,
|
|
||||||
//QualityList: nil,
|
|
||||||
//SpecName: "",
|
|
||||||
Specs: "颜色|红色,黑色",
|
|
||||||
//SpecPrices: "",
|
|
||||||
//SpecPic: "",
|
|
||||||
//MaximumPerOrder: 0,
|
|
||||||
//LimitPerBuyer: 0,
|
|
||||||
//MinimumPerOrder: 0,
|
|
||||||
//ProductFormatNew: "29146",
|
|
||||||
//SpuId: 0,
|
|
||||||
//AppointDeliveryDay: 0,
|
|
||||||
//ThirdUrl: "",
|
|
||||||
//Extra: "",
|
|
||||||
//Src: "",
|
|
||||||
//StandardBrandId: 0,
|
|
||||||
//NeedCheckOut: false,
|
|
||||||
//PoiResource: nil,
|
|
||||||
//CarVinCode: "",
|
|
||||||
//PresellConfigLevel: 0,
|
|
||||||
//NeedRechargeMode: false,
|
|
||||||
//AccountTemplateId: "",
|
|
||||||
//PresellDeliveryType: 0,
|
|
||||||
//WhiteBackGroundPicUrl: "",
|
|
||||||
//LongPicUrl: "",
|
|
||||||
//AfterSaleService: nil,
|
|
||||||
//SellChannel: nil,
|
|
||||||
StartSaleType: 0, // 立即上架
|
|
||||||
//DelayRule: nil,
|
|
||||||
//MaterialVideoId: "",
|
|
||||||
PickupMethod: "0",
|
|
||||||
//SizeInfoTemplateId: 0,
|
|
||||||
//SubstituteGoodsUrl: "",
|
|
||||||
//SaleChannelType: "",
|
|
||||||
//RecruitInfo: nil,
|
|
||||||
//StoreId: 0,
|
|
||||||
//MainProductId: 0,
|
|
||||||
//SaleLimitId: 0,
|
|
||||||
//NamePrefix: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取属性
|
|
||||||
category, err := a.GetCatePropertyV2(param.CategoryLeafId)
|
|
||||||
format := make(map[string][]*ProductFormatNewList, 0)
|
|
||||||
for _, v := range category.Data.Data {
|
|
||||||
if v.Required != 1 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
for _, d := range v.Options {
|
|
||||||
formateNew := &ProductFormatNewList{
|
|
||||||
Value: utils.Str2Int64(d.Value),
|
|
||||||
Name: d.Name,
|
|
||||||
DiyType: v.DiyType,
|
|
||||||
}
|
|
||||||
format[utils.Int64ToStr(v.PropertyId)] = append(format[utils.Int64ToStr(v.PropertyId)], formateNew)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
productFormatNew, err := json.Marshal(format)
|
|
||||||
param.ProductFormatNew = string(productFormatNew)
|
|
||||||
|
|
||||||
skuSize := make([]*SpecDetailList, 0, 0)
|
|
||||||
skuDetail := param.Specs
|
|
||||||
detail1 := strings.Split(skuDetail, "^")
|
|
||||||
if len(detail1) > 3 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
switch len(detail1) {
|
|
||||||
case 1:
|
|
||||||
name1 := strings.Split(strings.Split(detail1[0], "|")[1], ",")
|
|
||||||
for i := 0; i < len(name1); i++ {
|
|
||||||
sku := &SpecDetailList{
|
|
||||||
SpecDetailName1: name1[i],
|
|
||||||
StockNum: 750,
|
|
||||||
Price: 100,
|
|
||||||
Code: "19930826",
|
|
||||||
StepStockNum: 0,
|
|
||||||
SupplierID: "jxcs1993",
|
|
||||||
OuterSkuID: "1997338" + utils.Int2Str(i),
|
|
||||||
DeliveryInfos: []*DeliveryInfos{
|
|
||||||
{InfoType: "weight", InfoUnit: "kg", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "g", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "mg", InfoValue: "250"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
skuSize = append(skuSize, sku)
|
|
||||||
}
|
|
||||||
case 2:
|
|
||||||
name1 := strings.Split(strings.Split(detail1[0], "|")[1], ",")
|
|
||||||
name2 := strings.Split(strings.Split(detail1[1], "|")[1], ",")
|
|
||||||
for i := 0; i < len(name1); i++ {
|
|
||||||
for j := 0; j < len(name2); j++ {
|
|
||||||
sku := &SpecDetailList{
|
|
||||||
SpecDetailName1: name1[i],
|
|
||||||
SpecDetailName2: name2[j],
|
|
||||||
StockNum: 750,
|
|
||||||
Price: 100,
|
|
||||||
Code: "19930826",
|
|
||||||
StepStockNum: 0,
|
|
||||||
SupplierID: "jxcs1993",
|
|
||||||
OuterSkuID: "1997338",
|
|
||||||
DeliveryInfos: []*DeliveryInfos{
|
|
||||||
{InfoType: "weight", InfoUnit: "kg", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "g", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "mg", InfoValue: "250"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
skuSize = append(skuSize, sku)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
case 3:
|
|
||||||
name1 := strings.Split(strings.Split(detail1[0], "|")[1], ",")
|
|
||||||
name2 := strings.Split(strings.Split(detail1[1], "|")[1], ",")
|
|
||||||
name3 := strings.Split(strings.Split(detail1[2], "|")[1], ",")
|
|
||||||
for i := 0; i < len(name1); i++ {
|
|
||||||
for j := 0; j < len(name2); j++ {
|
|
||||||
for k := 0; k < len(name3); k++ {
|
|
||||||
sku := &SpecDetailList{
|
|
||||||
SpecDetailName1: name1[i],
|
|
||||||
SpecDetailName2: name2[j],
|
|
||||||
SpecDetailName3: name3[k],
|
|
||||||
StockNum: 750,
|
|
||||||
Price: 100,
|
|
||||||
Code: "19930826",
|
|
||||||
StepStockNum: 0,
|
|
||||||
SupplierID: "jxcs1993",
|
|
||||||
OuterSkuID: "1997338",
|
|
||||||
DeliveryInfos: []*DeliveryInfos{
|
|
||||||
{InfoType: "weight", InfoUnit: "kg", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "g", InfoValue: "250"},
|
|
||||||
{InfoType: "weight", InfoUnit: "mg", InfoValue: "250"},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
skuSize = append(skuSize, sku)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
specPricesString, _ := json.Marshal(skuSize)
|
|
||||||
param.SpecPrices = string(specPricesString)
|
|
||||||
data, err := a.CreateStoreCommodity(param)
|
|
||||||
fmt.Println("err=============", err)
|
|
||||||
fmt.Println("data===", fmt.Sprintf("%v", data))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInt16(t *testing.T) {
|
func TestInt16(t *testing.T) {
|
||||||
fmt.Println(utils.Str2Int16(strings.ReplaceAll("08:00", ":", "")))
|
fmt.Println(utils.Str2Int16(strings.ReplaceAll("08:00", ":", "")))
|
||||||
}
|
}
|
||||||
@@ -420,6 +244,33 @@ func TestGetProductAuditList(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func Test111(t *testing.T) {
|
func TestCreateShopData(t *testing.T) {
|
||||||
fmt.Println(time.Now().Sub(time.Now().Add(time.Minute * 120)))
|
imgs := make([]Imgs, 0, 0)
|
||||||
|
img := []string{"http://image.jxc4.com/image/2506b07009977017f4a412557584957b.jpg"}
|
||||||
|
for _, v := range img {
|
||||||
|
if v != "" {
|
||||||
|
imgs = append(imgs, Imgs{
|
||||||
|
Name: "111" + "_" + v[21:54],
|
||||||
|
Url: v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
tiktokImgList, err := a.BatchUploadImages(imgs)
|
||||||
|
globals.SugarLogger.Debugf("========err %s", utils.Format4Output(err, false))
|
||||||
|
|
||||||
|
detailTiktok := ""
|
||||||
|
var tiktokImg []string
|
||||||
|
for _, v := range tiktokImgList {
|
||||||
|
if strings.Contains(v.Name, "detail_") {
|
||||||
|
detailTiktok = v.ByteUrl
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tiktokImg = append(tiktokImg, v.ByteUrl)
|
||||||
|
}
|
||||||
|
if detailTiktok == "" {
|
||||||
|
detailTiktok = tiktokImg[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
a.GetRecommendCategory(tiktokImg)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user