add分类三级
This commit is contained in:
@@ -112,8 +112,8 @@ func GetCategories(ctx *jxcontext.Context, parentID int, isExd bool) (catList []
|
||||
|
||||
func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
|
||||
db := dao.GetDB()
|
||||
if cat.Level < 0 || cat.Level > 2 {
|
||||
return nil, errors.New("Level必须为1或2")
|
||||
if cat.Level < 0 || cat.Level > 3 {
|
||||
return nil, errors.New("Level必须为1或2,3")
|
||||
} else if cat.Level == 1 && cat.ParentID != 0 {
|
||||
return nil, errors.New("Level1的分类其父分类必须为0")
|
||||
} else if cat.Level == 2 {
|
||||
@@ -128,6 +128,18 @@ func AddCategory(ctx *jxcontext.Context, cat *model.SkuCategory, userName string
|
||||
if parentCat.Level != 1 {
|
||||
return nil, errors.New("Level2的分类其父分类必须为Level1分类")
|
||||
}
|
||||
} else if cat.Level == 3 {
|
||||
if cat.ParentID == 0 {
|
||||
return nil, errors.New("Level3的分类其父分类必须不为0")
|
||||
}
|
||||
parentCat := &model.SkuCategory{}
|
||||
parentCat.ID = cat.ParentID
|
||||
if err = dao.GetEntity(db, parentCat); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if parentCat.Level != 2 {
|
||||
return nil, errors.New("Level3的分类其父分类必须为Level2分类")
|
||||
}
|
||||
}
|
||||
|
||||
dao.WrapAddIDCULDEntity(cat, userName)
|
||||
|
||||
Reference in New Issue
Block a user