234 lines
8.9 KiB
Go
234 lines
8.9 KiB
Go
package jdapi
|
||
|
||
import (
|
||
"errors"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
const (
|
||
MaxStoreSkuBatchSize = 50
|
||
MaxStockQty = 100000000
|
||
)
|
||
|
||
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"`
|
||
}
|
||
|
||
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,这类函数一般可以批量操作
|
||
// 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 && result != 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 && result != 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) (priceInfo []*StorePriceInfo, err error) {
|
||
jdParams := map[string]interface{}{
|
||
"skuIds": skuIds,
|
||
"stationNo": stationNo,
|
||
}
|
||
result, err := a.AccessAPINoPage("price/getStationInfoList", jdParams, nil, nil, genNoPageResultParser("code", "detail", "result", "0"))
|
||
if err == nil && result != nil {
|
||
err = utils.Map2StructByJson(result, &priceInfo, false)
|
||
}
|
||
return priceInfo, 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 && result != 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 && result != 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 && result != 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) (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 {
|
||
err = utils.Map2StructByJson(result, &stockResponse, false)
|
||
}
|
||
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) (vendibilityResponse []*UpdateVendibilityResponse, err 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 && result != nil {
|
||
err = utils.Map2StructByJson(result, &vendibilityResponse, false)
|
||
}
|
||
return vendibilityResponse, err
|
||
}
|