xiziwen 4 dagen geleden
bovenliggende
commit
8f59ddf5f6
1 gewijzigde bestanden met toevoegingen van 26 en 23 verwijderingen
  1. 26 23
      services/data/base_from_clarksons.go

+ 26 - 23
services/data/base_from_clarksons.go

@@ -217,19 +217,22 @@ func EditClarksonsIndex(indexId, classifyId int) (baseFromClarksonsIndex *data_m
 		}
 		return
 	}
-	classify, err := data_manage.GetClarksonsClassifyById(classifyId)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			errMsg = `该分类不存在或已删除`
+	if classifyId > 0 {
+		classify, err := data_manage.GetClarksonsClassifyById(classifyId)
+		if err != nil {
+			if err.Error() == utils.ErrNoRow() {
+				errMsg = `该分类不存在或已删除`
+				err = nil
+			}
+			return
+		}
+		if classify.Level == 1 { // 顶级分类
+			errMsg = `不合法的编辑`
 			err = nil
+			return
 		}
-		return
-	}
-	if classify.Level == 1 { // 顶级分类
-		errMsg = `不合法的编辑`
-		err = nil
-		return
 	}
+
 	maxSort, err := data_manage.GetChildClarksonsClassifyMaxSortById(classifyId)
 	if err != nil {
 		return
@@ -304,23 +307,23 @@ func MoveClarksonsClassify(classifyId, parentClassifyId, prevClassifyId, nextCla
 		return
 	}
 
-	// 校验移动的父级目录下是否有重名分类
-	count, e := data_manage.GetBaseFromClarksonsClassifyCount(classifyInfo.ClassifyName, parentClassifyId)
-	if e != nil && e.Error() != utils.ErrNoRow() {
-		errMsg = "移动失败"
-		err = errors.New("获取父级目录下的同名分类失败, Err: " + e.Error())
-		return
-	}
-	if count > 0 {
-		errMsg = "移动失败,分类名称已存在"
-		err = errors.New("该父级目录下已存在同名分类,请重新命名")
-		return
-	}
-
 	updateCol := make([]string, 0)
 
 	//判断上级id是否一致,如果不一致的话,那么需要移动该分类层级
 	if classifyInfo.ParentId != parentClassifyId && parentClassifyId != 0 {
+		// 校验移动的父级目录下是否有重名分类
+		count, e := data_manage.GetBaseFromClarksonsClassifyCount(classifyInfo.ClassifyName, parentClassifyId)
+		if e != nil && e.Error() != utils.ErrNoRow() {
+			errMsg = "移动失败"
+			err = errors.New("获取父级目录下的同名分类失败, Err: " + e.Error())
+			return
+		}
+		if count > 0 {
+			errMsg = "移动失败,分类名称已存在"
+			err = errors.New("该父级目录下已存在同名分类,请重新命名")
+			return
+		}
+
 		parentClassifyInfo, tmpErr := data_manage.GetClarksonsClassifyById(parentClassifyId)
 		if tmpErr != nil {
 			errMsg = "移动失败"