Files
baseapi/platformapi/jdapi/store.go
2018-08-29 23:23:34 +08:00

178 lines
6.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package jdapi
// todo 没有删除门店的方法?
import (
"git.rosy.net.cn/baseapi/utils"
)
const (
KeyStationName = "stationName"
KeyOutSystemId = "outSystemId"
KeyPhone = "phone"
KeyMobile = "mobile"
KeyCity = "city"
KeyCounty = "county"
KeyStationAddress = "stationAddress"
KeyOperator = "operator"
KeyServiceTimeStart1 = "serviceTimeStart1"
KeyServiceTimeEnd1 = "serviceTimeEnd1"
KeyServiceTimeStart2 = "serviceTimeStart2"
KeyServiceTimeEnd2 = "serviceTimeEnd2"
KeyLng = "lng"
KeyLat = "lat"
KeyDeliveryRangeType = "deliveryRangeType"
KeyCoordinateType = "coordinateType"
KeyDeliveryRangeRadius = "deliveryRangeRadius"
KeyCoordinatePoints = "coordinatePoints"
KeyCloseStatus = "closeStatus"
KeyStoreNotice = "storeNotice"
KeyStandByPhone = "standByPhone"
)
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, genNoPageResultParser("code", "msg", "result", "1"))
if err == nil {
result2 := result.([]interface{})
retVal := make([]string, len(result2))
for k, v := range result2 {
retVal[k] = v.(string)
}
return retVal, nil
}
return nil, err
}
// 新增不带资质的门店信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=93acef27c3aa4d8286d5c8c26b493629
func (a *API) CreateStore(stationName, phone string, city, county int, stationAddress, userName string, serviceTimeStart1, serviceTimeEnd1 int, lng, lat float64, deliveryRangeType, coordinateType int, standByPhone string, addParams map[string]interface{}) (*CreateShopResult, error) {
params := map[string]interface{}{
KeyStationName: stationName,
KeyPhone: phone,
KeyCity: city,
KeyCounty: county,
KeyStationAddress: stationAddress,
KeyOperator: utils.GetAPIOperator(userName),
KeyServiceTimeStart1: serviceTimeStart1,
KeyServiceTimeEnd2: serviceTimeEnd1,
KeyLng: lng,
KeyLat: lat,
KeyDeliveryRangeType: deliveryRangeType,
KeyCoordinateType: coordinateType,
KeyStandByPhone: standByPhone,
}
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 nil, utils.NewErrorCode(data["msg"].(string), innerCode, 1)
})
if err == nil {
return interface2CreateShopResult(result), nil
}
return nil, err
}
// 根据到家门店编码查询门店基本信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=4c48e347027146d5a103e851055cb1a7
func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, error) {
result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil)
if err == nil {
return result.(map[string]interface{}), nil
}
return nil, err
}
// 修改门店基础信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=2600369a456446f0921e918f3d15e96a
func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[string]interface{}) (*CreateShopResult, error) {
jdParams := map[string]interface{}{
"stationNo": storeNo,
"operator": utils.GetAPIOperator(userName),
}
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 interface2CreateShopResult(result), nil
}
return nil, err
}
// 根据订单号查询商家门店评价信息接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=bd23397725bb4e74b69e2f2fa1c88d43
func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) {
jdParams := map[string]interface{}{
"orderId": orderId,
}
result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, nil)
if err == nil {
return result.(map[string]interface{}), nil
}
return nil, err
}
// 商家门店评价信息回复接口
// 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,
"storeId": storeID,
"content": content,
"replyPin": replayPin,
}
result, err := a.AccessAPINoPage("commentOutApi/orgReplyComment", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
if err == nil {
return result.(string), nil
}
return "", err
}
// 根据到家门店编码修改商家自动接单接口
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=5df446bb5ff14413965b8d702718dc48
func (a *API) UpdateStoreConfig4Open(stationNo string, isAutoOrder bool) (bool, error) {
jdParams := map[string]interface{}{
"stationNo": stationNo,
}
// 01是反的
if isAutoOrder {
jdParams["isAutoOrder"] = 0
} else {
jdParams["isAutoOrder"] = 1
}
result, err := a.AccessAPINoPage("store/updateStoreConfig4Open", jdParams, nil, nil, nil)
if err != nil {
return false, err
}
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
}