获取类目id

This commit is contained in:
苏尹岚
2020-05-09 11:14:22 +08:00
parent 9b0863d4f8
commit d6962a27ef
3 changed files with 73 additions and 35 deletions

View File

@@ -433,7 +433,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
}
} else {
if sku.MergedStatus == model.SkuStatusNormal {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB && vendorID != model.VendorIDJDShop {
globals.SugarLogger.Warnf("syncStoreSkuNew 创建门店:%d商品:%d但没有平台分类ID", storeID, sku.SkuID)
} else {
createList = append(createList, sku)
@@ -455,7 +455,7 @@ func syncStoreSkuNew(ctx *jxcontext.Context, parentTask tasksch.ITask, causeFlag
isAdded2Update := false
// 修改商品信息时不改价(以免活动引起的失败),而用单独的改价来改
if (model.IsSyncStatusUpdate(sku.SkuSyncStatus) || (model.IsSyncStatusSeq(sku.SkuSyncStatus) && reorderHandler == nil)) && singleStoreHandler != nil {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB {
if dao.IsVendorThingIDEmpty(sku.VendorCatID) && !strings.Contains(sku.StoreName, model.ExdStoreName) && vendorID != model.VendorIDYB && vendorID != model.VendorIDJDShop {
globals.SugarLogger.Warnf("syncStoreSkuNew 修改门店:%d商品:%d但没有平台分类ID", storeID, sku.SkuID)
} else {
isAdded2Update = true

View File

@@ -1,6 +1,7 @@
package jdshop
import (
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils/jxcontext"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/partner"
@@ -39,5 +40,19 @@ func (p *PurchaseHandler) UploadImg(ctx *jxcontext.Context, vendorOrgCode, imgUR
}
func (p *PurchaseHandler) GetVendorCategories(ctx *jxcontext.Context) (vendorCats []*model.SkuVendorCategory, err error) {
result, err := api.JdShopAPI.FindVendorCategories()
for _, v := range result {
cat := &model.SkuVendorCategory{
VendorID: model.VendorIDJDShop,
Name: v.Name,
Level: v.Lev,
VendorCategoryID: utils.Int2Str(v.ID),
}
if v.Lev > 1 {
cat.ParentID = utils.Int2Str(v.Fid)
cat.IsLeaf = 1
}
vendorCats = append(vendorCats, cat)
}
return vendorCats, err
}

View File

@@ -71,64 +71,50 @@ func (p *PurchaseHandler) UpdateStoreSkusStock(ctx *jxcontext.Context, vendorOrg
}
func (p *PurchaseHandler) GetStoreAllCategories(ctx *jxcontext.Context, storeID int, vendorStoreID string) (cats []*partner.BareCategoryInfo, err error) {
result, err := api.JdShopAPI.FindShopCategories()
for _, v := range result {
var cat = &partner.BareCategoryInfo{
VendorCatID: utils.Int64ToStr(v.CID),
Name: v.Name,
}
if v.ParentCID == 0 {
cat.Level = 1
} else {
cat.Level = 2
}
cats = append(cats, cat)
}
return cats, err
}
func (p *PurchaseHandler) CreateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
fmt.Println("test1111111111111111111111", partner.GetMultiStoreVendorIDs())
var createShopCategoryParams []*jdshopapi.CreateShopCategoryParam
result, err := api.JdShopAPI.FindShopCategories()
if err != nil {
return err
}
for _, v := range result {
createShopCategoryParam := &jdshopapi.CreateShopCategoryParam{
HomeShow: "0",
ID: utils.Int64ToStr(v.CID),
Open: "",
OrderNo: utils.Int2Str(v.OrderNo),
ParentID: utils.Int64ToStr(v.ParentCID),
Title: v.Name,
Type: jdshopapi.UpdateCatType,
}
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam)
}
createShopCategoryParam2 := &jdshopapi.CreateShopCategoryParam{
HomeShow: "0",
ID: "1",
Open: "",
OrderNo: utils.Int2Str(storeCat.Seq),
ParentID: storeCat.ParentVendorCatID,
Title: storeCat.Name,
Type: jdshopapi.CreateCatType,
}
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam2)
err = api.JdShopAPI.CreateShopCategory(createShopCategoryParams)
err = updateOrCreateCategories(storeCat, true)
}
return err
}
func (p *PurchaseHandler) UpdateStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID string, storeCat *dao.SkuStoreCatInfo) (err error) {
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
err = updateOrCreateCategories(storeCat, false)
}
return err
}
func (p *PurchaseHandler) DeleteStoreCategory(ctx *jxcontext.Context, storeID int, vendorStoreID, vendorCatID string, level int) (err error) {
if globals.EnableJdShopWrite && vendorStoreID == model.JdShopMainVendorStoreID {
_, err = api.JdShopAPI.DeleteShopCategory(utils.Str2Int64(vendorCatID))
}
return err
}
func (p *PurchaseHandler) IsErrSkuExist(err error) (isExist bool) {
return yinbaoapi.IsErrSkuExist(err)
return false
}
func (p *PurchaseHandler) IsErrCategoryExist(err error) (isExist bool) {
return yinbaoapi.IsErrCategoryExist(err)
return false
}
func (p *PurchaseHandler) IsErrCategoryNotExist(err error) (isNotExist bool) {
@@ -144,7 +130,7 @@ func (p *PurchaseHandler) GetSensitiveWordRegexp() *regexp.Regexp {
}
func (p *PurchaseHandler) IsErrSkuNotExist(err error) (isNotExist bool) {
return yinbaoapi.IsErrSkuNotExist(err)
return false
}
func ybSkuStatus2Jx(ybStatus int) (jxSkuStatus int) {
@@ -196,3 +182,40 @@ func vendorSku2Jx(result *yinbaoapi.QueryProductByBarcodeResult, resultp []*yinb
}
return skuName
}
func updateOrCreateCategories(storeCat *dao.SkuStoreCatInfo, isCreate bool) (err error) {
var createShopCategoryParams []*jdshopapi.CreateShopCategoryParam
result, err := api.JdShopAPI.FindShopCategories()
if err != nil {
return err
}
for _, v := range result {
createShopCategoryParam := &jdshopapi.CreateShopCategoryParam{
HomeShow: "0",
ID: utils.Int64ToStr(v.CID),
Open: "",
OrderNo: utils.Int2Str(v.OrderNo),
ParentID: utils.Int64ToStr(v.ParentCID),
Title: v.Name,
Type: jdshopapi.UpdateCatType,
}
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam)
}
createShopCategoryParam2 := &jdshopapi.CreateShopCategoryParam{
HomeShow: "0",
Open: "",
OrderNo: utils.Int2Str(storeCat.Seq),
ParentID: storeCat.ParentVendorCatID,
Title: storeCat.Name,
}
if isCreate {
createShopCategoryParam2.Type = jdshopapi.CreateCatType
createShopCategoryParam2.ID = "1"
} else {
createShopCategoryParam2.Type = jdshopapi.UpdateCatType
createShopCategoryParam2.ID = storeCat.VendorCatID
}
createShopCategoryParams = append(createShopCategoryParams, createShopCategoryParam2)
err = api.JdShopAPI.CreateShopCategory(createShopCategoryParams)
return err
}