From 51713e54be4b7f4b205ed542ebe151bc2e81ffa0 Mon Sep 17 00:00:00 2001 From: gazebo Date: Thu, 30 May 2019 17:01:52 +0800 Subject: [PATCH] =?UTF-8?q?-=20mtwm.RetailGet=E4=B8=8Eebai.SkuList?= =?UTF-8?q?=E7=94=A8struct=E6=9B=BF=E6=8D=A2map?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/shop_sku.go | 88 ++++++++++++++++++++++------ platformapi/ebaiapi/shop_sku_test.go | 12 ++-- platformapi/mtwmapi/retail.go | 59 ++++++++++++++++++- platformapi/mtwmapi/retail_test.go | 12 +++- 4 files changed, 142 insertions(+), 29 deletions(-) diff --git a/platformapi/ebaiapi/shop_sku.go b/platformapi/ebaiapi/shop_sku.go index c1113fa5..30c27568 100644 --- a/platformapi/ebaiapi/shop_sku.go +++ b/platformapi/ebaiapi/shop_sku.go @@ -9,8 +9,9 @@ import ( ) const ( - SkuStatusOnline = 1 - SkuStatusOffline = 0 + SkuStatusOnline = 1 // 为上架 + SkuStatusOffline = 0 // 为下架 + SkuStatusDeleted = 2 // 为删除 ) const ( @@ -29,11 +30,67 @@ type CategoryInfo struct { Level int `json:"level"` } +type SkuListParams struct { + Page int `json:"page,omitempty"` + PageSize int `json:"pagesize,omitempty"` + Upc string `json:"upc,omitempty"` + SkuID int64 `json:"sku_id,omitempty"` + CustomSkuID string `json:"custom_sku_id,omitempty"` + UpcType int `json:"upc_type,omitempty"` + GetUncate int `json:"get_uncate,omitempty"` + Delete int `json:"delete,omitempty"` + Enabled int `json:"enabled,omitempty"` + StartTime int `json:"start_time,omitempty"` + EndTime int `json:"end_time,omitempty"` +} + +type SkuPhotoInfo struct { + IsMaster int `json:"is_master"` + URL string `json:"url"` +} + +type SkuCustomCatInfo struct { + CustomCatID string `json:"custom_cat_id"` + CustomCatName string `json:"custom_cat_name"` +} + +type SkuInfo struct { + CustomCatIDs string `json:"custom_cat_ids"` + CustomCatList []*SkuCustomCatInfo `json:"custom_cat_list"` + CustomSkuID string `json:"custom_sku_id"` + IsInActivity int `json:"is_in_activity"` + LeftNum int `json:"left_num"` + MarketPrice int `json:"market_price"` + Minimum int `json:"minimum"` + Name string `json:"name"` + NeedIce int `json:"need_ice"` + Photos []*SkuPhotoInfo `json:"photos"` + PreminusWeight int `json:"preminus_weight"` + PreparationTime string `json:"preparation_time"` + ProductionAddr1 string `json:"production_addr1"` + ProductionAddr2 string `json:"production_addr2"` + ProductionAddr3 string `json:"production_addr3"` + Rtf string `json:"rtf"` + SalePrice int64 `json:"sale_price"` + SaleStep string `json:"sale_step"` + SaleUnit string `json:"sale_unit"` + ShelfNumber string `json:"shelf_number"` + SkuID int64 `json:"sku_id"` + // SkuProperty []interface{} `json:"sku_property"` + Status int `json:"status"` + Summary string `json:"summary"` + Upc string `json:"upc"` + UpcType string `json:"upc_type"` + UpdateTime string `json:"update_time"` + Weight int `json:"weight"` + WeightFlag int `json:"weight_flag"` +} + type PageDataInfo struct { - Total int - Page int - Pages int - List []map[string]interface{} + Total int `json:"Total"` + Page int `json:"Page"` + Pages int `json:"Pages"` + List []*SkuInfo `json:"List"` } var ( @@ -114,21 +171,14 @@ func (a *API) SkuGetItemsByCategoryId(shopID string, categoryID int64) (skus []m return nil, err } -func (a *API) SkuList(shopID string, params map[string]interface{}) (skuInfo *PageDataInfo, err error) { - defParams := map[string]interface{}{ - KeyShopID: shopID, - } - result, err := a.AccessAPI("sku.list", utils.MergeMaps(params, defParams)) +func (a *API) SkuList(shopID string, params *SkuListParams) (skuInfo *PageDataInfo, err error) { + paramMap := utils.Struct2FlatMap(params) + paramMap[KeyShopID] = shopID + result, err := a.AccessAPI("sku.list", paramMap) if err == nil { - data := result.Data.(map[string]interface{}) - return &PageDataInfo{ - Total: int(utils.MustInterface2Int64(data["total"])), - Page: int(utils.MustInterface2Int64(data["page"])), - Pages: int(utils.MustInterface2Int64(data["pages"])), - List: utils.Slice2MapSlice(data["list"].([]interface{})), - }, nil + err = utils.Map2StructByJson(result.Data, &skuInfo, true) } - return nil, err + return skuInfo, err } func (a *API) SkuCreate(shopID string, customSkuID int, params map[string]interface{}) (skuID int64, err error) { diff --git a/platformapi/ebaiapi/shop_sku_test.go b/platformapi/ebaiapi/shop_sku_test.go index f69040f1..501250ff 100644 --- a/platformapi/ebaiapi/shop_sku_test.go +++ b/platformapi/ebaiapi/shop_sku_test.go @@ -48,9 +48,8 @@ func TestSkuGetItemsByCategoryId(t *testing.T) { } func TestSkuList(t *testing.T) { - result, err := api.SkuList(testShopID, map[string]interface{}{ - KeySkuID: 15579787500720732, - // "delete": 1, + result, err := api.SkuList(testShopID, &SkuListParams{ + SkuID: 15579787500720732, }) if err != nil { t.Fatal(err) @@ -94,9 +93,12 @@ func TestSkuCreate(t *testing.T) { } func TestSkuUpdate(t *testing.T) { - result, err := api.SkuUpdate("2", 15579787500720732, map[string]interface{}{ + // 15579787500720732 高级 + + result, err := api.SkuUpdate("2", 1557043939079105, map[string]interface{}{ // "name": "高级商品2015a333约1100g/份", - "rtf": "http://www.rosy.net.cn/rtf.html", + // "rtf": "http://www.rosy.net.cn/rtf.html", + "shelf_number": 12, }) if err != nil { t.Fatal(err) diff --git a/platformapi/mtwmapi/retail.go b/platformapi/mtwmapi/retail.go index aec116c1..9790068e 100644 --- a/platformapi/mtwmapi/retail.go +++ b/platformapi/mtwmapi/retail.go @@ -31,6 +31,57 @@ type BareStoreFoodInfo struct { Skus []*BareStoreSkuInfo `json:"skus"` } +type AvailableTimesInfo struct { + Friday string `json:"friday"` + Monday string `json:"monday"` + Saturday string `json:"saturday"` + Sunday string `json:"sunday"` + Thursday string `json:"thursday"` + Tuesday string `json:"tuesday"` + Wednesday string `json:"wednesday"` +} + +type SkuInfo struct { + AvailableTimes *AvailableTimesInfo `json:"available_times"` + BoxNum string `json:"box_num"` + BoxPrice string `json:"box_price"` + LocationCode string `json:"location_code"` + Price string `json:"price"` + SkuID string `json:"sku_id"` + Spec string `json:"spec"` + Stock string `json:"stock"` + Upc string `json:"upc"` + Weight int `json:"weight"` +} + +type AppFood struct { + AppFoodCode string `json:"app_food_code"` + AppPoiCode string `json:"app_poi_code"` + BoxNum float64 `json:"box_num"` + BoxPrice float64 `json:"box_price"` + CategoryCode string `json:"category_code"` + CategoryName string `json:"category_name"` + Ctime int `json:"ctime"` + Description string `json:"description"` + IsSp int `json:"isSp"` + IsSoldOut int `json:"is_sold_out"` + IsSpecialty int `json:"is_specialty"` + MinOrderCount int `json:"min_order_count"` + Name string `json:"name"` + Picture string `json:"picture"` + PictureContents string `json:"picture_contents"` + Price float64 `json:"price"` + SecondaryCategoryCode string `json:"secondary_category_code"` + SecondaryCategoryName string `json:"secondary_category_name"` + Sequence int `json:"sequence"` + Skus string `json:"skus"` + SkuList []*SkuInfo `json:"skuList"` + TagID int `json:"tag_id"` + Unit string `json:"unit"` + Utime int `json:"utime"` + ZhName string `json:"zh_name"` +} + // 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名 // name(和originName)的长度不能超过10个字符(字符,不是字节) // 创建一级分类,originName为空,name为新分类名,secondaryName为空 @@ -127,15 +178,17 @@ func (a *API) RetailSkuStock(poiCode string, foodData []*BareStoreFoodInfo) (err return err } -func (a *API) RetailGet(poiCode, foodCode string) (food map[string]interface{}, err error) { +func (a *API) RetailGet(poiCode, foodCode string) (food *AppFood, err error) { result, err := a.AccessAPI("retail/get", true, map[string]interface{}{ KeyAppPoiCode: poiCode, KeyAppFoodCode: foodCode, }) if err == nil { - return result.(map[string]interface{}), nil + if err = utils.Map2StructByJson(result, &food, true); err == nil && food.Skus != "" { + err = utils.UnmarshalUseNumber([]byte(food.Skus), &food.SkuList) + } } - return nil, err + return food, err } func (a *API) RetailSkuSave(poiCode, foodCode string, standardSkus, unstandardSkus []map[string]interface{}) (err error) { diff --git a/platformapi/mtwmapi/retail_test.go b/platformapi/mtwmapi/retail_test.go index a81c8cdc..09704e74 100644 --- a/platformapi/mtwmapi/retail_test.go +++ b/platformapi/mtwmapi/retail_test.go @@ -47,7 +47,15 @@ func TestRetailList(t *testing.T) { if len(result) == 0 { t.Fatal("should have items") } - // t.Log(utils.Format4Output(result, false)) + t.Log(utils.Format4Output(result, false)) +} + +func TestRetailGet(t *testing.T) { + result, err := api.RetailGet(testPoiCode, "5246") + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) } func TestRetailGetSpTagIds(t *testing.T) { @@ -69,7 +77,7 @@ func TestRetailCatSkuBatchDelete(t *testing.T) { } func TestRetailDelete(t *testing.T) { - err := api.RetailDelete(testPoiCode, "") + err := api.RetailDelete(testPoiCode, "614") if err != nil { t.Fatal(err) }