From b53c2bea1bd60438717f22900500ef12523c0248 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Thu, 22 Dec 2022 19:30:46 +0800 Subject: [PATCH 1/3] 1 --- platformapi/jdapi/jdapi_test.go | 4 ++-- platformapi/jdapi/order_test.go | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index 3dc1bb38..d34fb507 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -25,13 +25,13 @@ func init() { // sandbox // api = New("594ab45a-9a73-4a43-82b0-a64cbd55d883", "06692746f7224695ad4788ce340bc854", "d6b42a35a7414a5490d811654d745c84") // prod - //api = New("73e2e9f6-b21e-4dcd-8c92-71e4e100b07e", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") + api = New("73e2e9f6-b21e-4dcd-8c92-71e4e100b07e", "1dba76d40cac446ca500c0391a0b6c9d", "a88d031a1e7b462cb1579f12e97fe7f4") // 天天果园 //api = New("c45e6510-00ba-4be2-977e-bcb9c9792cc7", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") // 京东果园 //api = New("b1138139-9610-4b80-9a63-a63da4773885", "5d5577a2506f41b8b4ec520ba83490f5", "0b01b9eeb15b41dab1c3d05d95c17a26") // 果切 - api = New("0e12f461-2e6b-49ca-bce6-935c6672362d", "f2ed33075faf4773a47e065acd79532b", "aed14cbbecac4456843570e90c5f46ec") + //api = New("0e12f461-2e6b-49ca-bce6-935c6672362d", "f2ed33075faf4773a47e065acd79532b", "aed14cbbecac4456843570e90c5f46ec") //prod zs // api = New("6f8d3290-0120-4ad7-8b53-943c67c84f3f", "789279b9ae814ba091ac52815566b54d", "5d668cd227644637bb0fd73ed8118ec8") diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index fe76fb47..a03e55a0 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -109,7 +109,7 @@ func TestGetAfsService2(t *testing.T) { } func TestOrderShoudSettlementService2(t *testing.T) { - result, err := api.OrderShoudSettlementService2("2226231085000191") + result, err := api.OrderShoudSettlementService2("2230697160000272") if err != nil { t.Fatal(err.Error()) } From 9b5fb4abf146e731e54b85b8dbbe3d8e98ca9bfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 23 Dec 2022 15:00:00 +0800 Subject: [PATCH 2/3] 1 --- platformapi/jdapi/order_test.go | 2 +- platformapi/tiktok_shop/tiktok_api/afs_test.go | 17 ++++++----------- platformapi/tiktok_shop/tiktok_api/sku_type.go | 10 +++++++--- .../tiktok_shop/tiktok_api/sku_warehouse.go | 9 ++++++--- .../tiktok_api/sku_warehouse_test.go | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/platformapi/jdapi/order_test.go b/platformapi/jdapi/order_test.go index a03e55a0..6802b5be 100644 --- a/platformapi/jdapi/order_test.go +++ b/platformapi/jdapi/order_test.go @@ -109,7 +109,7 @@ func TestGetAfsService2(t *testing.T) { } func TestOrderShoudSettlementService2(t *testing.T) { - result, err := api.OrderShoudSettlementService2("2230697160000272") + result, err := api.OrderShoudSettlementService2("2230776748000074") if err != nil { t.Fatal(err.Error()) } diff --git a/platformapi/tiktok_shop/tiktok_api/afs_test.go b/platformapi/tiktok_shop/tiktok_api/afs_test.go index 573d159c..93b6fde9 100644 --- a/platformapi/tiktok_shop/tiktok_api/afs_test.go +++ b/platformapi/tiktok_shop/tiktok_api/afs_test.go @@ -8,18 +8,13 @@ import ( "testing" ) -//var token = `{ -// "access_token": "b668f8cc-d875-4887-a613-5452f05e752e", -// "expires_in": 1671432212, -// "scope": "SCOPE", -// "shop_id": 63141688, -// "shop_name": "小时达开放平台专用店", -// "refresh_token": "fa64fedf-05a7-4c1b-b6c4-f97f90e10b75", -// "authority_id": "" -//}` - +// 菜市账号 //var token = `{"access_token":"e8b6c1bc-2477-40ff-bd8e-faf547669d77","expires_in":1671431173,"scope":"SCOPE","shop_id":57939570,"shop_name":"京西菜市速食","refresh_token":"3cd84170-73a0-485c-b55a-74e128618693","authority_id":""}` -var token = `{"access_token":"83e52462-ad46-4297-98c4-242ee6b7a5c8","expires_in":1672033612,"scope":"SCOPE","shop_id":63141688,"shop_name":"二期-抖音超市小时达测试店铺","refresh_token":"8f690bc3-3f3e-49bd-bbf7-31c9e868e980","authority_id":""}` +//var token = `{"access_token":"83e52462-ad46-4297-98c4-242ee6b7a5c8","expires_in":1672033612,"scope":"SCOPE","shop_id":63141688,"shop_name":"二期-抖音超市小时达测试店铺","refresh_token":"8f690bc3-3f3e-49bd-bbf7-31c9e868e980","authority_id":""}` +//var a = New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token) + +// 超市账号 +var token = `{"access_token":"99961136-7f45-4da1-9b4a-28cdbe90132b","expires_in":1672280107,"scope":"SCOPE","shop_id":68023619,"shop_name":"京西到家","refresh_token":"61551caf-925e-4654-9408-c76ef7520392","authority_id":""}` var a = New("7136048270014416392", "c397aa9f-3927-47c4-8cfe-4d84e02602e0", token) // 查询售后单详情 diff --git a/platformapi/tiktok_shop/tiktok_api/sku_type.go b/platformapi/tiktok_shop/tiktok_api/sku_type.go index 83e7861e..9a71ee66 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_type.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_type.go @@ -7,9 +7,13 @@ type Imgs struct { // 抖店文件夹id写死两个 const ( - TiktokFolder1 = "71580417560930552391570" // 文件夹(京西菜市) - TiktokFolder2 = "71482723234545339291960" - TiktokFolder3 = "71762017122139835211688" // (方案二测试文件夹) + TiktokFolder1 = "71580417560930552391570" // 文件夹(京西菜市) + TiktokFolder2 = "71482723234545339291960" + TiktokFolder3 = "71762017122139835211688" // (方案二测试文件夹) + TiktokShoppingFolder = "71802347591117703711619" // (方案二测试文件夹) + TiktokFloderKeyVegetableKey = 57939570 // (菜市的文件夹id) + TiktokFloderKeyShoppingKey = 68023619 // (商超账号的文件夹id) + TiktokFloderKeyTestKey = 63141688 // (测试账号) ) // 商品减库存类型 diff --git a/platformapi/tiktok_shop/tiktok_api/sku_warehouse.go b/platformapi/tiktok_shop/tiktok_api/sku_warehouse.go index 8abd9b41..0df2b753 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_warehouse.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_warehouse.go @@ -44,14 +44,17 @@ func (a *API) BatchUploadImages(imgs []Imgs) (map[string]material_batchUploadIma for i := 0; i < len(imgs); i++ { img := material_batchUploadImageSync_request.MaterialsItem{ RequestId: imgs[i].Name, - FolderId: TiktokFolder1, // 默认存储 MaterialType: "photo", Name: imgs[i].Name, Url: imgs[i].Url, } - // 测试文件夹 - if a.accessTokenObj.ShopId == 63141688 { + switch a.accessTokenObj.ShopId { + case TiktokFloderKeyTestKey: img.FolderId = TiktokFolder3 + case TiktokFloderKeyShoppingKey: + img.FolderId = TiktokShoppingFolder + case TiktokFloderKeyVegetableKey: + img.FolderId = TiktokFolder1 } param = append(param, img) } diff --git a/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go b/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go index 28fdbc5c..ad63aa51 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_warehouse_test.go @@ -24,7 +24,7 @@ func init() { } func TestCreateFolad(t *testing.T) { - data, err := a.CreateFolder("shop_63141688") + data, err := a.CreateFolder("shopping_folder") fmt.Println("err=====", err) fmt.Println("LogId====", data.LogId) //2022092811422001020812109607601B77 fmt.Println("data====", data.Data.Name) // jxcs_folder From 062002f5da919605a77dd1396b6b75d2d20bf988 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Fri, 23 Dec 2022 16:12:10 +0800 Subject: [PATCH 3/3] 1 --- platformapi/tiktok_shop/tiktok_api/sku.go | 46 ++-- .../tiktok_shop/tiktok_api/sku_test.go | 207 +++--------------- 2 files changed, 53 insertions(+), 200 deletions(-) diff --git a/platformapi/tiktok_shop/tiktok_api/sku.go b/platformapi/tiktok_shop/tiktok_api/sku.go index 59854de5..72d5405b 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku.go +++ b/platformapi/tiktok_shop/tiktok_api/sku.go @@ -440,9 +440,9 @@ func (a *API) GetProductAuditList(page, pageSize, status int64) ([]product_audit } // GetRecommendCategory 根据图片预测商品类目,优先四级>三级>二级>1级 -func (a *API) GetRecommendCategory(picParams []string) int64 { +func (a *API) GetRecommendCategory(picParams []string) (int64, error) { if len(picParams) == 0 { - return 0 + return 0, errors.New("抖音根据图片预测分类,图片不能为空") } request := product_GetRecommendCategory_request.New() request.Param.Scene = "smart_publish" // 根据图片获取分类属性 @@ -454,10 +454,14 @@ func (a *API) GetRecommendCategory(picParams []string) int64 { result, err := request.Execute(a.accessTokenObj) if err != nil { - return 0 + return 0, err } 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 @@ -465,33 +469,31 @@ func (a *API) GetRecommendCategory(picParams []string) int64 { var thirdCid int64 var fourthCid int64 - for _, v := range result.Data.CategoryDetails { - if v.CategoryDetail.FirstCid != 0 { - firstCid = v.CategoryDetail.FirstCid - } - if v.CategoryDetail.SecondCid != 0 { - secondCid = v.CategoryDetail.SecondCid - } - if v.CategoryDetail.ThirdCid != 0 { - thirdCid = v.CategoryDetail.ThirdCid - } - if v.CategoryDetail.FourthCid != 0 { - fourthCid = v.CategoryDetail.FourthCid - } + if result.Data.CategoryDetails[0].CategoryDetail.FirstCid != 0 { + firstCid = result.Data.CategoryDetails[0].CategoryDetail.FirstCid + } + if result.Data.CategoryDetails[0].CategoryDetail.SecondCid != 0 { + secondCid = result.Data.CategoryDetails[0].CategoryDetail.SecondCid + } + if result.Data.CategoryDetails[0].CategoryDetail.ThirdCid != 0 { + thirdCid = result.Data.CategoryDetails[0].CategoryDetail.ThirdCid + } + if result.Data.CategoryDetails[0].CategoryDetail.FourthCid != 0 { + fourthCid = result.Data.CategoryDetails[0].CategoryDetail.FourthCid } if fourthCid != 0 { - return fourthCid + return fourthCid, nil } if thirdCid != 0 { - return thirdCid + return thirdCid, nil } if secondCid != 0 { - return secondCid + return secondCid, nil } if firstCid != 0 { - return firstCid + return firstCid, nil } - return 0 + return 0, errors.New("抖音获取推荐分类异常") } /*--------------------------------方案二 将住上铺平铺到所有门店店中,不在使用子商品------------------------------------------------------------------------------------*/ diff --git a/platformapi/tiktok_shop/tiktok_api/sku_test.go b/platformapi/tiktok_shop/tiktok_api/sku_test.go index 4a235aaa..c756af7a 100644 --- a/platformapi/tiktok_shop/tiktok_api/sku_test.go +++ b/platformapi/tiktok_shop/tiktok_api/sku_test.go @@ -1,10 +1,8 @@ package tiktok_api import ( - "encoding/json" "fmt" "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_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" @@ -44,180 +42,6 @@ func TestGetCatePropertyV2(t *testing.T) { 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) { fmt.Println(utils.Str2Int16(strings.ReplaceAll("08:00", ":", ""))) } @@ -420,6 +244,33 @@ func TestGetProductAuditList(t *testing.T) { } } -func Test111(t *testing.T) { - fmt.Println(time.Now().Sub(time.Now().Add(time.Minute * 120))) +func TestCreateShopData(t *testing.T) { + 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) }