- 重要修改相关的函数新增trackInfo参数,追踪修改人.接口类型改变

This commit is contained in:
gazebo
2019-07-28 12:34:52 +08:00
parent 437711eb38
commit da9c8a11c2
13 changed files with 152 additions and 100 deletions

View File

@@ -143,7 +143,7 @@ func New(token, appKey, appSecret string, config ...*platformapi.APIConfig) *API
}
}
func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal map[string]interface{}, err error) {
func (a *API) AccessAPI2(apiStr string, jdParams map[string]interface{}, traceInfo string) (retVal map[string]interface{}, err error) {
params := make(map[string]interface{})
params["v"] = "1.0"
params["format"] = "json"
@@ -182,6 +182,9 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
request.Header.Set("charset", "UTF-8")
request.Header.Set("Content-Type", "application/x-www-form-urlencoded")
}
if traceInfo != "" {
request.Header.Set(platformapi.KeyTrackInfo, traceInfo)
}
// request.Close = true //todo 为了性能考虑还是不要关闭
return request
},
@@ -208,6 +211,10 @@ func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal
return retVal, platformapi.RebuildError(err, jdParams, watchKeys)
}
func (a *API) AccessAPI(apiStr string, jdParams map[string]interface{}) (retVal map[string]interface{}, err error) {
return a.AccessAPI2(apiStr, jdParams, "")
}
func genNoPageResultParser(codeKey, msgKey, resultKey, okCode string) func(data map[string]interface{}) (interface{}, error) {
return func(data map[string]interface{}) (innerData interface{}, err error) {
rawInnerCode, ok := data[codeKey]
@@ -236,11 +243,11 @@ func formatErrorMsg(msg interface{}) (strMsg string) {
return strMsg
}
func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error)) (interface{}, error) {
func (a *API) AccessAPINoPage2(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error), traceInfo string) (interface{}, error) {
if resultParser == nil {
resultParser = genNoPageResultParser("code", "msg", "result", "0")
}
jsonResult, err := a.AccessAPI(apiStr, jdParams)
jsonResult, err := a.AccessAPI2(apiStr, jdParams, traceInfo)
if err != nil {
return nil, err
}
@@ -257,6 +264,10 @@ func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, ke
return result, err
}
func (a *API) AccessAPINoPage(apiStr string, jdParams map[string]interface{}, keyToRemove, keyToKeep []string, resultParser func(data map[string]interface{}) (interface{}, error)) (interface{}, error) {
return a.AccessAPINoPage2(apiStr, jdParams, keyToRemove, keyToKeep, resultParser, "")
}
func normalHavePageResultParser(data map[string]interface{}, totalCount int) ([]interface{}, int, error) {
var result map[string]interface{}
var retVal []interface{}

View File

@@ -622,3 +622,15 @@ func ProcessQuestionPic(questionPic string) (outQuestionPic string) {
}
return outQuestionPic
}
// 订单商家加小费接口
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=169&apiid=ed9e3ca7325c4d4d8ceaf959ed0e7a62
func (a *API) OrderAddTips(OrderID string, tips int, pin string) (err error) {
jdParams := map[string]interface{}{
"orderId": OrderID,
"tips": tips,
"pin": utils.GetAPIOperator(pin),
}
_, err = a.AccessAPINoPage("order/addTips", jdParams, nil, nil, nullResultParser)
return err
}

View File

