diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index b34c2aff5..70f8d3428 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -2896,6 +2896,6 @@ func ReorderVendorCategories(ctx *jxcontext.Context, parentID, vendorID int, ven } } dao.Commit(db) - _, err = SyncCategories(ctx, nil, []int{model.VendorIDJD}, []string{vendorOrgCode}, categoryIDs, true) + SyncReorderCategories(ctx, parentID, true) return err } diff --git a/business/jxstore/cms/sync2.go b/business/jxstore/cms/sync2.go index 92e034bcf..df1d61990 100644 --- a/business/jxstore/cms/sync2.go +++ b/business/jxstore/cms/sync2.go @@ -222,20 +222,35 @@ func SyncReorderCategories(ctx *jxcontext.Context, parentCatID int, isAsync bool func(t *tasksch.ParallelTask, batchItemList []interface{}, params ...interface{}) (retVal interface{}, err error) { vendorInfo := batchItemList[0].(*MultiStoreVendorInfo) multiStoresHandler := CurVendorSync.GetMultiStoreHandler(vendorInfo.VendorID) + vendorOrgCode, err := dao.GetVendorOrgCode(db, vendorInfo.VendorID, vendorInfo.OrgCode) if multiStoresHandler != nil { - catList, err2 := dao.GetSkuCategoryWithVendor(db, []int{vendorInfo.VendorID}, []string{vendorInfo.OrgCode}, parentCatID, nil, false) - if err = err2; err == nil { - var vendorCatIDList []string - for _, v := range catList { - if v.VendorCatID != "" { - vendorCatIDList = append(vendorCatIDList, v.VendorCatID) + var vendorCatIDList []string + var parentVendorCatID string + //如果用平台分类就走else,用京西分类就还是原来的if + if vendorOrgCode[0].IsJxCat == model.NO { + catList, err2 := dao.GetSkuCategoryWithVendor(db, []int{vendorInfo.VendorID}, []string{vendorInfo.OrgCode}, parentCatID, nil, false) + if err = err2; err == nil { + for _, v := range catList { + if v.VendorCatID != "" { + vendorCatIDList = append(vendorCatIDList, v.VendorCatID) + } } } - if len(vendorCatIDList) > 0 { - if err = multiStoresHandler.ReorderCategories2(ctx, vendorInfo.OrgCode, catList[0].ParentVendorCatID, vendorCatIDList); err == nil { - retVal = []int{len(vendorCatIDList)} + parentVendorCatID = catList[0].ParentVendorCatID + } else { + vendorCatList, _ := dao.GetVendorCategoryMapExt(db, parentCatID, 0, vendorInfo.VendorID, vendorInfo.OrgCode, 0) + for _, v := range vendorCatList { + if v.VendorThingID != "" { + vendorCatIDList = append(vendorCatIDList, v.VendorThingID) } } + thingMaps, _ := dao.GetThingMapList(db, model.ThingTypeCategory, []int{vendorInfo.VendorID}, []int{parentCatID}, []string{vendorInfo.OrgCode}) + parentVendorCatID = thingMaps[0].VendorThingID + } + if len(vendorCatIDList) > 0 { + if err = multiStoresHandler.ReorderCategories2(ctx, vendorInfo.OrgCode, parentVendorCatID, vendorCatIDList); err == nil { + retVal = []int{len(vendorCatIDList)} + } } } else { err = fmt.Errorf("非法平台:%d", vendorInfo.VendorID) diff --git a/business/model/dao/sku.go b/business/model/dao/sku.go index 018e279b3..ea61a51cd 100644 --- a/business/model/dao/sku.go +++ b/business/model/dao/sku.go @@ -485,3 +485,46 @@ func GetVendorCategoryMap(db *DaoDB, parentID, level, vendorID int, vendorOrgCod } return vendorMaps, err } + +type GetVendorCategoryMapExtResult struct { + model.VendorCategoryMap + VendorThingID string `orm:"column(vendor_thing_id)" json:"vendorThingID"` +} + +func GetVendorCategoryMapExt(db *DaoDB, parentID, level, vendorID int, vendorOrgCode string, categoryID int) (vendorMaps []*GetVendorCategoryMapExtResult, err error) { + sql := ` + SELECT a.*, b.vendor_thing_id + FROM vendor_category_map a + JOIN thing_map b ON b.thing_id = a.category_id AND b.thing_type = ? + WHERE a.deleted_at = ? + ` + sqlParams := []interface{}{ + utils.DefaultTimeValue, + } + if parentID >= 0 { + sql += " AND a.parent_id = ?" + sqlParams = append(sqlParams, parentID) + } + if level > 0 { + sql += " AND a.level = ?" + sqlParams = append(sqlParams, level) + } + if vendorID != -1 { + sql += " AND a.vendor_id = ?" + sqlParams = append(sqlParams, vendorID) + } + if vendorOrgCode != "" { + sql += " AND a.vendor_org_code = ?" + sqlParams = append(sqlParams, vendorOrgCode) + } + if categoryID > 0 { + sql += " AND a.category_id = ?" + sqlParams = append(sqlParams, categoryID) + } + sql += " ORDER BY a.vendor_category_seq" + err = GetRows(db, &vendorMaps, sql, sqlParams) + if err != nil { + return nil, err + } + return vendorMaps, err +}