diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index bba90516..cf7b1b5c 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -10,9 +10,12 @@ const ( SkuStatusOffline = 0 ) +const ( + UPCTypeStandard = 1 + UPCTypePrivate = 0 +) const ( MaxLeftNum = 9999 - DefUPC = 12345678 ) type CategoryInfo struct { @@ -109,13 +112,17 @@ func (a *API) SkuList(shopID string, params map[string]interface{}) (skuInfo *Pa return nil, err } -func (a *API) SkuCreate(shopID string, params map[string]interface{}) (skuID int64, err error) { +func (a *API) SkuCreate(shopID string, customSkuID int, params map[string]interface{}) (skuID int64, err error) { defParams := map[string]interface{}{ - KeyShopID: shopID, - } - if params["upc"] == nil { - defParams["upc"] = DefUPC + KeyShopID: shopID, + "custom_sku_id": customSkuID, + "upc_type": UPCTypePrivate, + "upc": customSkuID, + "brand_name": "京西菜市", } + // if params["upc"] == nil { + // defParams["upc"] = "upc-" + utils.Int2Str(customSkuID) + // } if params["brand_id"] == nil { defParams["brand_id"] = 0 } diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index ac0e5d88..32f93e6a 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -57,13 +57,21 @@ func TestSkuList(t *testing.T) { } func TestSkuCreate(t *testing.T) { - result, err := api.SkuCreate(testShopID, map[string]interface{}{ - "name": "测试商品", - "status": SkuStatusOnline, - "left_num": MaxLeftNum, - "sale_price": 100, - "market_price": 100, - "custom_sku_id": 1, + result, err := api.SkuCreate(testShopID, 114, map[string]interface{}{ + "name": "测试商品", + "status": SkuStatusOnline, + "left_num": MaxLeftNum, + "sale_price": 100, + "market_price": 100, + "cat1_id": 151301831158987, + "cat2_id": 15347484581335, + "cat3_id": 15347484581339, + "photos": []map[string]interface{}{ + map[string]interface{}{ + "is_master": true, + "url": "http://image.jx.scaqda.com/8536c76779333f53517006f88ea7174c.jpg?imageView2/1/w/80/h/80", + }, + }, }) if err != nil { t.Fatal(err) diff --git a/platformapi/ebaiapi/sku.go b/platformapi/ebaiapi/sku.go index 534b6a63..c79eafb5 100644 --- a/platformapi/ebaiapi/sku.go +++ b/platformapi/ebaiapi/sku.go @@ -1,6 +1,13 @@ package ebaiapi -import "git.rosy.net.cn/baseapi/utils" +import ( + "git.rosy.net.cn/baseapi/utils" +) + +type BrandInfo struct { + BrandID int64 `json:"brand_id"` + BrandName string `json:"brand_name"` +} func (a *API) SkuCategoryList(keyword string, depth int, parentID int64) (cats []interface{}, err error) { result, err := a.AccessAPI("sku.category.list", map[string]interface{}{ @@ -13,3 +20,26 @@ func (a *API) SkuCategoryList(keyword string, depth int, parentID int64) (cats [ } return nil, err } + +// pageNo页,从1开始 +func (a *API) SkuBrandList(keyword string, pageNo int) (brands []*BrandInfo, err error) { + result, err := a.AccessAPI("sku.brand.list", map[string]interface{}{ + "keyword": keyword, + "page": pageNo, + }) + if err == nil { + // baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) + brs := result.Data.(map[string]interface{}) + detail := brs["detail"].([]interface{}) + brands = make([]*BrandInfo, len(detail)) + for k, v := range detail { + brandMap := v.(map[string]interface{}) + brands[k] = &BrandInfo{ + BrandID: utils.MustInterface2Int64(brandMap["brand_id"]), + BrandName: utils.Interface2String(brandMap["brand_name"]), + } + } + return brands, nil + } + return nil, err +} diff --git a/platformapi/ebaiapi/sku_test.go b/platformapi/ebaiapi/sku_test.go index 46d40620..ce68dc77 100644 --- a/platformapi/ebaiapi/sku_test.go +++ b/platformapi/ebaiapi/sku_test.go @@ -7,7 +7,16 @@ import ( ) func TestSkuCategoryList(t *testing.T) { - result, err := api.SkuCategoryList("", 1, 0) + result, err := api.SkuCategoryList("", 3, 1491490798176) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + +func TestSkuBrandList(t *testing.T) { + result, err := api.SkuBrandList("", 1) if err != nil { t.Fatal(err) } else {