1
This commit is contained in:
@@ -146,28 +146,22 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
PickupMethod: "0",
|
||||
OuterProductId: utils.Int2Str(storeSku.SkuID), // 本地skuId为外部商品id
|
||||
}
|
||||
// 部分商品没有所属的分类,直接跳过!
|
||||
if storeSku.SkuVendorMapCatID != "" {
|
||||
param.CategoryLeafId = utils.Str2Int64(storeSku.SkuVendorMapCatID)
|
||||
} else {
|
||||
} else if storeSku.VendorVendorCatID != 0 {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
param.Pic = img
|
||||
// 商品详情图
|
||||
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
|
||||
}
|
||||
param.Description = detailImg
|
||||
|
||||
// weight_unit 目前抖音只支持g和kg两种
|
||||
//switch storeSku.Unit {
|
||||
@@ -181,32 +175,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||
// 获取商品的属性
|
||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
||||
categoryList, err := api.GetCatePropertyV2(param.CategoryLeafId)
|
||||
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||
if err != nil {
|
||||
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 {
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
}
|
||||
@@ -318,22 +290,14 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
} else {
|
||||
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 {
|
||||
return nil, err
|
||||
}
|
||||
param.Pic = img
|
||||
// 商品详情图
|
||||
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
|
||||
}
|
||||
param.Description = detailImg
|
||||
|
||||
// weight_unit 目前抖音只支持g和kg两种
|
||||
//switch storeSku.Unit {
|
||||
@@ -346,32 +310,10 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI
|
||||
//param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, 0, storeSku)
|
||||
// 获取商品的属性
|
||||
if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" {
|
||||
categoryList, err := api.GetCatePropertyV2(param.CategoryLeafId)
|
||||
param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId)
|
||||
if err != nil {
|
||||
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 {
|
||||
param.ProductFormatNew = storeSku.TiktokAttribute
|
||||
}
|
||||
@@ -558,7 +500,7 @@ func GetProductFormatNew(categoryLeftId int64, vendorOrgCode string) (*product_g
|
||||
}
|
||||
|
||||
// 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)
|
||||
var tiktokImg []string
|
||||
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 {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, v := range tiktokImgList {
|
||||
tiktokImg = append(tiktokImg, v.ByteUrl)
|
||||
categoryMap := make(map[string][]map[string]interface{})
|
||||
for _, v := range categoryList.Data.Data {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
return strings.Join(tiktokImg, "|"), nil
|
||||
productFormatNew := utils.Format4Output(categoryMap, false)
|
||||
dao.UpdateSkuNameTiktokAttr(dao.GetDB(), skuNameId, productFormatNew)
|
||||
return utils.Format4Output(categoryMap, false), nil
|
||||
}
|
||||
|
||||
// GetSpecPrices 解析属性和规格参数
|
||||
|
||||
Reference in New Issue
Block a user