diff --git a/platformapi/jdapi/sku_test.go b/platformapi/jdapi/sku_test.go index 797744f9..9ad68100 100644 --- a/platformapi/jdapi/sku_test.go +++ b/platformapi/jdapi/sku_test.go @@ -58,12 +58,12 @@ func TestBatchUpdateOutSkuId(t *testing.T) { func TestQuerySkuInfos(t *testing.T) { pageSize := 20 - result, totalCount, err := api.QuerySkuInfos("", 0, 0, pageSize, true) + result, totalCount, err := api.QuerySkuInfos("一个高级商品", 0, 0, pageSize, true) if err != nil { t.Fatal(err) } if len(result) != pageSize || totalCount == 0 { - baseapi.SugarLogger.Debug(result) + baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) t.Fatalf("QuerySkuInfos result size is not same as requested:%d", pageSize) } } diff --git a/platformapi/jdapi/store_sku.go b/platformapi/jdapi/store_sku.go index af6342ea..f8648a8a 100644 --- a/platformapi/jdapi/store_sku.go +++ b/platformapi/jdapi/store_sku.go @@ -41,6 +41,38 @@ type SkuIdEntity struct { OutSkuId string `json:"outSkuId"` } +type StorePriceInfo struct { + MarketPrice int64 `json:"marketPrice"` + Pin string `json:"pin"` + Price int64 `json:"price"` + PromoteVipPrice int64 `json:"promoteVipPrice"` + SkuID int64 `json:"skuId"` + StationNo string `json:"stationNo"` + VenderID string `json:"venderId"` + VipPrice int64 `json:"vipPrice"` +} + +type QueryStockResponse struct { + SkuID int64 `json:"skuId"` + StationNo string `json:"stationNo"` + UsableQty int `json:"usableQty"` + LockQty int `json:"lockQty"` + OrderQty int `json:"orderQty"` + Vendibility int `json:"vendibility"` +} + +type UpdateVendibilityResponse struct { + Code int `json:"code"` + CurrentQty int `json:"currentQty"` + LockQty int `json:"lockQty"` + Msg string `json:"msg"` + OrderQty int `json:"orderQty"` + OutSkuID string `json:"outSkuId"` + SkuID int64 `json:"skuId"` + UsableQty int `json:"usableQty"` + Vendibility int `json:"vendibility"` +} + // 传入为数组的,最多一次为50个 // 有好些功能有两个类似的函数,一个为到家ID,一个为商家ID,建议都只用商家ID的那个,因为: // 1,这类函数一般可以批量操作 @@ -85,16 +117,16 @@ func (a *API) UpdateStationPrice(skuId int64, stationNo string, price int) (stri // 根据到家商品编码和到家门店编码批量查询商品门店价格信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=21ccd5a00d3a4582b4c9a8ef0ae238fc -func (a *API) GetStationInfoList(stationNo string, skuIds []int64) ([]map[string]interface{}, error) { +func (a *API) GetStationInfoList(stationNo string, skuIds []int64) (priceInfo []*StorePriceInfo, err error) { jdParams := map[string]interface{}{ "skuIds": skuIds, "stationNo": stationNo, } - result, err := a.AccessAPINoPage("price/getStationInfoList", jdParams, nil, nil, nil) + result, err := a.AccessAPINoPage("price/getStationInfoList", jdParams, nil, nil, genNoPageResultParser("code", "detail", "result", "0")) if err == nil && result != nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + err = utils.Map2StructByJson(result, &priceInfo, false) } - return nil, err + return priceInfo, err } // 根据商家商品编码和商家门店编码批量修改现货库存接口 @@ -174,20 +206,20 @@ func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendib // 根据到家商品编码和门店编码批量查询商品库存及可售状态信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=bc6ad75e8fd34580856e06b5eb149aad // 尽量不用这个接口,用下面那个 -func (a *API) QueryOpenUseable(listBaseStockCenterRequest []*BaseStockCenterRequest) ([]map[string]interface{}, error) { +func (a *API) QueryOpenUseable(listBaseStockCenterRequest []*BaseStockCenterRequest) (stockResponse []*QueryStockResponse, err error) { jdParams := map[string]interface{}{ "listBaseStockCenterRequest": listBaseStockCenterRequest, } result, err := a.AccessAPINoPage("stock/queryOpenUseable", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0")) if err == nil && result != nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + err = utils.Map2StructByJson(result, &stockResponse, false) } - return nil, err + return stockResponse, err } // 根据商家商品编码和门店编码批量查询商品库存及可售状态信息接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=ba70316bb84f425f8c088d3c19b2570d -func (a *API) QueryStockCenter(outStationNo string, skuIds []*SkuIdEntity, userPin string) ([]map[string]interface{}, error) { +func (a *API) QueryStockCenter(outStationNo string, skuIds []*SkuIdEntity, userPin string) (vendibilityResponse []*UpdateVendibilityResponse, err error) { jdParams := map[string]interface{}{ "outStationNo": outStationNo, "skuIds": skuIds, @@ -195,7 +227,7 @@ func (a *API) QueryStockCenter(outStationNo string, skuIds []*SkuIdEntity, userP } result, err := a.AccessAPINoPage("stock/queryStockCenter", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0")) if err == nil && result != nil { - return utils.Slice2MapSlice(result.([]interface{})), nil + err = utils.Map2StructByJson(result, &vendibilityResponse, false) } - return nil, err + return vendibilityResponse, err } diff --git a/platformapi/jdapi/store_sku_test.go b/platformapi/jdapi/store_sku_test.go index 2e7b0985..0c0d6d60 100644 --- a/platformapi/jdapi/store_sku_test.go +++ b/platformapi/jdapi/store_sku_test.go @@ -8,8 +8,8 @@ import ( ) const ( - mustExistSkuID = 2017194325 - mustExistSkuJXID = "21206" + mustExistSkuID = 2023747677 + mustExistSkuJXID = "5246" ) func TestGetStationInfoList(t *testing.T) { @@ -17,9 +17,7 @@ func TestGetStationInfoList(t *testing.T) { if err != nil { t.Fatal(err) } - for _, v := range result { - baseapi.SugarLogger.Debug(v) - } + t.Log(utils.Format4Output(result, false)) } func TestQueryOpenUseable(t *testing.T) { @@ -32,9 +30,7 @@ func TestQueryOpenUseable(t *testing.T) { if err != nil { t.Fatal(err) } - for _, v := range result { - baseapi.SugarLogger.Debug(v) - } + t.Log(utils.Format4Output(result, false)) } func TestQueryStockCenter(t *testing.T) { @@ -46,9 +42,7 @@ func TestQueryStockCenter(t *testing.T) { if err != nil { t.Fatal(err) } - for _, v := range result { - baseapi.SugarLogger.Debug(v) - } + t.Log(utils.Format4Output(result, false)) } func TestBatchUpdateVendibility(t *testing.T) { diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 692a180b..2b62eeab 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -9,8 +9,8 @@ import ( ) const ( - mustExistStoreID = "11738324" - mustExistStoreJXID = "100285" + mustExistStoreID = "11053496" + mustExistStoreJXID = "2" ) func TestGetAllCities(t *testing.T) {