- jd store_sku api added.
This commit is contained in:
@@ -336,7 +336,7 @@ func forceInnerCode2Str(innerCode interface{}) string {
|
||||
if innerCodeStr, ok := innerCode.(string); ok {
|
||||
return innerCodeStr
|
||||
}
|
||||
return utils.Int64ToStr(utils.Interface2Int64WithDefault(innerCode, 0))
|
||||
return fmt.Sprintf("%v", innerCode)
|
||||
}
|
||||
|
||||
func getErrMsgFromData(data map[string]interface{}) string {
|
||||
|
||||
196
platformapi/jdapi/store_sku.go
Normal file
196
platformapi/jdapi/store_sku.go
Normal file
@@ -0,0 +1,196 @@
|
||||
package jdapi
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
)
|
||||
|
||||
type SkuPriceInfo struct {
|
||||
OutSkuId string `json:"outSkuId"`
|
||||
Price int `json:"price"`
|
||||
}
|
||||
|
||||
type SkuStock struct {
|
||||
OutSkuId string `json:"outSkuId"`
|
||||
StockQty int `json:"stockQty"`
|
||||
}
|
||||
|
||||
type QueryStockRequest struct {
|
||||
StationNo string `json:"stationNo"`
|
||||
SkuId int64 `json:"skuId"`
|
||||
DoSale int `json:"doSale"` //可售状态(0:可售,1:不可售)
|
||||
}
|
||||
|
||||
type StockVendibility struct {
|
||||
OutSkuId string `json:"outSkuId"`
|
||||
DoSale bool `json:"doSale"` // 可售状态(true:可售,false:不可售)
|
||||
}
|
||||
|
||||
type BaseStockCenterRequest struct {
|
||||
StationNo string `json:"stationNo"`
|
||||
SkuId int64 `json:"skuId"`
|
||||
}
|
||||
|
||||
type SkuIdEntity struct {
|
||||
OutSkuId string `json:"outSkuId"`
|
||||
}
|
||||
|
||||
// 传入为数组的,最多一次为50个
|
||||
// 有好些功能有两个类似的函数,一个为到家ID,一个为商家ID,建议都只用商家ID的那个,因为:
|
||||
// 1,这类函数一般可以批量操作
|
||||
// 2,这类函数一般可以记录操作人员
|
||||
|
||||
// 根据商家商品编码和商家门店编码批量修改门店价格接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=fcbf346648a54d03b92dec8fa62ea643
|
||||
func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) ([]map[string]interface{}, error) {
|
||||
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||
}
|
||||
jdParams := map[string]interface{}{
|
||||
"skuPriceInfoList": skuPriceInfoList,
|
||||
}
|
||||
if outStationNo != "" {
|
||||
jdParams["outStationNo"] = outStationNo
|
||||
} else {
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("venderprice/updateStationPrice", jdParams, nil, nil, nil)
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据到家商品编码和到家门店编码修改门店价格接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=45f83ef7c6e74dad94b6b68d3c50b673
|
||||
// 此接口基本可以不用
|
||||
func (a *API) UpdateStationPrice(skuId int64, stationNo string, price int) (string, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"skuId": skuId,
|
||||
"stationNo": stationNo,
|
||||
"price": price,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("price/updateStationPrice", jdParams, nil, nil, nil)
|
||||
if err == nil {
|
||||
return utils.Interface2String(result), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 根据到家商品编码和到家门店编码批量查询商品门店价格信息接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=21ccd5a00d3a4582b4c9a8ef0ae238fc
|
||||
func (a *API) GetStationInfoList(stationNo string, skuIds []int64) ([]map[string]interface{}, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"skuIds": skuIds,
|
||||
"stationNo": stationNo,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("price/getStationInfoList", jdParams, nil, nil, nil)
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据商家商品编码和商家门店编码批量修改现货库存接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=10812f9fc7ee4564b552f19270a7e92e
|
||||
func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) ([]map[string]interface{}, error) {
|
||||
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||
}
|
||||
jdParams := map[string]interface{}{
|
||||
"skuStockList": skuStockList,
|
||||
"userPin": userPin,
|
||||
}
|
||||
if outStationNo != "" {
|
||||
jdParams["outStationNo"] = outStationNo
|
||||
} else {
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据商家商品编码和商家门店编码更新门店现货库存接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=a78664d4ead349da95d2f4576ed18d7f
|
||||
// 此接口基本可以不用
|
||||
func (a *API) StockUpdate(stationNo string, skuId int64, currentQty int) error {
|
||||
jdParams := map[string]interface{}{
|
||||
"stationNo": stationNo,
|
||||
"skuId": skuId,
|
||||
"currentQty": currentQty,
|
||||
}
|
||||
_, err := a.AccessAPINoPage("stock/update", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "", ""))
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// 根据到家商品编码和到家门店编码批量修改门店商品可售状态接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=b783a508e2cf4aca94681e4eed9af5bc
|
||||
// 尽量不用这个接口,用下面那个
|
||||
func (a *API) UpdateVendibility(listBaseStockCenterRequest []*QueryStockRequest) ([]map[string]interface{}, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"listBaseStockCenterRequest": listBaseStockCenterRequest,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/updateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据商家商品编码和门店编码批量修改门店商品可售状态接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=ac6f559ebabf4b70bc423687638e07c1
|
||||
func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) ([]map[string]interface{}, error) {
|
||||
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
|
||||
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
|
||||
}
|
||||
jdParams := map[string]interface{}{
|
||||
"stockVendibilityList": stockVendibilityList,
|
||||
"userPin": userPin,
|
||||
}
|
||||
if outStationNo != "" {
|
||||
jdParams["outStationNo"] = outStationNo
|
||||
} else {
|
||||
jdParams["stationNo"] = stationNo
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据到家商品编码和门店编码批量查询商品库存及可售状态信息接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=bc6ad75e8fd34580856e06b5eb149aad
|
||||
// 尽量不用这个接口,用下面那个
|
||||
func (a *API) QueryOpenUseable(listBaseStockCenterRequest []*BaseStockCenterRequest) ([]map[string]interface{}, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"listBaseStockCenterRequest": listBaseStockCenterRequest,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/queryOpenUseable", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, 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) {
|
||||
jdParams := map[string]interface{}{
|
||||
"outStationNo": outStationNo,
|
||||
"skuIds": skuIds,
|
||||
"userPin": userPin,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("stock/queryStockCenter", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
|
||||
if err == nil {
|
||||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
51
platformapi/jdapi/store_sku_test.go
Normal file
51
platformapi/jdapi/store_sku_test.go
Normal file
@@ -0,0 +1,51 @@
|
||||
package jdapi
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
)
|
||||
|
||||
const (
|
||||
mustExistSkuID = 2017194325
|
||||
mustExistSkuJXID = "21206"
|
||||
)
|
||||
|
||||
func TestGetStationInfoList(t *testing.T) {
|
||||
result, err := jdapi.GetStationInfoList(mustExistStoreID, []int64{mustExistSkuID})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, v := range result {
|
||||
baseapi.SugarLogger.Debug(v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryOpenUseable(t *testing.T) {
|
||||
result, err := jdapi.QueryOpenUseable([]*BaseStockCenterRequest{
|
||||
&BaseStockCenterRequest{
|
||||
StationNo: mustExistStoreID,
|
||||
SkuId: mustExistSkuID,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, v := range result {
|
||||
baseapi.SugarLogger.Debug(v)
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryStockCenter(t *testing.T) {
|
||||
result, err := jdapi.QueryStockCenter(mustExistStoreJXID, []*SkuIdEntity{
|
||||
&SkuIdEntity{
|
||||
OutSkuId: mustExistSkuJXID,
|
||||
},
|
||||
}, "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, v := range result {
|
||||
baseapi.SugarLogger.Debug(v)
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
mustExistStoreID = "11738324"
|
||||
mustExistStoreID = "11738324"
|
||||
mustExistStoreJXID = "100285"
|
||||
)
|
||||
|
||||
func TestGetStationsByVenderId(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user