- refactor result parser.
This commit is contained in:
@@ -32,12 +32,13 @@ const (
|
||||
type CreateShopResult struct {
|
||||
DeliveryRangeType int `json:"deliveryRangeType"`
|
||||
CoordinatePoints string `json:"coordinatePoints"`
|
||||
StationNo string `json:"stationNo"`
|
||||
}
|
||||
|
||||
// 获取门店编码列表接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=138426aa19b54c48ae8464af1ca3b681
|
||||
func (a *API) GetStationsByVenderId() ([]string, error) {
|
||||
result, err := a.AccessAPINoPage("store/getStationsByVenderId", nil, nil, nil, nil)
|
||||
result, err := a.AccessAPINoPage("store/getStationsByVenderId", nil, nil, nil, genNoPageResultParser("code", "msg", "result", "1"))
|
||||
if err == nil {
|
||||
result2 := result.([]interface{})
|
||||
retVal := make([]string, len(result2))
|
||||
@@ -67,14 +68,17 @@ func (a *API) CreateStore(stationName, phone string, city, county int, stationAd
|
||||
KeyCoordinateType: coordinateType,
|
||||
KeyStandByPhone: standByPhone,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("store/createStore", utils.MergeMaps(params, addParams), nil, nil, nil)
|
||||
if err == nil {
|
||||
result2 := result.(map[string]interface{})
|
||||
retVal := &CreateShopResult{
|
||||
DeliveryRangeType: int(utils.MustInterface2Int64(result2["deliveryRangeType"])),
|
||||
CoordinatePoints: utils.Interface2String(result2["coordinatePoints"]),
|
||||
result, err := a.AccessAPINoPage("store/createStore", utils.MergeMaps(params, addParams), nil, nil, func(data map[string]interface{}) (interface{}, error) {
|
||||
innerCode := data["code"].(string)
|
||||
if data["code"] == "0" {
|
||||
mapData := data["data"].(map[string]interface{})
|
||||
mapData["result"] = data["result"].(string)
|
||||
return mapData, nil
|
||||
}
|
||||
return retVal, nil
|
||||
return nil, utils.NewErrorCode(data["msg"].(string), innerCode, 1)
|
||||
})
|
||||
if err == nil {
|
||||
return interface2CreateShopResult(result), nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
@@ -91,19 +95,25 @@ func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, e
|
||||
|
||||
// 修改门店基础信息接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=2600369a456446f0921e918f3d15e96a
|
||||
func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) (string, error) {
|
||||
func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) (*CreateShopResult, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"stationNo": storeNo,
|
||||
"operator": utils.GetAPIOperator(userName),
|
||||
}
|
||||
for k, v := range addParams {
|
||||
jdParams[k] = v
|
||||
}
|
||||
result, err := a.AccessAPINoPage("store/updateStoreInfo4Open", jdParams, nil, nil, nil)
|
||||
jdParams = utils.MergeMaps(jdParams, addParams)
|
||||
result, err := a.AccessAPINoPage("store/updateStoreInfo4Open", jdParams, nil, nil, func(data map[string]interface{}) (interface{}, error) {
|
||||
innerCode := data["code"].(string)
|
||||
if data["code"] == "0" {
|
||||
mapData := data["data"].(map[string]interface{})
|
||||
mapData["result"] = data["result"].(string)
|
||||
return mapData, nil
|
||||
}
|
||||
return nil, utils.NewErrorCode(data["msg"].(string), innerCode, 1)
|
||||
})
|
||||
if err == nil {
|
||||
return result.(string), nil
|
||||
return interface2CreateShopResult(result), nil
|
||||
}
|
||||
return "", err
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 根据订单号查询商家门店评价信息接口
|
||||
@@ -113,14 +123,14 @@ func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error)
|
||||
"orderId": orderId,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err == nil {
|
||||
return result.(map[string]interface{}), nil
|
||||
}
|
||||
return result.(map[string]interface{}), nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 商家门店评价信息回复接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=ea0b466a7fa8489b813e8b197efca2d4?
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=ea0b466a7fa8489b813e8b197efca2d4
|
||||
func (a *API) OrgReplyComment(orderID int64, storeID, content, replayPin string) (string, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderID,
|
||||
@@ -128,11 +138,11 @@ func (a *API) OrgReplyComment(orderID int64, storeID, content, replayPin string)
|
||||
"content": content,
|
||||
"replyPin": replayPin,
|
||||
}
|
||||
result, err := a.AccessAPINoPage("commentOutApi/orgReplyComment", jdParams, nil, nil, nil)
|
||||
if err != nil {
|
||||
return "", err
|
||||
result, err := a.AccessAPINoPage("commentOutApi/orgReplyComment", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
|
||||
if err == nil {
|
||||
return result.(string), nil
|
||||
}
|
||||
return result.(string), nil
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 根据到家门店编码修改商家自动接单接口
|
||||
@@ -153,3 +163,15 @@ func (a *API) UpdateStoreConfig4Open(stationNo string, isAutoOrder bool) (bool,
|
||||
}
|
||||
return result.(bool), nil
|
||||
}
|
||||
|
||||
// 私有函数
|
||||
func interface2CreateShopResult(data interface{}) (retVal *CreateShopResult) {
|
||||
if result, ok := data.(map[string]interface{}); ok {
|
||||
retVal = &CreateShopResult{
|
||||
DeliveryRangeType: int(utils.MustInterface2Int64(result["deliveryRangeType"])),
|
||||
CoordinatePoints: utils.Interface2String(result["coordinatePoints"]),
|
||||
StationNo: utils.Interface2String(result["result"]),
|
||||
}
|
||||
}
|
||||
return retVal
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user