- 京东门店信息查询相关的三个API返回值改为具体的struct

This commit is contained in:
gazebo
2019-05-17 17:13:25 +08:00
parent 677100b522
commit 4a82d71f0d
4 changed files with 51 additions and 25 deletions

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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) {

View File

@@ -9,8 +9,8 @@ import (
)
const (
mustExistStoreID = "11738324"
mustExistStoreJXID = "100285"
mustExistStoreID = "11053496"
mustExistStoreJXID = "2"
)
func TestGetAllCities(t *testing.T) {