门店禁止自我关联

This commit is contained in:
gazebo
2020-02-05 12:03:13 +08:00
parent a600391ca1
commit 5a0a56e9b1

View File

@@ -783,11 +783,9 @@ func UpdateStore(ctx *jxcontext.Context, storeID int, payload map[string]interfa
if err != nil {
return 0, err
}
if linkStoreID != 0 {
if err = checkStoreHaveLinkedStore(storeID); err != nil {
if err = checkStoreHaveLinkedStore(storeID, linkStoreID); err != nil {
return 0, err
}
}
valid["linkStoreID"] = linkStoreID
// globals.SugarLogger.Debug(linkStoreID)
}
@@ -1012,9 +1010,13 @@ func EnableHaveRestStores(ctx *jxcontext.Context, isAsync, isContinueWhenError b
return hint, err
}
func checkStoreHaveLinkedStore(storeID int) (err error) {
storeList, err := dao.GetStoreLinkStores(dao.GetDB(), storeID)
if err == nil {
func checkStoreHaveLinkedStore(storeID, linkStoreID int) (err error) {
if linkStoreID != 0 {
if storeID == linkStoreID {
err = fmt.Errorf("不能自我关联")
} else {
storeList, err2 := dao.GetStoreLinkStores(dao.GetDB(), storeID)
if err = err2; err == nil {
if len(storeList) > 0 {
var storeInfo []string
for _, v := range storeList {
@@ -1023,6 +1025,8 @@ func checkStoreHaveLinkedStore(storeID int) (err error) {
err = fmt.Errorf("门店%d已经被其它门店(%s)关联,不能再关联至其它门店", storeID, strings.Join(storeInfo, ","))
}
}
}
}
return err
}
@@ -1045,11 +1049,9 @@ func CreateStore(ctx *jxcontext.Context, storeExt *StoreExt, userName string) (i
if err != nil {
return 0, err
}
if realLinkStoreID != 0 {
if err = checkStoreHaveLinkedStore(storeExt.ID); err != nil {
if err = checkStoreHaveLinkedStore(storeExt.ID, realLinkStoreID); err != nil {
return 0, err
}
}
storeExt.LinkStoreID = realLinkStoreID
existingID := store.ID