美团配送与达达添加获取配送员坐标及加小费相关的API
This commit is contained in:
@@ -130,6 +130,8 @@ type ResponseResult struct {
|
||||
}
|
||||
|
||||
type CreateOrderByShopParam struct {
|
||||
// 以下为必要参数
|
||||
|
||||
DeliveryID int64 `json:"delivery_id"`
|
||||
OrderID string `json:"order_id"`
|
||||
ShopID string `json:"shop_id"`
|
||||
@@ -139,11 +141,29 @@ type CreateOrderByShopParam struct {
|
||||
ReceiverPhone string `json:"receiver_phone"`
|
||||
ReceiverLng int `json:"receiver_lng"`
|
||||
ReceiverLat int `json:"receiver_lat"`
|
||||
CoordinateType int `json:"coordinate_type"`
|
||||
GoodsValue float64 `json:"goods_value"`
|
||||
GoodsWeight float64 `json:"goods_weight"`
|
||||
// ExpectedDeliveryTime int64 `json:"expected_delivery_time"`
|
||||
OrderType int `json:"order_type"`
|
||||
|
||||
// 以下为可选参数
|
||||
|
||||
CoordinateType int `json:"coordinate_type"`
|
||||
GoodsHeight float64 `json:"goods_height,omitempty"`
|
||||
GoodsWidth float64 `json:"goods_width,omitempty"`
|
||||
GoodsLength float64 `json:"goods_length,omitempty"`
|
||||
GoodsDetail string `json:"goods_detail,omitempty"`
|
||||
GoodsPickupInfo string `json:"goods_pickup_info,omitempty"`
|
||||
GoodsDeliveryInfo string `json:"goods_delivery_info,omitempty"`
|
||||
ExpectedPickupTime int64 `json:"expected_pickup_time,omitempty"` // 期望取货时间,时区为GMT+8,当前距离Epoch(1970年1月1日) 以秒计算的时间,即unix-timestamp。
|
||||
// 期望送达时间,时区为GMT+8,当前距离Epoch(1970年1月1日) 以秒计算的时间,即unix-timestamp
|
||||
// 即时单:以发单时间 + 服务包时效作为期望送达时间(当天送服务包需客户指定期望送达时间)
|
||||
// 预约单:以客户传参数据为准(预约时间必须大于当前下单时间+服务包时效+3分钟)
|
||||
ExpectedDeliveryTime int64 `json:"expected_delivery_time,omitempty"`
|
||||
OrderType int `json:"order_type,omitempty"`
|
||||
PoiSeq string `json:"poi_seq,omitempty"`
|
||||
Note string `json:"note,omitempty"`
|
||||
CashOnDelivery float64 `json:"cash_on_delivery,omitempty"`
|
||||
CashOnPickup float64 `json:"cash_on_pickup,omitempty"`
|
||||
InvoiceTitle string `json:"invoice_title,omitempty"`
|
||||
}
|
||||
|
||||
type GoodsItem struct {
|
||||
@@ -280,7 +300,7 @@ func (a *API) CreateOrderByShop(basicParams *CreateOrderByShopParam, addParams m
|
||||
allParams := utils.MergeMaps(params, addParams)
|
||||
|
||||
if params["order_type"] != utils.Int2Str(OrderTypeBook) {
|
||||
delete(params, "expected_delivery_time")
|
||||
delete(allParams, "expected_delivery_time")
|
||||
}
|
||||
if result, err := a.AccessAPI("order/createByShop", allParams); err != nil {
|
||||
return nil, err
|
||||
@@ -289,6 +309,18 @@ func (a *API) CreateOrderByShop(basicParams *CreateOrderByShopParam, addParams m
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) CreateOrderByShop2(basicParams *CreateOrderByShopParam) (order *OrderResponse, err error) {
|
||||
params := utils.Struct2MapByJson(basicParams)
|
||||
if basicParams.OrderType != OrderTypeBook {
|
||||
delete(params, "expected_delivery_time")
|
||||
}
|
||||
if result, err := a.AccessAPI("order/createByShop", params); err != nil {
|
||||
return nil, err
|
||||
} else {
|
||||
return a.result2OrderResponse(result), nil
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) QueryOrderStatus(deliveryId int64, mtPeiSongId string) (retVal map[string]interface{}, err error) {
|
||||
params := map[string]interface{}{
|
||||
"delivery_id": deliveryId,
|
||||
@@ -355,3 +387,18 @@ func (a *API) EvaluateRider(deliveryId int64, mtPeiSongId string, score int, com
|
||||
_, err = a.AccessAPI("order/evaluate", params)
|
||||
return err
|
||||
}
|
||||
|
||||
// 获取骑手当前位置
|
||||
// https://peisong.meituan.com/open/doc#section2-9
|
||||
func (a *API) RiderLocation(deliveryId int64, mtPeiSongId string) (lng, lat int, err error) {
|
||||
params := map[string]interface{}{
|
||||
"delivery_id": deliveryId,
|
||||
"mt_peisong_id": mtPeiSongId,
|
||||
}
|
||||
result, err := a.AccessAPI("order/rider/location", params)
|
||||
if err == nil {
|
||||
lng = int(utils.ForceInterface2Int64(result.Data["lng"]))
|
||||
lat = int(utils.ForceInterface2Int64(result.Data["lat"]))
|
||||
}
|
||||
return lng, lat, err
|
||||
}
|
||||
|
||||
@@ -57,8 +57,33 @@ func TestAccessAPI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrderByShop(t *testing.T) {
|
||||
basicParams := &CreateOrderByShopParam{
|
||||
DeliveryID: 123456789,
|
||||
OrderID: "order_123456789",
|
||||
// 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km
|
||||
ShopID: "test_0001",
|
||||
DeliveryServiceCode: DeliveryServiceCodeIntime,
|
||||
ReceiverName: "xjh",
|
||||
ReceiverAddress: "九里堤",
|
||||
ReceiverPhone: "18112345678",
|
||||
ReceiverLng: 97235456,
|
||||
ReceiverLat: 31065079,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
GoodsValue: 12.34,
|
||||
GoodsWeight: 3.4,
|
||||
OrderType: OrderTypeASAP,
|
||||
}
|
||||
|
||||
order, err := api.CreateOrderByShop2(basicParams)
|
||||
handleError(t, err)
|
||||
if order != nil {
|
||||
sugarLogger.Debugf("order:%v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelOrder(t *testing.T) {
|
||||
result, err := api.CancelOrder(123456789, "1529387562097059", CancelReasonMerchantOther, "just a test")
|
||||
result, err := api.CancelOrder(123456789, "1577258173664001659", CancelReasonMerchantOther, "just a test")
|
||||
handleError(t, err)
|
||||
sugarLogger.Debug(result)
|
||||
}
|
||||
@@ -69,3 +94,11 @@ func TestEvaluateRider(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRiderLocation(t *testing.T) {
|
||||
lng, lat, err := api.RiderLocation(2997655, "1577100357518191619")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Logf("lng:%d,lat:%d", lng, lat)
|
||||
}
|
||||
|
||||
@@ -13,31 +13,6 @@ func TestSimulateShopStatus(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrderByShop(t *testing.T) {
|
||||
basicParams := &CreateOrderByShopParam{
|
||||
DeliveryID: 123456789,
|
||||
OrderID: "order_123456789",
|
||||
// 设置测试门店 id,测试门店的坐标地址为 97235456,31065079(高德坐标),配送范围3km
|
||||
ShopID: "test_0001",
|
||||
DeliveryServiceCode: DeliveryServiceCodeIntime,
|
||||
ReceiverName: "xjh",
|
||||
ReceiverAddress: "九里堤",
|
||||
ReceiverPhone: "18112345678",
|
||||
ReceiverLng: 97235456,
|
||||
ReceiverLat: 31065079,
|
||||
CoordinateType: CoordinateTypeMars,
|
||||
GoodsValue: 12.34,
|
||||
GoodsWeight: 3.4,
|
||||
OrderType: OrderTypeASAP,
|
||||
}
|
||||
|
||||
order, err := api.CreateOrderByShop(basicParams, nil)
|
||||
handleError(t, err)
|
||||
if order != nil {
|
||||
sugarLogger.Debugf("order:%v", order)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShopQuery(t *testing.T) {
|
||||
shopInfo, err := api.ShopQuery("not exist")
|
||||
if err == nil {
|
||||
|
||||
Reference in New Issue
Block a user