diff --git a/business/partner/purchase/tiktok_store/store_sku2_utils.go b/business/partner/purchase/tiktok_store/store_sku2_utils.go index 9d184f87d..5c48aef3a 100644 --- a/business/partner/purchase/tiktok_store/store_sku2_utils.go +++ b/business/partner/purchase/tiktok_store/store_sku2_utils.go @@ -214,8 +214,15 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI // 根据本地商品id获取线上商品是否存在,存在则只创建子商品 // 获取本地存储映射关系,获取本地主商品id是否存在 + var mainProductId int64 = 0 localThing, _ := dao.GetThingToTiktokMapList(db, model.VendorIDDD, int64(storeSku.SkuID), storeDetail.VendorOrgCode) mainOrderDetail, err := api.GetSkuDetailLocalID("", utils.Int2Str(storeSku.SkuID)) + if mainOrderDetail.MainProductId != 0 { + mainProductId = mainOrderDetail.MainProductId + } else { + mainProductId = mainOrderDetail.ProductId + } + if len(localThing) == 0 { if err != nil || mainOrderDetail == nil || mainOrderDetail.ProductIdStr == "" { tiktokResult, err := api.CreateStoreCommodity(param) // 创建主商品,同步主商品 @@ -246,18 +253,17 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI continue } - if err := dao.CreateThingMap(int64(storeSku.SkuID), mainOrderDetail.ProductIdStr, storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0); err != nil { + if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainProductId), storeDetail.VendorOrgCode, "线上存在本地不存在", model.ThingTypeSku, 0); err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) } - globals.SugarLogger.Debugf("111111111") - childrenProductId, err = api.CreateSubProduct(mainOrderDetail.ProductId, utils.Str2Int64(vendorStoreID)) + childrenProductId, err = api.CreateSubProduct(mainProductId, utils.Str2Int64(vendorStoreID)) if err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) continue } - storeSku.VendorMainId = mainOrderDetail.ProductIdStr + storeSku.VendorMainId = utils.Int64ToStr(mainProductId) var attrId []string for _, v := range mainOrderDetail.SpecPrices { attrId = append(attrId, utils.Int64ToStr(v.SkuId)) @@ -302,7 +308,7 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI updateParam.WeightUnit = tiktokShop.WeightUint_G updateParam.StandardBrandId = param.StandardBrandId // 默认品牌京西菜市 updateParam.ProductId = mainOrderDetail.ProductId - updateParam.MainProductId = mainOrderDetail.ProductId + updateParam.MainProductId = mainProductId updateParam.SpecPrices = param.SpecPrices //updateParam.StoreId = utils.Str2Int64(vendorStoreID) if err := api.EditStoreCommodity(updateParam); err != nil { @@ -318,7 +324,6 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI } // 主商品存在,直接同步子商品 - globals.SugarLogger.Debugf("22222222") childrenProductId, err := api.CreateSubProduct(utils.Str2Int64(localThing[0].VendorThingID), utils.Str2Int64(vendorStoreID)) if err != nil || childrenProductId == 0 { failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) @@ -398,7 +403,12 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) continue } - mainIdInt = mainOrderDetail.ProductId + if mainOrderDetail.MainProductId != 0 { + mainIdInt = mainOrderDetail.MainProductId + } else { + mainIdInt = mainOrderDetail.ProductId + } + storeSku.VendorMainId = utils.Int64ToStr(mainIdInt) if err := dao.CreateThingMap(int64(storeSku.SkuID), utils.Int64ToStr(mainIdInt), storeDetail.VendorOrgCode, "更新发现不存在", model.ThingTypeSku, 0); err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSku, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) @@ -412,10 +422,9 @@ func (p *PurchaseHandler) createOrUpdateStoreSkus(ctx *jxcontext.Context, storeI } // 修改商品 - param.ProductId = mainIdInt + param.ProductId = utils.Str2Int64(storeSku.VendorSkuID) param.MainProductId = mainIdInt param.SpecPrices = GetSpecPrices(param.Specs, vendorStoreID, param.MainProductId, storeSku) - //param.StoreId = utils.Str2Int64(vendorStoreID) if err := api.EditStoreCommodity(param); err != nil { failedList = putils.GetErrMsg2FailedSingleList(storeSkuList, err, storeID, model.VendorChineseNames[model.VendorIDDD], syncType) storeSku.VendorSkuID = utils.Int2Str(storeSku.SkuID)