From 0c7ecd4a875fdb7a4860f1a7fce1ac2ab80ac652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Tue, 28 Jul 2020 11:00:43 +0800 Subject: [PATCH] =?UTF-8?q?=E5=95=86=E5=93=81=E6=98=A0=E5=B0=84=E7=B1=BB?= =?UTF-8?q?=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- business/jxstore/cms/sku.go | 53 ++++++++++++++++++++++++++++++------- business/model/sku.go | 5 ++++ 2 files changed, 49 insertions(+), 9 deletions(-) diff --git a/business/jxstore/cms/sku.go b/business/jxstore/cms/sku.go index 686e60ea5..ae635a7ba 100644 --- a/business/jxstore/cms/sku.go +++ b/business/jxstore/cms/sku.go @@ -904,6 +904,8 @@ func AddSkuName(ctx *jxcontext.Context, skuNameExt *model.SkuNameExt, userName s } outSkuNameExt = tmpInfo.SkuNames[0] _, err = CurVendorSync.SyncSku(ctx, db, outSkuNameExt.SkuName.ID, -1, false, false, userName) + + updateOrCreateSkuVendorCategoryMap(db, ctx, outSkuNameExt.SkuName.ID, nil, skuNameExt, false) return outSkuNameExt, err } @@ -981,7 +983,7 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf return 0, err } } - updateOrCreateSkuVendorCategoryMap(db, ctx, nameID, payload, false) + updateOrCreateSkuVendorCategoryMap(db, ctx, nameID, payload, nil, false) if utils.Interface2Int64WithDefault(payload["isGlobal"], 0) == 0 && payload["places"] != nil { if places, ok := payload["places"].([]interface{}); ok { if _, err = dao.DeleteSkuNamePlace(db, nameID, nil); err != nil { @@ -1053,23 +1055,55 @@ func UpdateSkuName(ctx *jxcontext.Context, nameID int, payload map[string]interf return num, err } -func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, nameID int, payload map[string]interface{}, isDelete bool) { +func updateOrCreateSkuVendorCategoryMap(db *dao.DaoDB, ctx *jxcontext.Context, nameID int, payload map[string]interface{}, skuNameExt *model.SkuNameExt, isDelete bool) { if isDelete { - + skuVendorCatMaps, _ := dao.GetSkuVendorCategoryMaps(db, []int{nameID}, nil, nil) + for _, v := range skuVendorCatMaps { + v.DeletedAt = time.Now() + v.LastOperator = ctx.GetUserName() + dao.UpdateEntity(db, v, "DeletedAt", "LastOperator") + } } else { - - if payload["jdCategoryID"].(string) != "" { - skuVendorCatMaps, _ := dao.GetSkuVendorCategoryMaps(db, []int{nameID}, []int{model.VendorIDJD}, nil) + updateOrCreate := func(vendorID, nameID int, vendorCatID string) { + skuVendorCatMaps, _ := dao.GetSkuVendorCategoryMaps(db, []int{nameID}, []int{vendorID}, nil) if len(skuVendorCatMaps) > 0 { - skuVendorCatMaps[0].VendorCategoryID = payload["jdCategoryID"].(string) + skuVendorCatMaps[0].VendorCategoryID = vendorCatID dao.UpdateEntity(db, skuVendorCatMaps[0], "VendorCategoryID") } else { skuVendorCatMap := &model.SkuVendorCategoryMap{ NameID: nameID, - VendorID: model.VendorIDJD, - VendorCategoryID: payload["jdCategoryID"].(string), + VendorID: vendorID, + VendorCategoryID: vendorCatID, } dao.WrapAddIDCULDEntity(skuVendorCatMap, ctx.GetUserName()) + dao.CreateEntity(db, skuVendorCatMap) + } + } + if skuNameExt != nil { + if skuNameExt.JdCategoryID != "" { + updateOrCreate(model.VendorIDJD, nameID, skuNameExt.JdCategoryID) + } + if skuNameExt.JdsCategoryID != "" { + updateOrCreate(model.VendorIDJDShop, nameID, skuNameExt.JdsCategoryID) + } + if skuNameExt.EbaiCategoryID != "" { + updateOrCreate(model.VendorIDEBAI, nameID, skuNameExt.EbaiCategoryID) + } + if skuNameExt.MtwmCategoryID != "" { + updateOrCreate(model.VendorIDMTWM, nameID, skuNameExt.MtwmCategoryID) + } + } else { + if payload["jdCategoryID"].(string) != "" { + updateOrCreate(model.VendorIDJD, nameID, payload["jdCategoryID"].(string)) + } + if payload["jdsCategoryID"].(string) != "" { + updateOrCreate(model.VendorIDJDShop, nameID, payload["jdsCategoryID"].(string)) + } + if payload["ebaiCategoryID"].(string) != "" { + updateOrCreate(model.VendorIDEBAI, nameID, payload["ebaiCategoryID"].(string)) + } + if payload["mtwmCategoryID"].(string) != "" { + updateOrCreate(model.VendorIDMTWM, nameID, payload["mtwmCategoryID"].(string)) } } } @@ -1142,6 +1176,7 @@ func DeleteSkuName(ctx *jxcontext.Context, nameID int, userName string) (num int if len(skuList) > 0 { _, err = CurVendorSync.SyncSku(ctx, db, skuName.ID, -1, false, false, userName) } + updateOrCreateSkuVendorCategoryMap(db, ctx, nameID, nil, nil, true) return num, err } diff --git a/business/model/sku.go b/business/model/sku.go index 22c89c5a2..a1c68d140 100644 --- a/business/model/sku.go +++ b/business/model/sku.go @@ -284,6 +284,11 @@ type SkuNameExt struct { Places []int `orm:"-" json:"places"` PlacesStr string `json:"-"` MidUnitPrice int `json:"midUnitPrice"` + + JdCategoryID string `json:"JdCategoryID"` + JdsCategoryID string `json:"JdsCategoryID"` + EbaiCategoryID string `json:"EbaiCategoryID"` + MtwmCategoryID string `json:"MtwmCategoryID"` } type SkuExinfoMap struct {