门店禁止自我关联
This commit is contained in:
@@ -783,10 +783,8 @@ 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 {
|
||||
return 0, err
|
||||
}
|
||||
if err = checkStoreHaveLinkedStore(storeID, linkStoreID); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
valid["linkStoreID"] = linkStoreID
|
||||
// globals.SugarLogger.Debug(linkStoreID)
|
||||
@@ -1012,15 +1010,21 @@ 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 {
|
||||
if len(storeList) > 0 {
|
||||
var storeInfo []string
|
||||
for _, v := range storeList {
|
||||
storeInfo = append(storeInfo, utils.Int2Str(v.ID))
|
||||
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 {
|
||||
storeInfo = append(storeInfo, utils.Int2Str(v.ID))
|
||||
}
|
||||
err = fmt.Errorf("门店%d已经被其它门店(%s)关联,不能再关联至其它门店", storeID, strings.Join(storeInfo, ","))
|
||||
}
|
||||
}
|
||||
err = fmt.Errorf("门店%d已经被其它门店(%s)关联,不能再关联至其它门店", storeID, strings.Join(storeInfo, ","))
|
||||
}
|
||||
}
|
||||
return err
|
||||
@@ -1045,10 +1049,8 @@ 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 {
|
||||
return 0, err
|
||||
}
|
||||
if err = checkStoreHaveLinkedStore(storeExt.ID, realLinkStoreID); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
storeExt.LinkStoreID = realLinkStoreID
|
||||
|
||||
|
||||
Reference in New Issue
Block a user