From b73aae14747ceb043e055571454b5b93b6c045c4 Mon Sep 17 00:00:00 2001 From: gazebo Date: Tue, 16 Oct 2018 15:17:08 +0800 Subject: [PATCH] - check store existing for CopyStoreSkus. --- business/jxstore/cms/store_sku.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/business/jxstore/cms/store_sku.go b/business/jxstore/cms/store_sku.go index fba99c6d0..f1b9e9f8b 100644 --- a/business/jxstore/cms/store_sku.go +++ b/business/jxstore/cms/store_sku.go @@ -10,6 +10,7 @@ import ( "git.rosy.net.cn/jx-callback/business/model" "git.rosy.net.cn/jx-callback/business/model/dao" "git.rosy.net.cn/jx-callback/globals" + "github.com/astaxie/beego/orm" ) const ( @@ -447,7 +448,18 @@ func CopyStoreSkus(fromStoreID, toStoreID int, copyMode string, params map[strin if copyMode != CopyStoreSkuModeFresh && copyMode != CopyStoreSkuModeUpdate { return 0, fmt.Errorf("不支持的拷贝模式:%s", copyMode) } + if fromStoreID == toStoreID { + return 0, fmt.Errorf("源门店:%d与目标门店:%d相同", fromStoreID, toStoreID) + } + db := dao.GetDB() + if err = checkStoreExisting(db, fromStoreID); err != nil { + return 0, err + } + if err = checkStoreExisting(db, toStoreID); err != nil { + return 0, err + } + sqlCatAndSku := "" sqlCatAndSkuParams := make([]interface{}, 0) if params["categoryIDs"] != nil { @@ -549,3 +561,15 @@ func setStoreSkuBindStatus(skuBind *model.StoreSkuBind, status int8) { skuBind.ElmSyncStatus |= status skuBind.EbaiSyncStatus |= status } + +func checkStoreExisting(db *dao.DaoDB, storeID int) (err error) { + store := model.Store{} + store.ID = storeID + if err = dao.GetEntity(db, store); err != nil { + if err == orm.ErrNoRows { + return fmt.Errorf("门店:%d不存在", storeID) + } + return err + } + return nil +}