Files
baseapi/platformapi/jdapi/store.go
2019-11-09 10:54:36 +08:00

443 lines
21 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"
)
const (
CarrierNoCrowdSourcing = 9966 // 众包
CarrierNoSelfDelivery = 2938 // 自送
CarrierNoSelfTake = 9999 // 到店自提
)
const (
CoordinateTypeGoogle = 1 // 谷歌
CoordinateTypeBaidu = 2 // 百度
CoordinateTypeAutonavi = 3 // 高德
CoordinateTypeTencent = 4 // 腾讯
)
const (
FreightFreeTypeAll = 0 // 全免
FreightFreeTypeBase = 1 // 免基础运费
FreightFreeTypePartBase = 2 // 免部分基础运费
)
const (
MaxStoreNameLen = 13 // 门店名称最大长度2个英文或数字算一位
)
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"` // 0是有意义的值所以不能是omitempty
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"` // 0是有意义的值所以不能是omitempty
StoreNotice string `json:"storeNotice,omitempty"`
StandByPhone string `json:"standByPhone,omitempty"`
// 以下仅用于查询
AllowRangeOptimized int `json:"allowRangeOptimized"`
CacheKey4StoreList string `json:"cacheKey4StoreList"`
CarrierNo int `json:"carrierNo"`
CityName string `json:"cityName"`
Coordinate string `json:"coordinate"`
CoordinateAddress string `json:"coordinateAddress"`
CountyName string `json:"countyName"`
CreatePin string `json:"createPin"`
CreateTime *utils.JavaDate `json:"createTime"`
ID int64 `json:"id"`
IndustryTag int `json:"industryTag"`
InnerNoStatus int `json:"innerNoStatus"`
IsAutoOrder int `json:"isAutoOrder"` // 是否自动接单0:是1:否
IsMembership int `json:"isMembership"`
IsNoPaper int `json:"isNoPaper"`
OnlineTime *utils.JavaDate `json:"onlineTime"`
OrderAging int `json:"orderAging"`
OrderNoticeType int `json:"orderNoticeType"`
PreWarehouse int `json:"preWarehouse"`
Province int `json:"province"`
ProvinceName string `json:"provinceName"`
QualifyStatus int `json:"qualifyStatus"`
RegularFlag int `json:"regularFlag"`
StationDeliveryStatus int `json:"stationDeliveryStatus"`
SupportInvoice int `json:"supportInvoice"`
SupportOfflinePurchase int `json:"supportOfflinePurchase"`
TestMark int `json:"testMark"`
TimeAmType int `json:"timeAmType"`
TimePmType int `json:"timePmType"`
Ts *utils.JavaDate `json:"ts"`
UpdatePin string `json:"updatePin"`
UpdateTime *utils.JavaDate `json:"updateTime"`
VenderID string `json:"venderId"`
VenderName string `json:"venderName"`
WareType int `json:"wareType"`
WhiteDelivery bool `json:"whiteDelivery"`
Yn int8 `json:"yn"` // 门店状态,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"`
}
type FreeFreightTime struct {
FreeBeginTime string `json:"freeBeginTime,omitempty"`
FreeEndTime string `json:"freeEndTime,omitempty"`
}
type FreeFreightInfo struct {
FullFreeMoney int64 `json:"fullFreeMoney,omitempty"`
FreeType int `json:"freeType"`
FreeMoney int64 `json:"freeMoney,omitempty"`
OutActivityID string `json:"outActivityId,omitempty"`
FreeFreightTimes []*FreeFreightTime `json:"freeFreightTimes,omitempty"`
}
type UpdateStoreFreightParam struct {
UserPin string `json:"userPin"`
OpenDistanceFreight bool `json:"openDistanceFreight"`
IsFullFree bool `json:"isFullFree"`
StationNo string `json:"stationNo,omitempty"`
MerchantStationNo string `json:"merchantStationNo,omitempty"`
StartCharge int64 `json:"startCharge,omitempty"`
SelfDeliveryFreightMoney int64 `json:"selfDeliveryFreightMoney,omitempty"`
StartBeginTime string `json:"startBeginTime,omitempty"`
StartEndTime string `json:"startEndTime,omitempty"`
DistanceFreightThreshold int `json:"distanceFreightThreshold,omitempty"`
DistanceUnit int `json:"distanceUnit,omitempty"`
DistanceFreight int64 `json:"distanceFreight,omitempty"`
FreeFreightInfoList []*FreeFreightInfo `json:"freeFreightInfoList,omitempty"`
}
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) {
createParams.Operator = utils.GetAPIOperator(createParams.Operator)
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) {
updateParams.Operator = utils.GetAPIOperator(updateParams.Operator)
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,
}
// 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
}
// 获取门店配送范围接口
// 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
}
// 根据门店编码修改运费起送价、满免以及商家自送运费接口
// https://openo2o.jddj.com/staticnew/widgets/resources.html?groupid=194&apiid=997977a13c62449ba15f3db3b4aec932
func (a *API) UpdateStoreFreightConfigNew(upateParam *UpdateStoreFreightParam) (err error) {
if upateParam.UserPin != "" {
upateParam.UserPin = utils.GetAPIOperator(upateParam.UserPin)
}
jdParams := utils.Struct2MapByJson(upateParam)
_, err = a.AccessAPINoPage("freight/updateStoreFreightConfigNew", jdParams, nil, nil, genNoPageResultParser("code", "detail", "", "0"))
return err
}