From 33121d2ce518fc751202c9ca37824f10d6afaac8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Tue, 28 Feb 2023 14:37:15 +0800 Subject: [PATCH] 1 --- .../purchase/tiktok_store/store_sku2_utils.go | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/business/partner/purchase/tiktok_store/store_sku2_utils.go b/business/partner/purchase/tiktok_store/store_sku2_utils.go index f9294ff7c..788533e85 100644 --- a/business/partner/purchase/tiktok_store/store_sku2_utils.go +++ b/business/partner/purchase/tiktok_store/store_sku2_utils.go @@ -249,7 +249,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI updateParam.Pic = param.Pic updateParam.Description = param.Description updateParam.WeightUnit = tiktokShop.WeightUint_G - updateParam.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, updateParam.CategoryLeafId) + //updateParam.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, updateParam.CategoryLeafId) updateParam.ProductId = mainOrderDetail.ProductId updateParam.MainProductId = mainProductId @@ -369,7 +369,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI // 获取商品的属性 if storeSku.TiktokAttribute == "" || storeSku.TiktokAttribute == "{}" { - param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId) + param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId) if err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) continue @@ -378,8 +378,9 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI param.ProductFormatNew = storeSku.TiktokAttribute } // 获取品牌 - param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId) - + if param.StandardBrandId == 0 { + param.StandardBrandId, _ = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId) + } // 修改商品 param.ProductId = mainIdInt param.MainProductId = mainIdInt @@ -459,17 +460,20 @@ func makeMainProductSku(db *dao.DaoDB, api *tiktokShop.API, storeSku *dao.StoreS } else if storeSku.VendorSkuAttrId != "" && storeSku.VendorSkuAttrId != "{}" { param.ProductFormatNew = storeSku.TiktokAttribute } else { - param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId) + param.ProductFormatNew, param.StandardBrandId, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId) + //param.ProductFormatNew, err = MakeProductFormatNew(api, int64(storeSku.NameID), param.CategoryLeafId) if err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) return } } - param.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId) - if err != nil { - failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) - return + if param.StandardBrandId == 0 { + param.StandardBrandId, err = getTiktokBrandId(api, db, storeSku.Upc, storeSku.UpcBrandName, storeSku.UpcTiktokBrandId, param.CategoryLeafId) + if err != nil { + failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) + return + } } param.FreightId, param.SaleLimitId, err = getFreightIdAndSaleLimitId(api, db, storeDetail, vendorStoreID) @@ -907,19 +911,22 @@ func GetTiktokImgList(api *tiktokShop.API, storeId, appOrgCode string, detailImg return strings.Join(tiktokImg, "|"), detailTiktok, nil } -func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64) (string, error) { +func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId int64, upcCode, upcBrandName, upcTiktokBrandId string) (string, int64, error) { + db := dao.GetDB() categoryList, err := api.GetCatePropertyV2(categoryLeafId) if err != nil { - return "", err + return "", 0, err } categoryMap := make(map[string][]map[string]interface{}) + var tiktokBrandId int64 = 0 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}) + tiktokBrandId, _ = getTiktokBrandId(api, db, upcCode, upcBrandName, upcTiktokBrandId, categoryLeafId) + options = append(options, map[string]interface{}{"name": v.PropertyName, "value": tiktokBrandId, "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}) @@ -934,7 +941,7 @@ func MakeProductFormatNew(api *tiktokShop.API, skuNameId int64, categoryLeafId i } productFormatNew := utils.Format4Output(categoryMap, false) dao.UpdateSkuNameTiktokAttr(dao.GetDB(), skuNameId, productFormatNew) - return utils.Format4Output(categoryMap, false), nil + return utils.Format4Output(categoryMap, false), tiktokBrandId, nil } // GetSpecPrices 解析属性和规格参数