From c5b0e1a847800ad3625a565f4890afdc38efedac Mon Sep 17 00:00:00 2001 From: gazebo Date: Mon, 14 Oct 2019 18:41:56 +0800 Subject: [PATCH] =?UTF-8?q?mtwmapi=E7=94=B1RetailSellStatus=E5=8F=96?= =?UTF-8?q?=E4=BB=A3RetailSkuSellStatus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/dadaapi/dadaapi.go | 4 +-- platformapi/mtwmapi/order.go | 2 ++ platformapi/mtwmapi/retail.go | 31 ++++++++++++++++++++++ platformapi/mtwmapi/retail_test.go | 41 ++++++++++++++++++++++++++++-- 4 files changed, 74 insertions(+), 4 deletions(-) diff --git a/platformapi/dadaapi/dadaapi.go b/platformapi/dadaapi/dadaapi.go index 00901b4a..7d4a6994 100644 --- a/platformapi/dadaapi/dadaapi.go +++ b/platformapi/dadaapi/dadaapi.go @@ -12,8 +12,8 @@ import ( ) const ( - sandboxURL = "http://newopen.qa.imdada.cn" - prodURL = "http://newopen.imdada.cn" + sandboxURL = "https://newopen.qa.imdada.cn" + prodURL = "https://newopen.imdada.cn" signKey = "signature" ) diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index 803ee838..11652927 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -154,6 +154,7 @@ type FoodInfo struct { SkuID string `json:"sku_id"` Spec string `json:"spec"` Unit string `json:"unit"` + Weight int64 `json:"weight"` } type CanRefundFoodInfo struct { @@ -261,6 +262,7 @@ type OrderInfo struct { Status int `json:"status"` TaxpayerID string `json:"taxpayer_id"` Total float64 `json:"total"` + TotalWeight int64 `json:"total_weight"` Utime int64 `json:"utime"` WmOrderIDView int64 `json:"wm_order_id_view"` WmPoiAddress string `json:"wm_poi_address"` diff --git a/platformapi/mtwmapi/retail.go b/platformapi/mtwmapi/retail.go index fe3249ff..76264033 100644 --- a/platformapi/mtwmapi/retail.go +++ b/platformapi/mtwmapi/retail.go @@ -106,6 +106,11 @@ type AppFoodResult struct { ErrorMsg string `json:"error_msg"` } +type AppFoodResult4SellStatus struct { + AppFoodCode string `json:"appFoodCode"` + Msg string `json:"msg"` +} + // 美团分类没有ID,就以名字为唯一标识,不论级别都必须不能重名 // name(和originName)的长度不能超过10个字符(字符,不是字节) // 创建一级分类,originName为空,name为新分类名,secondaryName为空 @@ -243,6 +248,9 @@ func (a *API) RetailSkuStock(trackInfo, poiCode string, foodData []*BareStoreFoo } // retail/sku/sellStatus在部分失败时会返回错误,其它相应的批处理函数则会返回成功 +// 此接口已准备废弃 +// 2019年9月17日开放平台已上线新接口【retail/sellStatus】,用于零售类商家批量更新商品售卖状态。请已接入老接口(retail/sku/sellStatus)的开发者在2019年10月31日前完成接口迁移,使用新接口的请求地址https://waimaiopen.meituan.com/api/v1/retail/sellStatus。 +// 开放平台将于2019年11月1日开始全面下线老接口(retail/sku/sellStatus),如开发者逾期未完成接口迁移,调用老接口失败所造成的相关问题或损失由商家自行承担。 func (a *API) RetailSkuSellStatus(trackInfo, poiCode string, foodData []*BareStoreFoodInfo, sellStatus int) (failedFoodList []*AppFoodResult, err error) { _, err = a.AccessAPI2("retail/sku/sellStatus", false, map[string]interface{}{ KeyAppPoiCode: poiCode, @@ -257,6 +265,29 @@ func (a *API) RetailSkuSellStatus(trackInfo, poiCode string, foodData []*BareSto return failedFoodList, err } +// 此接口部分失败也返回成功,但错误消息格式(errorMsg, appFoodCode)与其它两个不一样 +func (a *API) RetailSellStatus(trackInfo, poiCode string, foodData []*BareStoreFoodInfo, sellStatus int) (failedFoodList []*AppFoodResult, err error) { + result, err := a.AccessAPI2("retail/sellStatus", false, map[string]interface{}{ + KeyAppPoiCode: poiCode, + "food_data": string(utils.MustMarshal(foodData)), + "sell_status": sellStatus, + }, resultKeyMsg, trackInfo) + if err == nil { + var tmpFailedFoodList []*AppFoodResult4SellStatus + if msg, ok := result.(string); ok && msg != "" { + if err = utils.UnmarshalUseNumber([]byte(msg), &tmpFailedFoodList); err == nil { + for _, v := range tmpFailedFoodList { + failedFoodList = append(failedFoodList, &AppFoodResult{ + AppFoodCode: v.AppFoodCode, + ErrorMsg: v.Msg, + }) + } + } + } + } + return failedFoodList, err +} + func (a *API) RetailGet(poiCode, foodCode string) (food *AppFood, err error) { result, err := a.AccessAPI("retail/get", true, map[string]interface{}{ KeyAppPoiCode: poiCode, diff --git a/platformapi/mtwmapi/retail_test.go b/platformapi/mtwmapi/retail_test.go index 7e1e9913..e6bbb9e2 100644 --- a/platformapi/mtwmapi/retail_test.go +++ b/platformapi/mtwmapi/retail_test.go @@ -168,10 +168,10 @@ func TestRetailSkuPrice(t *testing.T) { func TestRetailSkuStock(t *testing.T) { result, err := api.RetailSkuStock(utils.GetUUID(), testPoiCode, []*BareStoreFoodInfo{ &BareStoreFoodInfo{ - AppFoodCode: "23841", + AppFoodCode: "2212", Skus: []*BareStoreSkuInfo{ &BareStoreSkuInfo{ - SkuID: "23841", + SkuID: "2212", Price: "1.2", Stock: "123", }, @@ -229,3 +229,40 @@ func TestRetailSkuSellStatus(t *testing.T) { } t.Log(utils.Format4Output(result, false)) } + +func TestRetailSellStatus(t *testing.T) { + result, err := api.RetailSellStatus(utils.GetUUID(), testPoiCode, []*BareStoreFoodInfo{ + &BareStoreFoodInfo{ + AppFoodCode: "2212", + Skus: []*BareStoreSkuInfo{ + &BareStoreSkuInfo{ + SkuID: "2212", + Price: "1.2", + Stock: "123", + }, + }, + }, + &BareStoreFoodInfo{ + AppFoodCode: "23840", + Skus: []*BareStoreSkuInfo{ + &BareStoreSkuInfo{ + SkuID: "23840", + Stock: "123", + }, + }, + }, + &BareStoreFoodInfo{ + AppFoodCode: "2384999", + Skus: []*BareStoreSkuInfo{ + &BareStoreSkuInfo{ + SkuID: "2384999", + Stock: "123", + }, + }, + }, + }, SellStatusOnline) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) +}