1
This commit is contained in:
@@ -146,28 +146,22 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
PickupMethod: "0",
|
PickupMethod: "0",
|
||||||
OuterProductId: utils.Int2Str(storeSku.SkuID), // 本地skuId为外部商品id
|
OuterProductId: utils.Int2Str(storeSku.SkuID), // 本地skuId为外部商品id
|
||||||
}
|
}
|
||||||
|
// 部分商品没有所属的分类,直接跳过!
|
||||||
if storeSku.SkuVendorMapCatID != "" {
|
if storeSku.SkuVendorMapCatID != "" {
|
||||||
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
|
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
|
||||||
} else {
|
} else if storeSku.VendorVendorCatID != 0 {
|
||||||
param.CategoryLeafId = storeSku.VendorVendorCatID
|
param.CategoryLeafId = storeSku.VendorVendorCatID
|
||||||
|
} else {
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取上传图,商品轮播图
|
// 获取上传图,商品轮播图
|
||||||
img, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5, storeSku.DescImg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
param.Pic = img
|
param.Pic = img
|
||||||
// 商品详情图
|
param.Description = detailImg
|
||||||
if storeSku.DescImg == "" {
|
|
||||||
param.Description = strings.Split(img, ",")[0]
|
|
||||||
} else {
|
|
||||||
img2, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg)
|
|
||||||
if err != nil {
|
|
||||||
param.Description = strings.Split(img, ",")[0]
|
|
||||||
}
|
|
||||||
param.Description = img2
|
|
||||||
}
|
|
||||||
|
|
||||||
// weight_unit 目前抖音只支持g和kg两种
|
// weight_unit 目前抖音只支持g和kg两种
|
||||||
//switch storeSku.Unit {
|
//switch storeSku.Unit {
|
||||||
@@ -181,32 +175,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||||
// 获取商品的属性
|
// 获取商品的属性
|
||||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
||||||
categoryList, err := api.GetCatePropertyV2(param.CategoryLeafId)
|
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
categoryMap := make(map[string][]map[string]interface{})
|
|
||||||
for _, v := range categoryList.Data.Data {
|
|
||||||
if v.Required == model.YES {
|
|
||||||
options := make([]map[string]interface{}, 0)
|
|
||||||
if v.PropertyName == "品牌" {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 789194134, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else if v.PropertyName == "产地" {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else if len(options) == 0 {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 0, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": v.Options[0].Value, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
param.ProductFormatNew = utils.Format4Output(categoryMap, false)
|
|
||||||
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), int64(storeSku.NameID), param.ProductFormatNew)
|
|
||||||
} else {
|
} else {
|
||||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||||
}
|
}
|
||||||
@@ -318,22 +290,14 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
} else {
|
} else {
|
||||||
param.CategoryLeafId = storeSku.VendorVendorCatID
|
param.CategoryLeafId = storeSku.VendorVendorCatID
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取上传图,商品轮播图
|
// 获取上传图,商品轮播图
|
||||||
img, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5)
|
img, detailImg, err := GetTiktokImgList(api, utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg, storeSku.ImgOrigin, storeSku.Img2, storeSku.Img3, storeSku.Img4, storeSku.Img5, storeSku.DescImg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
param.Pic = img
|
param.Pic = img
|
||||||
// 商品详情图
|
param.Description = detailImg
|
||||||
if storeSku.DescImg == "" {
|
|
||||||
param.Description = strings.Split(img, ",")[0]
|
|
||||||
} else {
|
|
||||||
img2, err := GetTiktokImgList(utils.Int2Str(storeSku.StoreID), storeDetail.VendorOrgCode, storeSku.DescImg)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
param.Description = img2
|
|
||||||
}
|
|
||||||
|
|
||||||
// weight_unit 目前抖音只支持g和kg两种
|
// weight_unit 目前抖音只支持g和kg两种
|
||||||
//switch storeSku.Unit {
|
//switch storeSku.Unit {
|
||||||
@@ -346,32 +310,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
|||||||
//param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
//param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||||
// 获取商品的属性
|
// 获取商品的属性
|
||||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
||||||
categoryList, err := api.GetCatePropertyV2(param.CategoryLeafId)
|
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
categoryMap := make(map[string][]map[string]interface{})
|
|
||||||
for _, v := range categoryList.Data.Data {
|
|
||||||
if v.Required == model.YES {
|
|
||||||
options := make([]map[string]interface{}, 0)
|
|
||||||
if v.PropertyName == "品牌" {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 789194134, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else if v.PropertyName == "产地" {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else if len(options) == 0 {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 0, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
} else {
|
|
||||||
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": v.Options[0].Value, "diy_type": v.DiyType})
|
|
||||||
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
|
||||||
}
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
param.ProductFormatNew = utils.Format4Output(categoryMap, false)
|
|
||||||
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), int64(storeSku.NameID), param.ProductFormatNew)
|
|
||||||
} else {
|
} else {
|
||||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||||
}
|
}
|
||||||
@@ -558,7 +500,7 @@ func GetProductFormatNew(categoryLeftId int64, vendorOrgCode string) (*product_g
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetTiktokImgList 获取抖音图片链接
|
// GetTiktokImgList 获取抖音图片链接
|
||||||
func GetTiktokImgList(storeId, appOrgCode string, img ...string) (string, error) {
|
func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg string, img ...string) (string, string, error) {
|
||||||
imgs := make([]tiktokShop.Imgs, 0, 0)
|
imgs := make([]tiktokShop.Imgs, 0, 0)
|
||||||
var tiktokImg []string
|
var tiktokImg []string
|
||||||
for _, v := range img {
|
for _, v := range img {
|
||||||
@@ -569,16 +511,59 @@ func GetTiktokImgList(storeId, appOrgCode string, img ...string) (string, error)
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tiktokImgList, err := getAPI(appOrgCode, 0, "").BatchUploadImages(imgs)
|
if detailImg != "" {
|
||||||
|
imgs = append(imgs, tiktokShop.Imgs{
|
||||||
|
Name: "detail_" + storeId + "_" + detailImg[21:54],
|
||||||
|
Url: detailImg,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
tiktokImgList, err := api.BatchUploadImages(imgs)
|
||||||
|
if err != nil {
|
||||||
|
return "", "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
detailTiktok := ""
|
||||||
|
for _, v := range tiktokImgList {
|
||||||
|
if strings.HasPrefix(v.Name, "detail_") {
|
||||||
|
detailTiktok = v.ByteUrl
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tiktokImg = append(tiktokImg, v.ByteUrl)
|
||||||
|
}
|
||||||
|
if detailTiktok == "" {
|
||||||
|
detailTiktok = tiktokImg[0]
|
||||||
|
}
|
||||||
|
return strings.Join(tiktokImg, "|"), detailTiktok, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64) (string, error) {
|
||||||
|
categoryList, err := api.GetCatePropertyV2(categoryLeafId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
categoryMap := make(map[string][]map[string]interface{})
|
||||||
for _, v := range tiktokImgList {
|
for _, v := range categoryList.Data.Data {
|
||||||
tiktokImg = append(tiktokImg, v.ByteUrl)
|
if v.Required != model.YES {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
options := make([]map[string]interface{}, 0)
|
||||||
|
if v.PropertyName == "品牌" {
|
||||||
|
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 789194134, "diy_type": v.DiyType})
|
||||||
|
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
||||||
|
} else if v.PropertyName == "产地" {
|
||||||
|
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 13850, "diy_type": v.DiyType})
|
||||||
|
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
||||||
|
} else if len(options) == 0 {
|
||||||
|
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": 0, "diy_type": v.DiyType})
|
||||||
|
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
||||||
|
} else {
|
||||||
|
options = append(options, map[string]interface{}{"name": v.PropertyName, "value": v.Options[0].Value, "diy_type": v.DiyType})
|
||||||
|
categoryMap[utils.Int64ToStr(v.PropertyId)] = options
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
productFormatNew := utils.Format4Output(categoryMap, false)
|
||||||
return strings.Join(tiktokImg, "|"), nil
|
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), skuNameId, productFormatNew)
|
||||||
|
return utils.Format4Output(categoryMap, false), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSpecPrices 解析属性和规格参数
|
// GetSpecPrices 解析属性和规格参数
|
||||||
|
|||||||
Reference in New Issue
Block a user