177 lines
6.5 KiB
Go
177 lines
6.5 KiB
Go
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{}) error {
|
||
jdParams := map[string]interface{}{
|
||
"stationNo": storeNo,
|
||
"operator": utils.GetAPIOperator(userName),
|
||
}
|
||
jdParams = utils.MergeMaps(jdParams, addParams)
|
||
_, err := a.AccessAPINoPage("store/updateStoreInfo4Open", jdParams, nil, nil, nullResultParser)
|
||
return 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, genNoPageResultParser("code", "msg", "result", "200"))
|
||
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) error {
|
||
jdParams := map[string]interface{}{
|
||
"orderId": orderID,
|
||
"storeId": storeID,
|
||
"content": content,
|
||
"replyPin": replayPin,
|
||
}
|
||
_, err := a.AccessAPINoPage("commentOutApi/orgReplyComment", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
|
||
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,
|
||
}
|
||
// 0,1是反的
|
||
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
|
||
}
|
||
|
||
// 获取门店配送范围接口
|
||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=194&apiid=8f6d0ac75d734c68bf5bd2a09f376a78
|
||
func (a *API) GetDeliveryRangeByStationNo(stationNo string) (map[string]interface{}, error) {
|
||
jdParams := map[string]interface{}{
|
||
"stationNo": stationNo,
|
||
}
|
||
result, err := a.AccessAPINoPage("store/getDeliveryRangeByStationNo", jdParams, nil, nil, nil)
|
||
if err == nil {
|
||
return result.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
// 私有函数
|
||
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
|
||
}
|