@@ -97,7 +97,7 @@ type StoreSkuBatchUpdateResponse struct {
// 根据商家商品编码和商家门店编码批量修改门店价格接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=fcbf346648a54d03b92dec8fa62ea643
func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) (responseList []*StoreSkuBatchUpdateResponse, err error) {
func (a *API) UpdateVendorStationPrice(trackInfo string, outStationNo, stationNo string, skuPriceInfoList []*SkuPriceInfo) (responseList []*StoreSkuBatchUpdateResponse, err error) {
jdParams := map[string]interface{}{
"skuPriceInfoList": skuPriceInfoList,
}
@@ -106,7 +106,7 @@ func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceI
} else {
jdParams["stationNo"] = stationNo
}
result, err := a.AccessAPINoPage("venderprice/updateStationPrice", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "0"))
result, err := a.AccessAPINoPage2("venderprice/updateStationPrice", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "0"), trackInfo)
if result != nil {
var err2 error
if responseList, err2 = a.handleBatchOpResult(len(skuPriceInfoList), result, "json2"); err2 != nil && err == nil {
@@ -119,13 +119,13 @@ func (a *API) UpdateVendorStationPrice(outStationNo, stationNo string, skuPriceI
// 根据到家商品编码和到家门店编码修改门店价格接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=205&apiid=45f83ef7c6e74dad94b6b68d3c50b673
// 单商品用此接口
func (a *API) UpdateStationPrice(skuId int64, stationNo string, price int) (string, error) {
func (a *API) UpdateStationPrice(trackInfo string, 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)
result, err := a.AccessAPINoPage2("price/updateStationPrice", jdParams, nil, nil, nil, trackInfo)
if err == nil && result != nil {
return utils.Interface2String(result), nil
}
@@ -165,7 +165,7 @@ func (a *API) handleBatchOpResult(batchCount int, result interface{}, tagName st
// 根据商家商品编码和商家门店编码批量修改现货库存接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=10812f9fc7ee4564b552f19270a7e92e
func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
func (a *API) BatchUpdateCurrentQtys(trackInfo, outStationNo, stationNo string, skuStockList []*SkuStock, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
}
@@ -178,7 +178,7 @@ func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockLis
} else {
jdParams["stationNo"] = stationNo
}
result, err := a.AccessAPINoPage("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
result, err := a.AccessAPINoPage2("stock/batchUpdateCurrentQtys", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo)
if result != nil {
var err2 error
if responseList, err2 = a.handleBatchOpResult(len(skuStockList), result, ""); err2 != nil && err == nil {
@@ -191,14 +191,14 @@ func (a *API) BatchUpdateCurrentQtys(outStationNo, stationNo string, skuStockLis
// 根据商家商品编码和商家门店编码更新门店现货库存接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=a78664d4ead349da95d2f4576ed18d7f
// 此接口基本可以不用
func (a *API) StockUpdate(outStationNo string, outSkuID string, currentQty int) error {
func (a *API) StockUpdate(trackInfo string, outStationNo string, outSkuID string, currentQty int) error {
// !这个接口的stationNo与skuId好像本身就写错了的
jdParams := map[string]interface{}{
"stationNo": outStationNo,
"skuId": outSkuID,
"currentQty": currentQty,
}
_, err := a.AccessAPINoPage("stock/update", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "", "0"))
_, err := a.AccessAPINoPage2("stock/update", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "", "0"), trackInfo)
if err == nil {
return nil
}
@@ -208,13 +208,13 @@ func (a *API) StockUpdate(outStationNo string, outSkuID string, currentQty int)
// 根据到家商品编码和到家门店编码更新门店现货库存
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=200&apiid=af70e699d4974e1683128742018f6381
// 单商品用此接口
func (a *API) UpdateCurrentQty(stationNo string, skuID int64, currentQty int) error {
func (a *API) UpdateCurrentQty(trackInfo string, stationNo string, skuID int64, currentQty int) error {
jdParams := map[string]interface{}{
"stationNo": stationNo,
"skuId": skuID,
"currentQty": currentQty,
}
_, err := a.AccessAPINoPage("update/currentQty", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "", "0"))
_, err := a.AccessAPINoPage2("update/currentQty", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "", "0"), trackInfo)
if err == nil {
return nil
}
@@ -224,11 +224,11 @@ func (a *API) UpdateCurrentQty(stationNo string, skuID int64, currentQty int) er
// 根据到家商品编码和到家门店编码批量修改门店商品可售状态接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=b783a508e2cf4aca94681e4eed9af5bc
// 尽量不用这个接口用下面那个原因是这个不支持设置操作人BatchUpdateVendibility可以
func (a *API) UpdateVendibility(listBaseStockCenterRequest []*QueryStockRequest) (responseList []*StoreSkuBatchUpdateResponse, err error) {
func (a *API) UpdateVendibility(trackInfo string, listBaseStockCenterRequest []*QueryStockRequest) (responseList []*StoreSkuBatchUpdateResponse, err error) {
jdParams := map[string]interface{}{
"listBaseStockCenterRequest": listBaseStockCenterRequest,
}
result, err := a.AccessAPINoPage("stock/updateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
result, err := a.AccessAPINoPage2("stock/updateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo)
if result != nil {
var err2 error
if responseList, err2 = a.handleBatchOpResult(len(listBaseStockCenterRequest), result, ""); err2 != nil && err == nil {
@@ -240,7 +240,7 @@ func (a *API) UpdateVendibility(listBaseStockCenterRequest []*QueryStockRequest)
// 根据商家商品编码和门店编码批量修改门店商品可售状态接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=200&apiid=ac6f559ebabf4b70bc423687638e07c1
func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
func (a *API) BatchUpdateVendibility(trackInfo, outStationNo, stationNo string, stockVendibilityList []*StockVendibility, userPin string) (responseList []*StoreSkuBatchUpdateResponse, err error) {
if (outStationNo == "" && stationNo == "") || (outStationNo != "" && stationNo != "") {
return nil, errors.New("outStationNo and stationNo can not all be empty or have value")
}
@@ -253,7 +253,7 @@ func (a *API) BatchUpdateVendibility(outStationNo, stationNo string, stockVendib
} else {
jdParams["stationNo"] = stationNo
}
result, err := a.AccessAPINoPage("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"))
result, err := a.AccessAPINoPage2("stock/batchUpdateVendibility", jdParams, nil, nil, genNoPageResultParser("retCode", "retMsg", "data", "0"), trackInfo)
if result != nil {
var err2 error
if responseList, err2 = a.handleBatchOpResult(len(stockVendibilityList), result, ""); err2 != nil && err == nil {

View File

@@ -46,7 +46,7 @@ func TestQueryStockCenter(t *testing.T) {
}
func TestBatchUpdateVendibility(t *testing.T) {
result, err := api.BatchUpdateVendibility("100130", "", []*StockVendibility{
result, err := api.BatchUpdateVendibility("", "100130", "", []*StockVendibility{
&StockVendibility{
OutSkuId: "26919",
DoSale: true,
@@ -59,7 +59,7 @@ func TestBatchUpdateVendibility(t *testing.T) {
}
func TestUpdateVendibility(t *testing.T) {
result, err := api.UpdateVendibility([]*QueryStockRequest{
result, err := api.UpdateVendibility("", []*QueryStockRequest{
&QueryStockRequest{
StationNo: "11053496",
SkuId: 2012224772,