Browse Source

新增一级分类设置顶级ID

xyxie 1 year ago
parent
commit
b720d110e5
1 changed files with 11 additions and 1 deletions
  1. 11 1
      services/data/edb_classify.go

+ 11 - 1
services/data/edb_classify.go

@@ -297,10 +297,20 @@ func AddEdbClassify(classifyName string, parentId, level int, classifyType uint8
 		UniqueCode:      utils.MD5(utils.DATA_PREFIX + "_" + timestamp),
 		Sort:            maxSort + 1,
 	}
-	_, err = data_manage.AddEdbClassify(classifyInfo)
+	newId, err := data_manage.AddEdbClassify(classifyInfo)
 	if err != nil {
 		errMsg = "保存分类失败"
+		return
+	}
+	if parentId == 0 { //一级目录的rootId等于自己本身
+		classifyInfo.RootId = int(newId)
+		err = classifyInfo.Update([]string{"RootId"})
+		if err != nil {
+			errMsg = "更新分类失败"
+			return
+		}
 	}
+
 	return
 }