diff --git a/platformapi/jdapi/store.go b/platformapi/jdapi/store.go index 91812604..a6c42796 100644 --- a/platformapi/jdapi/store.go +++ b/platformapi/jdapi/store.go @@ -29,6 +29,12 @@ const ( KeyStandByPhone = "standByPhone" ) +const ( + CarrierNoCrowdSourcing = 9966 // 众包 + CarrierNoSelfDelivery = 2938 // 自送 + CarrierNoSelfTake = 9999 // 到店自提 +) + type CreateShopResult struct { DeliveryRangeType int `json:"deliveryRangeType"` CoordinatePoints string `json:"coordinatePoints"` @@ -44,11 +50,164 @@ type CityInfo struct { Yn int `json:"yn"` } -const ( - CarrierNoCrowdSourcing = 9966 // 众包 - CarrierNoSelfDelivery = 2938 // 自送 - CarrierNoSelfTake = 9999 // 到店自提 -) +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,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,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 int `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")) @@ -75,23 +234,8 @@ func (a *API) GetStationsByVenderId() ([]string, error) { // 新增不带资质的门店信息接口 // 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) { +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{}) @@ -116,6 +260,14 @@ func (a *API) GetStoreInfoByStationNo(storeNo string) (map[string]interface{}, e 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 { @@ -128,6 +280,11 @@ func (a *API) UpdateStoreInfo4Open(storeNo, userName string, addParams map[strin return err } +func (a *API) UpdateStoreInfo4Open2(updateParams *OpStoreParams) (err error) { + _, err = a.AccessAPINoPage("store/updateStoreInfo4Open", utils.Struct2MapByJson(updateParams), 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) { @@ -141,6 +298,17 @@ func (a *API) GetCommentByOrderId(orderId int64) (map[string]interface{}, error) 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 { @@ -186,6 +354,17 @@ func (a *API) GetDeliveryRangeByStationNo(stationNo string) (map[string]interfac 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 { diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 2b62eeab..6676e86a 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -11,6 +11,9 @@ import ( const ( mustExistStoreID = "11053496" mustExistStoreJXID = "2" + + // mustExistStoreID = "11734851" + // mustExistStoreJXID = "100118" ) func TestGetAllCities(t *testing.T) { @@ -39,56 +42,51 @@ func TestGetStationsByVenderId(t *testing.T) { } func TestGetStoreInfoByStationNo(t *testing.T) { - result, err := api.GetStoreInfoByStationNo(mustExistStoreID) + result, err := api.GetStoreInfoByStationNo2(mustExistStoreID) if err != nil { t.Fatal(err) } - outSystemId := result["outSystemId"].(string) - if outSystemId != "100285" { - baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", outSystemId) + t.Log(utils.Format4Output(result, false)) + if result.OutSystemID != mustExistStoreJXID { + baseapi.SugarLogger.Fatalf("outSystemId is not correct, its:%s", result.OutSystemID) } } func TestUpdateStoreInfo4Open(t *testing.T) { - result, err := api.GetStoreInfoByStationNo(mustExistStoreID) + result, err := api.GetStoreInfoByStationNo2(mustExistStoreID) if err != nil { t.Fatal(err) } - oldAddress := result["stationAddress"].(string) - testAddress := oldAddress + "T" - addParams := map[string]interface{}{ - "stationAddress": testAddress, + oldAddress := result.StationAddress + params := &OpStoreParams{ + StationNo: mustExistStoreID, + Operator: "test", + StationAddress: oldAddress + "T", } - err = api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) + err = api.UpdateStoreInfo4Open2(params) if err != nil { t.Fatal(err) } - result, err = api.GetStoreInfoByStationNo(mustExistStoreID) - newAddress := result["stationAddress"].(string) - if newAddress != testAddress { + result, err = api.GetStoreInfoByStationNo2(mustExistStoreID) + newAddress := result.StationAddress + if newAddress != params.StationAddress { t.Fatalf("address not match, newAddress:%s, oldAddress:%s", newAddress, oldAddress) } - addParams = map[string]interface{}{ - "stationAddress": oldAddress, - } - api.UpdateStoreInfo4Open(mustExistStoreID, "test", addParams) + params.StationAddress = oldAddress + api.UpdateStoreInfo4Open2(params) if err != nil { t.Fatal(err) } - } + func TestGetCommentByOrderId(t *testing.T) { - testOrderID := int64(822347450000922) - result, err := api.GetCommentByOrderId(testOrderID) + testOrderID := int64(922520919000622) + result, err := api.GetCommentByOrderId2(testOrderID) if err != nil { t.Fatal(err.Error()) } - gotOrderID := utils.MustInterface2Int64(result["orderId"]) - if gotOrderID != testOrderID { - t.Fatalf("GetCommentByOrderId wrong, gotOrderID:%d", gotOrderID) - } t.Log(utils.Format4Output(result, false)) } @@ -115,27 +113,27 @@ func TestUpdateStoreConfig4Open(t *testing.T) { } func TestGetDeliveryRangeByStationNo(t *testing.T) { - const testStoreID = "11738152" - result, err := api.GetDeliveryRangeByStationNo(testStoreID) - if err != nil { - t.Fatal(err) - } - result2, err := api.GetStoreInfoByStationNo(testStoreID) + const testStoreID = "11734851" + result, err := api.GetDeliveryRangeByStationNo2(testStoreID) if err != nil { t.Fatal(err) } baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) - baseapi.SugarLogger.Debug(utils.Format4Output(result2, false)) - deliveryRange := result["deliveryRange"].(string) - params := map[string]interface{}{ - "lng": result2["lng"], - "lat": result2["lat"], - "coordinateType": 3, - "deliveryRangeType": 2, - "coordinatePoints": deliveryRange, - } - err = api.UpdateStoreInfo4Open(testStoreID, "test", params) +} + +func TestDisableAutoOrder4AllStores(t *testing.T) { + storeIDs, err := api.GetStationsByVenderId() if err != nil { t.Fatal(err) } + for _, storeID := range storeIDs { + if storeInfo, err := api.GetStoreInfoByStationNo2(storeID); err == nil { + if storeInfo.Yn == 0 && storeInfo.IsAutoOrder == 0 { + t.Log(storeID) + api.UpdateStoreConfig4Open(storeID, false) + } + t.Log(utils.Format4Output(storeInfo, false)) + } + break + } }