390 lines
18 KiB
Go
390 lines
18 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"
|
||
)
|
||
|
||
const (
|
||
CarrierNoCrowdSourcing = 9966 // 众包
|
||
CarrierNoSelfDelivery = 2938 // 自送
|
||
CarrierNoSelfTake = 9999 // 到店自提
|
||
)
|
||
|
||
const (
|
||
CoordinateTypeGoogle = 1 // 谷歌
|
||
CoordinateTypeBaidu = 2 // 百度
|
||
CoordinateTypeAutonavi = 3 // 高德
|
||
CoordinateTypeTencent = 4 // 腾讯
|
||
)
|
||
|
||
type CreateShopResult struct {
|
||
DeliveryRangeType int `json:"deliveryRangeType"`
|
||
CoordinatePoints string `json:"coordinatePoints"`
|
||
StationNo string `json:"stationNo"`
|
||
}
|
||
|
||
type CityInfo struct {
|
||
AreaCode int `json:"areaCode"`
|
||
AreaLevel int `json:"areaLevel"`
|
||
AreaName string `json:"areaName"`
|
||
ParentAreaID int `json:"parentAreaId"`
|
||
TencentAddressCode int `json:"tencentAddressCode"`
|
||
Yn int `json:"yn"`
|
||
}
|
||
|
||
type OpStoreParams struct {
|
||
// 以下可用于修改(及查询)
|
||
StationNo string `json:"stationNo"` // 强制参数,主键
|
||
StationName string `json:"stationName,omitempty"`
|
||
OutSystemID string `json:"outSystemId,omitempty"`
|
||
Mobile string `json:"mobile,omitempty"`
|
||
Phone string `json:"phone,omitempty"`
|
||
Lat float64 `json:"lat,omitempty"`
|
||
Lng float64 `json:"lng,omitempty"`
|
||
City int `json:"city,omitempty"`
|
||
County int `json:"county,omitempty"`
|
||
StationAddress string `json:"stationAddress,omitempty"`
|
||
Operator string `json:"operator"` // 返回值无
|
||
ServiceTimeEnd1 int `json:"serviceTimeEnd1,omitempty"`
|
||
ServiceTimeStart1 int `json:"serviceTimeStart1,omitempty"`
|
||
ServiceTimeEnd2 int `json:"serviceTimeEnd2,omitempty"`
|
||
ServiceTimeStart2 int `json:"serviceTimeStart2,omitempty"`
|
||
DeliveryRangeType int8 `json:"deliveryRangeType,omitempty"` // 返回值无,划分配送服务范围的类型(3、圆心半径、2、不规则多边形(手动画范围))。若更新此字段需传完整值。
|
||
CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯)
|
||
DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值)
|
||
CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k
|
||
CloseStatus int `json:"closeStatus"`
|
||
StoreNotice string `json:"storeNotice,omitempty"`
|
||
StandByPhone string `json:"standByPhone,omitempty"`
|
||
}
|
||
|
||
type StoreDetail struct {
|
||
// 以下可用于修改(及查询)
|
||
StationNo string `json:"stationNo"` // 强制参数,主键
|
||
StationName string `json:"stationName,omitempty"`
|
||
OutSystemID string `json:"outSystemId,omitempty"`
|
||
Mobile string `json:"mobile,omitempty"`
|
||
Phone string `json:"phone,omitempty"`
|
||
Lat float64 `json:"lat,omitempty"`
|
||
Lng float64 `json:"lng,omitempty"`
|
||
City int `json:"city,omitempty"`
|
||
County int `json:"county,omitempty"`
|
||
StationAddress string `json:"stationAddress,omitempty"`
|
||
// Operator string `json:"operator"` // 返回值无
|
||
ServiceTimeEnd1 int `json:"serviceTimeEnd1,omitempty"`
|
||
ServiceTimeStart1 int `json:"serviceTimeStart1,omitempty"`
|
||
ServiceTimeEnd2 int `json:"serviceTimeEnd2,omitempty"`
|
||
ServiceTimeStart2 int `json:"serviceTimeStart2,omitempty"`
|
||
// DeliveryRangeType int8 `json:"deliveryRangeType,omitempty"` // 返回值无,划分配送服务范围的类型(3、圆心半径、2、不规则多边形(手动画范围))。若更新此字段需传完整值。
|
||
// CoordinateType int `json:"coordinateType,omitempty"` // 返回值无,使用的地图类型(1,谷歌), (2,百度), (3,高德), (4,腾讯)
|
||
// DeliveryRangeRadius int `json:"deliveryRangeRadius,omitempty"` // 返回值无,时效服务范围半径(单位:米)(如果服务范围为类型3的话,该字段有值)
|
||
// CoordinatePoints string `json:"coordinatePoints,omitempty"` // 返回值无,坐标点集合(如果服务范围为类型2的话,该字段有值),每个点以:经度,纬度 的格式表示,用“;”隔开多个点;对于腾讯地图、谷歌地图和高德地图,整个coordinatePoints的长度必须小于2k;对于百度地图,整个coordinatePoints的长度必须小于1k
|
||
CloseStatus int `json:"closeStatus,omitempty"`
|
||
StoreNotice string `json:"storeNotice,omitempty"`
|
||
StandByPhone string `json:"standByPhone,omitempty"`
|
||
|
||
// 以下仅用于查询
|
||
AllowRangeOptimized int `json:"allowRangeOptimized,omitempty"`
|
||
CacheKey4StoreList string `json:"cacheKey4StoreList,omitempty"`
|
||
CarrierNo int `json:"carrierNo,omitempty"`
|
||
CityName string `json:"cityName,omitempty"`
|
||
Coordinate string `json:"coordinate,omitempty"`
|
||
CoordinateAddress string `json:"coordinateAddress,omitempty"`
|
||
CountyName string `json:"countyName,omitempty"`
|
||
CreatePin string `json:"createPin,omitempty"`
|
||
CreateTime *utils.JavaDate `json:"createTime,omitempty"`
|
||
ID int64 `json:"id,omitempty"`
|
||
IndustryTag int `json:"industryTag,omitempty"`
|
||
InnerNoStatus int `json:"innerNoStatus,omitempty"`
|
||
IsAutoOrder int `json:"isAutoOrder,omitempty"` // 是否自动接单,0:是1:否
|
||
IsMembership int `json:"isMembership,omitempty"`
|
||
IsNoPaper int `json:"isNoPaper,omitempty"`
|
||
OnlineTime *utils.JavaDate `json:"onlineTime,omitempty"`
|
||
OrderAging int `json:"orderAging,omitempty"`
|
||
OrderNoticeType int `json:"orderNoticeType,omitempty"`
|
||
PreWarehouse int `json:"preWarehouse,omitempty"`
|
||
Province int `json:"province,omitempty"`
|
||
ProvinceName string `json:"provinceName,omitempty"`
|
||
QualifyStatus int `json:"qualifyStatus,omitempty"`
|
||
RegularFlag int `json:"regularFlag,omitempty"`
|
||
StationDeliveryStatus int `json:"stationDeliveryStatus,omitempty"`
|
||
SupportInvoice int `json:"supportInvoice,omitempty"`
|
||
SupportOfflinePurchase int `json:"supportOfflinePurchase,omitempty"`
|
||
TestMark int `json:"testMark,omitempty"`
|
||
TimeAmType int `json:"timeAmType,omitempty"`
|
||
TimePmType int `json:"timePmType,omitempty"`
|
||
Ts *utils.JavaDate `json:"ts,omitempty"`
|
||
UpdatePin string `json:"updatePin,omitempty"`
|
||
UpdateTime *utils.JavaDate `json:"updateTime,omitempty"`
|
||
VenderID string `json:"venderId,omitempty"`
|
||
VenderName string `json:"venderName,omitempty"`
|
||
WareType int `json:"wareType,omitempty"`
|
||
WhiteDelivery bool `json:"whiteDelivery,omitempty"`
|
||
Yn int8 `json:"yn,omitempty"` // 门店状态,0启用,1禁用
|
||
}
|
||
|
||
type OrderProdCommentVo struct {
|
||
CreatePin string `json:"createPin"`
|
||
CreateTime *utils.JavaDate `json:"createTime"`
|
||
ID int64 `json:"id"`
|
||
IsPraise int `json:"isPraise"`
|
||
Score int `json:"score"`
|
||
ScoreLevel int `json:"scoreLevel"`
|
||
SkuID int64 `json:"skuId"`
|
||
SkuName string `json:"skuName"`
|
||
UpdatePin string `json:"updatePin"`
|
||
UpdateTime *utils.JavaDate `json:"updateTime"`
|
||
Yn int8 `json:"yn"`
|
||
}
|
||
|
||
type OrderCommentInfo struct {
|
||
AppVersion string `json:"appVersion"`
|
||
CreatePin string `json:"createPin"`
|
||
CreateTime *utils.JavaDate `json:"createTime"`
|
||
DeliveryCarrierNo string `json:"deliveryCarrierNo"`
|
||
DeliveryConfirmTime *utils.JavaDate `json:"deliveryConfirmTime"`
|
||
DeliveryConfirmTime2 *utils.JavaDate `json:"deliveryConfirmTime2"`
|
||
DeliveryDifTime int `json:"deliveryDifTime"`
|
||
DeliveryDifTime2 int `json:"deliveryDifTime2"`
|
||
DeliveryManNo string `json:"deliveryManNo"`
|
||
DocID interface{} `json:"docId"`
|
||
ID int64 `json:"id"`
|
||
IsUpdate int `json:"isUpdate"`
|
||
OrderID int64 `json:"orderId"`
|
||
OrderProdCommentVoList []*OrderProdCommentVo `json:"orderProdCommentVoList"`
|
||
OrderType int `json:"orderType"`
|
||
OrgCode int `json:"orgCode"`
|
||
OrgCommentContent string `json:"orgCommentContent"`
|
||
OrgCommentStatus int `json:"orgCommentStatus"`
|
||
OrgCommentTime *utils.JavaDate `json:"orgCommentTime"`
|
||
OrgName string `json:"orgName"`
|
||
Score3 int `json:"score3"`
|
||
Score3Content string `json:"score3Content"`
|
||
Score4 int `json:"score4"`
|
||
Score4Content string `json:"score4Content"`
|
||
ScoreLevel int `json:"scoreLevel"`
|
||
StoreID int64 `json:"storeId"`
|
||
StoreName string `json:"storeName"`
|
||
Tags []string `json:"tags"`
|
||
TagsKey []string `json:"tagsKey"`
|
||
UpdatePin string `json:"updatePin"`
|
||
UpdateTime *utils.JavaDate `json:"updateTime"`
|
||
VenderTageKey []string `json:"venderTageKey"`
|
||
VenderTags []string `json:"venderTags"`
|
||
Yn int8 `json:"yn"`
|
||
}
|
||
|
||
type StoreDeliveryRange struct {
|
||
Adresses string `json:"adresses"`
|
||
CreatePin string `json:"createPin"`
|
||
CreateTime *utils.JavaDate `json:"createTime"`
|
||
DeliveryRange string `json:"deliveryRange"`
|
||
DeliveryRangeRadius int `json:"deliveryRangeRadius"`
|
||
DeliveryRangeType int `json:"deliveryRangeType"`
|
||
DeliveryServiceType int `json:"deliveryServiceType"`
|
||
ID int `json:"id"`
|
||
StationNo string `json:"stationNo"`
|
||
Ts *utils.JavaDate `json:"ts"`
|
||
UpdatePin string `json:"updatePin"`
|
||
UpdateTime *utils.JavaDate `json:"updateTime"`
|
||
VenderID string `json:"venderId"`
|
||
Yn int8 `json:"yn"`
|
||
}
|
||
|
||
func (a *API) GetAllCities() (cities []*CityInfo, err error) {
|
||
result, err := a.AccessAPINoPage("address/allcities", nil, nil, nil, genNoPageResultParser("code", "msg", "result", "0"))
|
||
if err == nil {
|
||
err = utils.Map2StructByJson(result, &cities, false)
|
||
}
|
||
return cities, err
|
||
}
|
||
|
||
// 获取门店编码列表接口
|
||
// 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", "0"))
|
||
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(createParams *OpStoreParams) (*CreateShopResult, error) {
|
||
result, err := a.AccessAPINoPage("store/createStore", utils.Struct2MapByJson(createParams), 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
|
||
}
|
||
|
||
func (a *API) GetStoreInfoByStationNo2(storeNo string) (storeDetail *StoreDetail, err error) {
|
||
result, err := a.AccessAPINoPage("storeapi/getStoreInfoByStationNo", utils.Params2Map("StoreNo", storeNo), nil, nil, nil)
|
||
if err == nil {
|
||
err = utils.Map2StructByJson(result, &storeDetail, false)
|
||
}
|
||
return storeDetail, 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
|
||
}
|
||
|
||
func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams, modifyCloseStatus bool) (err error) {
|
||
mapData := utils.Struct2MapByJson(updateParams)
|
||
if !modifyCloseStatus {
|
||
delete(mapData, "closeStatus")
|
||
}
|
||
_, err = a.AccessAPINoPage("store/updateStoreInfo4Open", mapData, 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
|
||
}
|
||
|
||
func (a *API) GetCommentByOrderId2(orderId int64) (orderComment *OrderCommentInfo, err error) {
|
||
jdParams := map[string]interface{}{
|
||
"orderId": orderId,
|
||
}
|
||
result, err := a.AccessAPINoPage("commentOutApi/getCommentByOrderId", jdParams, nil, nil, genNoPageResultParser("code", "msg", "result", "200"))
|
||
if err == nil {
|
||
err = utils.Map2StructByJson(result, &orderComment, false)
|
||
}
|
||
return orderComment, 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": utils.GetAPIOperator(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 (a *API) GetDeliveryRangeByStationNo2(stationNo string) (deliveryRange *StoreDeliveryRange, err error) {
|
||
jdParams := map[string]interface{}{
|
||
"stationNo": stationNo,
|
||
}
|
||
result, err := a.AccessAPINoPage("store/getDeliveryRangeByStationNo", jdParams, nil, nil, nil)
|
||
if err == nil {
|
||
err = utils.Map2StructByJson(result, &deliveryRange, false)
|
||
}
|
||
return deliveryRange, 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
|
||
}
|