- remove nonexistent field shop_custom_id in ShopCategoryCreate and ShopCategoryUpdate

This commit is contained in:
gazebo
2019-01-31 16:57:11 +08:00
parent a7c8658160
commit 335162d99a
2 changed files with 18 additions and 22 deletions

View File

@@ -18,12 +18,11 @@ const (
)
type CategoryInfo struct {
CategoryID int64 `json:"category_id"`
ShopCustomID string `json:"shop_custom_id"`
Name string `json:"name"`
Rank int `json:"rank"` // 店内分类独有
Children []*CategoryInfo `json:"children"`
Level int `json:"level"`
CategoryID int64 `json:"category_id"`
Name string `json:"name"`
Rank int `json:"rank"` // 店内分类独有
Children []*CategoryInfo `json:"children"`
Level int `json:"level"`
}
type PageDataInfo struct {
@@ -35,13 +34,12 @@ type PageDataInfo struct {
// category相关的函数shop_custom_id可重
func (a *API) ShopCategoryCreate(shopID string, parentID int64, name string, rank int, shopCustomID string) (catID int64, err error) {
func (a *API) ShopCategoryCreate(shopID string, parentID int64, name string, rank int) (catID int64, err error) {
result, err := a.AccessAPI("sku.shop.category.create", map[string]interface{}{
KeyShopID: shopID,
"parent_category_id": parentID,
"name": name,
"rank": rank,
"shop_custom_id": shopCustomID,
})
if err == nil {
return utils.Str2Int64(utils.Interface2String(result.Data.(map[string]interface{})["category_id"])), nil
@@ -60,13 +58,12 @@ func (a *API) ShopCategoryGet(shopID string) (cats []*CategoryInfo, err error) {
return nil, err
}
func (a *API) ShopCategoryUpdate(shopID string, categoryID int64, name string, rank int, shopCustomID string) (err error) {
func (a *API) ShopCategoryUpdate(shopID string, categoryID int64, name string, rank int) (err error) {
_, err = a.AccessAPI("sku.shop.category.update", map[string]interface{}{
KeyShopID: shopID,
"category_id": categoryID,
"name": name,
"rank": rank,
"shop_custom_id": shopCustomID,
KeyShopID: shopID,
"category_id": categoryID,
"name": name,
"rank": rank,
})
if errWithCode, ok := err.(*utils.ErrorWithCode); ok {
if errWithCode.Level() == 0 && errWithCode.IntCode() == 1 { //忽略同名错误
@@ -224,12 +221,11 @@ func interface2CatList(data interface{}, level int) (cats []*CategoryInfo) {
func interface2Cat(data interface{}, level int) (cat *CategoryInfo) {
catMap := data.(map[string]interface{})
cat = &CategoryInfo{
CategoryID: utils.MustInterface2Int64(catMap["category_id"]),
ShopCustomID: utils.Interface2String(catMap["shop_custom_id"]),
Name: utils.Interface2String(catMap["name"]),
Rank: int(utils.MustInterface2Int64(catMap["rank"])),
Children: interface2CatList(catMap["children"], level+1),
Level: level,
CategoryID: utils.MustInterface2Int64(catMap["category_id"]),
Name: utils.Interface2String(catMap["name"]),
Rank: int(utils.MustInterface2Int64(catMap["rank"])),
Children: interface2CatList(catMap["children"], level+1),
Level: level,
}
return cat
}

View File

@@ -7,7 +7,7 @@ import (
)
func TestShopCategoryCreate(t *testing.T) {
result, err := api.ShopCategoryCreate(testShopID, 0, "绿色蔬菜", 16, "16")
result, err := api.ShopCategoryCreate(testShopID, 0, "绿色蔬菜", 16)
if err != nil {
t.Fatal(err)
} else {
@@ -25,7 +25,7 @@ func TestShopCategoryGet(t *testing.T) {
}
func TestShopCategoryUpdate(t *testing.T) {
err := api.ShopCategoryUpdate(testShopID, 153760204017121, "水果2", 2, "2")
err := api.ShopCategoryUpdate(testShopID, 153760204017121, "水果2", 2)
if err != nil {
t.Fatal(err)
}