diff --git a/business/jxstore/cms/sync_store_sku.go b/business/jxstore/cms/sync_store_sku.go index d63747668..af0119781 100644 --- a/business/jxstore/cms/sync_store_sku.go +++ b/business/jxstore/cms/sync_store_sku.go @@ -568,23 +568,22 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, isFull bo return err } -func checkRemoteCatExist(localCatMap map[string]*dao.SkuStoreCatInfo, catList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) { - for _, v := range catList { - if localCatMap[v.VendorCatID] == nil && localCatMap[v.Name] == nil { - cat2Delete = append(cat2Delete, v) +func checkRemoteCatExist(outRemoteCatMap map[string]int, localCatMap map[string]*dao.SkuStoreCatInfo, remoteCatList []*partner.BareCategoryInfo) (cat2Delete []*partner.BareCategoryInfo) { + for _, v := range remoteCatList { + localCat := localCatMap[v.VendorCatID] + if localCat == nil { + localCat = localCatMap[v.Name] } - cat2Delete = append(cat2Delete, checkRemoteCatExist(localCatMap, v.Children)...) + if localCat == nil || v.Level != int(localCat.Level) { + cat2Delete = append(cat2Delete, v) + } else { + outRemoteCatMap[v.VendorCatID] = 1 + } + cat2Delete = append(cat2Delete, checkRemoteCatExist(outRemoteCatMap, localCatMap, v.Children)...) } return cat2Delete } -func fillRemoteCatMap(catList []*partner.BareCategoryInfo, catMap map[string]int) { - for _, v := range catList { - catMap[v.VendorCatID] = 1 - fillRemoteCatMap(v.Children, catMap) - } -} - // 清除京西没有,平台有的商品与商家分类 // todo !!!,因为美团外卖分类当前是用的名字关联的,所以改名后如果没有及时同步,这个函数会导致美团平台的分类被误删 func PruneMissingStoreSkus(ctx *jxcontext.Context, parentTask tasksch.ITask, vendorID, storeID int, vendorStoreID string, isAsync, isContinueWhenError bool) (hint string, err error) { @@ -627,12 +626,8 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v SkuID: skuID, VendorSkuID: v.SkuList[0].VendorSkuID, }) - } - if remoteSkuMap[skuID] == 0 { - remoteSkuMap[skuID] = 1 } else { - // 重复的删除后,再打上待创建标记 - remoteSkuMap[skuID] = 0 + remoteSkuMap[skuID] = 1 } } } @@ -674,10 +669,9 @@ func amendAndPruneStoreStuff(ctx *jxcontext.Context, parentTask tasksch.ITask, v remoteCatList, err2 := handler.GetStoreAllCategories(ctx, storeID, vendorStoreID) if err = err2; err == nil { - cat2Delete = checkRemoteCatExist(localCatMap, remoteCatList) - remoteCatMap := make(map[string]int) - fillRemoteCatMap(remoteCatList, remoteCatMap) + cat2Delete = checkRemoteCatExist(remoteCatMap, localCatMap, remoteCatList) + for _, v := range localCatList { if remoteCatMap[v.VendorCatID] == 0 && !model.IsSyncStatusNew(v.StoreCatSyncStatus) && !model.IsSyncStatusDelete(v.StoreCatSyncStatus) && v.MapID != 0 { storeCatBindIDs = append(storeCatBindIDs, v.MapID)