This commit is contained in:
richboo111
2022-12-23 17:54:20 +08:00
7 changed files with 70 additions and 210 deletions

View File

@@ -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")

View File

@@ -109,7 +109,7 @@ func TestGetAfsService2(t *testing.T) {
}
func TestOrderShoudSettlementService2(t *testing.T) {
result, err := api.OrderShoudSettlementService2("2226231085000191")
result, err := api.OrderShoudSettlementService2("2230776748000074")
if err != nil {
t.Fatal(err.Error())
}

View File

@@ -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("抖音获取推荐分类异常")
}
/*--------------------------------方案二 将住上铺平铺到所有门店店中,不在使用子商品------------------------------------------------------------------------------------*/

View File

@@ -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)
}

View File

@@ -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 // (测试账号)
)
// 商品减库存类型

View File

@@ -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)
}

View File

@@ -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