1
This commit is contained in:
@@ -304,26 +304,27 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
param.Name = checkNameLenght(param.Name)
|
||||
|
||||
// 获取上传图,商品轮播图
|
||||
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
||||
// 暂时只考虑修改白底图,提高效率.其余图片不做修改
|
||||
img, descImg, whiteImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeSku.SkuID, storeSku.DescImg, storeSku.Img, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
param.Pic = img
|
||||
param.Description = detailImg
|
||||
param.Description = descImg
|
||||
param.WhiteBackGroundPicUrl = whiteImg
|
||||
param.WeightUnit = tiktokShop.WeightUint_G
|
||||
|
||||
// 部分商品没有所属的分类,直接跳过!
|
||||
if storeSku.SkuVendorMapCatID != "" {
|
||||
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
|
||||
} else if len(param.Pic) != 0 { // 自动推导分类id
|
||||
param.CategoryLeafId, err = api.GetRecommendCategory(strings.Split(img, "|"))
|
||||
if param.CategoryLeafId == 0 || err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("当前商品本地未设置抖音分类/抖音推荐分类查询错误:"+err.Error()), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
}
|
||||
//if storeSku.SkuVendorMapCatID != "" {
|
||||
// param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
|
||||
//} else if len(param.Pic) != 0 { // 自动推导分类id
|
||||
// param.CategoryLeafId, err = api.GetRecommendCategory(strings.Split(img, "|"))
|
||||
// if param.CategoryLeafId == 0 || err != nil {
|
||||
// failedList = putils.GetErrMsg2FailedSingleList(storeSku, errors.New("当前商品本地未设置抖音分类/抖音推荐分类查询错误:"+err.Error()), storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
// continue
|
||||
// }
|
||||
//}
|
||||
|
||||
// 获取主商品id
|
||||
var mainIdInt int64
|
||||
@@ -341,36 +342,17 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
}
|
||||
|
||||
// 更新商品,主品如果名字和类目没变化,则更新子品价格!
|
||||
mainProductDetail, err := api.GetSkuDetail(utils.Int64ToStr(mainIdInt), "")
|
||||
if err != nil || mainProductDetail == nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
continue
|
||||
}
|
||||
if mainProductDetail.Name == param.Name && (mainProductDetail.CategoryDetail.ThirdCid == param.CategoryLeafId || mainProductDetail.CategoryDetail.FourthCid == param.CategoryLeafId) {
|
||||
// 更新子品,同步方法会更新子品的同时去更新库存和价格!删除之后接下的同步步骤失效!
|
||||
//if err := api.DeleteStoreCommodity(utils.Str2Int64(storeSku.VendorSkuID)); err != nil {
|
||||
// failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
// storeSku.SkuSyncStatus = model.SyncFlagStoreSkuModifiedMask
|
||||
// continue
|
||||
//}
|
||||
//childrenProductId, err := api.CreateSubProduct(mainIdInt, utils.Str2Int64(vendorStoreID))
|
||||
//if err != nil {
|
||||
// failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
// storeSku.SkuSyncStatus = model.SyncFlagStoreSkuModifiedMask
|
||||
// continue
|
||||
//}
|
||||
//if (err != nil || childrenProductId == 0) && !strings.Contains(err.Error(), "2010001") { // 2010001:重复创建渠道商品,就去更新
|
||||
// continue
|
||||
//}
|
||||
//
|
||||
//// 同步价格,库存,上架
|
||||
//storeSku.VendorSonSkuID = utils.Int64ToStr(childrenProductId) // (属性id skuID方案一)(自商品的商品id方案二)
|
||||
//storeSku.VendorSkuID = utils.Int64ToStr(childrenProductId) // 子商品主id
|
||||
failedList2 := upDateChildrenPriceStockLaunch(api, storeSku, utils.Str2Int64(storeSku.VendorSkuID), vendorStoreID, syncType)
|
||||
failedList = append(failedList, failedList2...)
|
||||
|
||||
continue
|
||||
}
|
||||
//mainProductDetail, err := api.GetSkuDetail(utils.Int64ToStr(mainIdInt), "")
|
||||
//if err != nil || mainProductDetail == nil {
|
||||
// failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
// continue
|
||||
//}
|
||||
//if mainProductDetail.Name == param.Name && (mainProductDetail.CategoryDetail.ThirdCid == param.CategoryLeafId || mainProductDetail.CategoryDetail.FourthCid == param.CategoryLeafId) {
|
||||
// // 更新子品,同步方法会更新子品的同时去更新库存和价格!删除之后接下的同步步骤失效!
|
||||
// failedList2 := upDateChildrenPriceStockLaunch(api, storeSku, utils.Str2Int64(storeSku.VendorSkuID), vendorStoreID, syncType)
|
||||
// failedList = append(failedList, failedList2...)
|
||||
// continue
|
||||
//}
|
||||
|
||||
// 获取商品的属性
|
||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" || storeSku.UpcTiktokBrandId == "" {
|
||||
@@ -397,6 +379,9 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
if err := api.EditStoreCommodity(param); err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)
|
||||
} else {
|
||||
// todo 暂时关闭之后解开
|
||||
//upDateChildrenPriceStockLaunch(api, storeSku, utils.Str2Int64(storeSku.VendorSkuID), vendorStoreID, syncType)
|
||||
}
|
||||
|
||||
storeSku.SkuSyncStatus = model.SyncFlagStoreSkuModifiedMask // 品库修改 售卖状态待同步 价格待同步
|
||||
@@ -427,13 +412,14 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS
|
||||
param.Name = checkNameLenght(param.Name)
|
||||
|
||||
// 获取上传图,商品轮播图
|
||||
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
||||
img, detailImg, whiteImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeSku.SkuID, storeSku.DescImg, storeSku.Img, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
||||
if err != nil {
|
||||
failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType)
|
||||
return
|
||||
}
|
||||
param.Pic = img
|
||||
param.Description = detailImg
|
||||
param.WhiteBackGroundPicUrl = whiteImg
|
||||
|
||||
// 部分商品没有所属的分类,直接跳过!
|
||||
if storeSku.SkuVendorMapCatID != "" {
|
||||
@@ -882,8 +868,35 @@ func GetProductFormatNew(categoryLeftId int64, vendorOrgCode string) (*product_g
|
||||
//return string(productFormatNew), nil
|
||||
}
|
||||
|
||||
// GetTiktokImgList 获取抖音图片链接
|
||||
func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg string, img ...string) (string, string, error) {
|
||||
// GetTiktokImgList 获取抖音图片链接 whiteImg 白底图,有的商品可能没有白底图随便用一张(创建商品专用,更新商品只考虑更新白底图,不然太慢了)
|
||||
func GetTiktokImgList(api *tiktokShop.API, storeId string, skuId int, detailImg, whiteImg string, img ...string) (string, string, string, error) {
|
||||
detailTiktok := ""
|
||||
whiteTiktok := ""
|
||||
tiktokImgLocal, err := dao.GetVendorImg(skuId, model.VendorIDDD)
|
||||
if err == nil && tiktokImgLocal != nil && tiktokImgLocal.Img != "" {
|
||||
localImgs := make([]string, 0, 0)
|
||||
localImgs = append(localImgs, tiktokImgLocal.Img)
|
||||
whiteTiktok = tiktokImgLocal.Img
|
||||
if tiktokImgLocal.Img2 != "" {
|
||||
localImgs = append(localImgs, tiktokImgLocal.Img2)
|
||||
}
|
||||
if tiktokImgLocal.Img3 != "" {
|
||||
localImgs = append(localImgs, tiktokImgLocal.Img3)
|
||||
}
|
||||
if tiktokImgLocal.Img4 != "" {
|
||||
localImgs = append(localImgs, tiktokImgLocal.Img4)
|
||||
}
|
||||
if tiktokImgLocal.Img5 != "" {
|
||||
localImgs = append(localImgs, tiktokImgLocal.Img5)
|
||||
}
|
||||
if tiktokImgLocal.DescImg != "" {
|
||||
detailTiktok = tiktokImgLocal.DescImg
|
||||
} else {
|
||||
detailTiktok = tiktokImgLocal.Img
|
||||
}
|
||||
return strings.Join(localImgs, "|"), detailTiktok, whiteTiktok, nil
|
||||
}
|
||||
|
||||
imgs := make([]tiktokShop.Imgs, 0, 0)
|
||||
for _, v := range img {
|
||||
if v != "" {
|
||||
@@ -899,27 +912,109 @@ func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg
|
||||
Url: detailImg,
|
||||
})
|
||||
}
|
||||
if whiteImg != "" {
|
||||
imgs = append(imgs, tiktokShop.Imgs{
|
||||
Name: "white_" + storeId + "_" + detailImg[21:54],
|
||||
Url: detailImg,
|
||||
})
|
||||
}
|
||||
tiktokImgList, err := api.BatchUploadImages(imgs)
|
||||
if err != nil {
|
||||
return "", "", err
|
||||
return "", "", "", err
|
||||
}
|
||||
|
||||
detailTiktok := ""
|
||||
var tiktokImg []string
|
||||
var localTiktokObj = &model.TaoSkuImg{
|
||||
SkuID: skuId,
|
||||
VendorID: model.VendorIDDD,
|
||||
}
|
||||
for k, v := range tiktokImgList {
|
||||
if strings.Contains(k, "detail_") {
|
||||
detailTiktok = v.ByteUrl
|
||||
localTiktokObj.DescImg = v.ByteUrl
|
||||
continue
|
||||
}
|
||||
if strings.Contains(k, "white_") {
|
||||
whiteTiktok = v.ByteUrl
|
||||
localTiktokObj.Img = v.ByteUrl
|
||||
continue
|
||||
}
|
||||
tiktokImg = append(tiktokImg, v.ByteUrl)
|
||||
}
|
||||
|
||||
if detailTiktok == "" {
|
||||
detailTiktok = tiktokImg[0]
|
||||
localTiktokObj.DescImg = detailTiktok
|
||||
}
|
||||
if whiteTiktok == "" {
|
||||
whiteTiktok = tiktokImg[0]
|
||||
localTiktokObj.Img = whiteTiktok
|
||||
}
|
||||
|
||||
return strings.Join(tiktokImg, "|"), detailTiktok, nil
|
||||
switch len(tiktokImg) {
|
||||
case 1:
|
||||
localTiktokObj.Img2 = tiktokImg[0]
|
||||
case 2:
|
||||
localTiktokObj.Img2 = tiktokImg[0]
|
||||
localTiktokObj.Img3 = tiktokImg[1]
|
||||
case 3:
|
||||
localTiktokObj.Img2 = tiktokImg[0]
|
||||
localTiktokObj.Img3 = tiktokImg[1]
|
||||
localTiktokObj.Img4 = tiktokImg[2]
|
||||
case 4:
|
||||
localTiktokObj.Img2 = tiktokImg[0]
|
||||
localTiktokObj.Img3 = tiktokImg[1]
|
||||
localTiktokObj.Img4 = tiktokImg[2]
|
||||
localTiktokObj.Img5 = tiktokImg[3]
|
||||
|
||||
}
|
||||
dao.CreateEntity(dao.GetDB(), localTiktokObj)
|
||||
return strings.Join(tiktokImg, "|"), detailTiktok, whiteTiktok, nil
|
||||
}
|
||||
|
||||
// GetWhiteImg 更新专用暂时只考虑更新白底图
|
||||
//func GetWhiteImg(api *tiktokShop.API, skuId int, storeId, whiteImg string) (string, error) {
|
||||
// //每个图片都上传太慢了
|
||||
// tiktokImgLocal, err := dao.GetVendorImg(skuId, model.VendorIDDD)
|
||||
// if err == nil && tiktokImgLocal != nil && tiktokImgLocal.Img != "" {
|
||||
// return tiktokImgLocal.Img, nil
|
||||
// }
|
||||
//
|
||||
// imgs := make([]tiktokShop.Imgs, 0, 0)
|
||||
// if whiteImg == "" {
|
||||
// return "", fmt.Errorf("商品白底图不能为空")
|
||||
// }
|
||||
//
|
||||
// imgs = append(imgs, tiktokShop.Imgs{
|
||||
// Name: "white_" + storeId + "_" + whiteImg[21:54],
|
||||
// Url: whiteImg,
|
||||
// })
|
||||
//
|
||||
// tiktokImgList, err := api.BatchUploadImages(imgs)
|
||||
// if err != nil {
|
||||
// return "", err
|
||||
// }
|
||||
// if len(tiktokImgList) == model.NO {
|
||||
// return "", fmt.Errorf("白底图片上传失败")
|
||||
// }
|
||||
//
|
||||
// whiteTiktok := ""
|
||||
// var tiktokImg []string
|
||||
// for k, v := range tiktokImgList {
|
||||
// if strings.Contains(k, "white_") {
|
||||
// whiteTiktok = v.ByteUrl
|
||||
// continue
|
||||
// }
|
||||
// tiktokImg = append(tiktokImg, v.ByteUrl)
|
||||
// }
|
||||
//
|
||||
// if whiteTiktok == "" {
|
||||
// whiteTiktok = tiktokImg[0]
|
||||
// }
|
||||
//
|
||||
// return whiteTiktok, nil
|
||||
//}
|
||||
|
||||
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64, upcCode, upcBrandName, upcTiktokBrandId string) (string, int64, error) {
|
||||
db := dao.GetDB()
|
||||
categoryList, err := api.GetCatePropertyV2(categoryLeafId)
|
||||
|
||||
Reference in New Issue
Block a user