- sku category.

This commit is contained in:
gazebo
2018-09-10 07:47:18 +08:00
parent d8907cf010
commit ce56d774a2
5 changed files with 82 additions and 21 deletions

View File

@@ -3,6 +3,7 @@ package cms
import (
"errors"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/business/jxutils"
"git.rosy.net.cn/jx-callback/business/model"
"git.rosy.net.cn/jx-callback/business/model/dao"
@@ -13,11 +14,14 @@ var (
)
// parentID 为-1表示所有
func GetVendorCategories(vendorID int, parentID int) (cats []*model.SkuVendorCategory, err error) {
if parentID == -1 {
return cats, dao.GetRows(nil, &cats, "SELECT * FROM sku_vendor_category WHERE vendor_id = ?", vendorID)
func GetVendorCategories(vendorID int, parentID int) (vendorCats []*model.SkuVendorCategory, err error) {
cond := map[string]interface{}{
"VendorID": vendorID,
}
return cats, dao.GetRows(nil, &cats, "SELECT * FROM sku_vendor_category WHERE vendor_id = ? AND parent_id = ?", vendorID, parentID)
if parentID != -1 {
cond["ParentID"] = parentID
}
return vendorCats, dao.GetEntities(nil, &vendorCats, cond, false)
}
func GetSkuMetaInfo() (*model.SkuMetaInfo, error) {
@@ -30,14 +34,15 @@ func GetSkuMetaInfo() (*model.SkuMetaInfo, error) {
// parentID 为-1表示所有
func GetCategories(parentID int) (cats []*model.SkuCategory, err error) {
if parentID == -1 {
return cats, dao.GetRows(nil, &cats, "SELECT * FROM sku_category")
return cats, dao.GetEntities(nil, &cats, nil, false)
}
return cats, dao.GetRows(nil, &cats, "SELECT * FROM sku_category WHERE parent_id = ?", parentID)
return cats, dao.GetEntities(nil, &cats, utils.Params2Map("ParentID", parentID), false)
}
func AddCategory(cat *model.SkuCategory, userName string) (outCat *model.SkuCategory, err error) {
cat.ID = 0
cat.JdSyncStatus = model.SyncFlagNewMask
cat.DeletedAt = utils.DefaultTimeValue
if err = dao.CreateEntity(nil, cat); err == nil {
outCat = cat
err = CurVendorSync.SyncCategory(cat.ID, false, userName)
@@ -63,7 +68,7 @@ func ReorderCategories(parentID int, categoryIDs []int, userName string) (err er
parentCat.ID = parentID
db := dao.GetDB()
if err = dao.GetEntity(db, parentCat); err == nil {
if err = dao.GetRows(db, &cats, "SELECT * FROM sku_category WHERE parent_id = ?", parentID); err == nil {
if err = dao.GetEntities(db, &cats, utils.Params2Map("ParentID", parentID), false); err == nil {
catsLen := len(cats)
if catsLen != len(categoryIDs) {
return ErrInputCatsDoesntMatch
@@ -86,3 +91,9 @@ func ReorderCategories(parentID int, categoryIDs []int, userName string) (err er
}
return err
}
func DeleteCategory(categoryID int, isForce bool, userName string) (num int64, err error) {
cat := &model.SkuCategory{}
cat.ID = categoryID
return dao.DeleteEntity(nil, cat, nil, userName)
}