217 lines
6.5 KiB
Go
217 lines
6.5 KiB
Go
package ebaiapi
|
||
|
||
import (
|
||
"time"
|
||
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
const (
|
||
CancelTypeNotInServiceArea = "1"
|
||
CancelTypeShopClosed = "2"
|
||
CancelTypeSoldOut = "3"
|
||
CancelTypePriceChanged = "4"
|
||
CancelTypeClientCanceled = "5"
|
||
CancelTypeDuplicatedOrder = "6"
|
||
CancelTypeTooBusy = "7"
|
||
CancelTypeCanNotContactClient = "8"
|
||
CancelTypeFakeOrder = "9"
|
||
CancelTypePushOrderFailed = "53"
|
||
CancelTypeCustom = "-1"
|
||
)
|
||
|
||
const (
|
||
OrderStatusNew = "1"
|
||
OrderStatusAccepted = "5"
|
||
OrderStatusCourierAccepted = "7"
|
||
OrderStatusCourierPickedup = "8"
|
||
OrderStatusFinished = "9"
|
||
OrderStatusCanceled = "10"
|
||
)
|
||
|
||
const (
|
||
WaybillStatusNew = "2"
|
||
WaybillStatusRequestDelivery = "3"
|
||
WaybillStatusWait4Courier = "4"
|
||
WaybillStatusCourierAccepted = "7"
|
||
WaybillStatusCourierPickedup = "8"
|
||
WaybillStatusDeliveryCancled = "15"
|
||
WaybillStatusFinished = "16"
|
||
WaybillStatusExceptional = "17"
|
||
WaybillStatusSelfDelivery = "18"
|
||
WaybillStatusNotInDelivering = "19"
|
||
WaybillStatusDeliveryRejected = "20"
|
||
)
|
||
|
||
const (
|
||
OrderPartRefundSuccess = "20" // 部分取消订单退款成功状态20
|
||
AfterOrderFinishedCancelType = "2" // 订单完成后全单退款
|
||
OrderUserCancelSuccessA = "40" // 全单取消订单退款成功状态40 客服同意
|
||
OrderUserCancelSuccessB = "60" // 全单取消订单退款成功状态60 商家同意
|
||
SendImmediatelySelf = 2 // 饿百商家自送的配送状态
|
||
)
|
||
|
||
const (
|
||
OrderFromBaidu = "1"
|
||
OrderFromElm = "2"
|
||
)
|
||
|
||
type ExpressInfo struct {
|
||
OrderID string `json:"order_id"`
|
||
ExpressID string `json:"express_id"`
|
||
ExpressCompany string `json:"express_company"`
|
||
}
|
||
|
||
type PrivateMobileInfo struct {
|
||
ShortNumber string `json:"short_number"`
|
||
ExpireDate *time.Time `json:"expire_date"`
|
||
}
|
||
|
||
// 提供给合作方确认订单所用。 注:1、10分钟内未确认的订单系统自动取消。2、确认失败的订单请不要做餐。 2016年7月4号起,将由百度外卖负责完成订单。届时,对接方无需调用完成订单接口,继续调用可能导致订单结算有问题。
|
||
func (a *API) OrderConfirm(orderID string) (err error) {
|
||
_, err = a.AccessAPI("order.confirm", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 提供给合作方取消订单所用。 注:1、百度物流配送且已经确认的订单无法取消。
|
||
func (a *API) OrderCancel(orderID, cancelType, cancelReason string) (err error) {
|
||
_, err = a.AccessAPI("order.cancel", map[string]interface{}{
|
||
"order_id": orderID,
|
||
"type": cancelType,
|
||
"reason": cancelReason,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 蜂鸟众包订单呼叫骑士配送,仅限蜂鸟众包商户调用
|
||
func (a *API) OrderCallDelivery(orderID string) (err error) {
|
||
_, err = a.AccessAPI("order.callDelivery", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 蜂鸟众包订单取消呼叫骑士配送,仅限蜂鸟众包商户调用。
|
||
func (a *API) OrderCancelDelivery(orderID string) (err error) {
|
||
_, err = a.AccessAPI("order.cancelDelivery", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 饿了么自配送订单回传订单已送出状态
|
||
// 此接口目前只支持饿了么侧订单调用
|
||
func (a *API) OrderSendOut(orderID, phone string) (err error) {
|
||
_, err = a.AccessAPI("order.sendout", map[string]interface{}{
|
||
"order_id": orderID,
|
||
"phone": phone,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 饿了么自配送订单回传订单送达状态,调用成功后订单状态变为已完成。需先调用订单送出接口,且接单5分钟后可调用
|
||
func (a *API) OrderComplete(orderID, phone string) (err error) {
|
||
_, err = a.AccessAPI("order.complete", map[string]interface{}{
|
||
"order_id": orderID,
|
||
"phone": phone,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 提供给合作方在配送异常或物流拒单后选择自行配送
|
||
func (a *API) OrderSwitchselfdelivery(orderID string) (err error) {
|
||
_, err = a.AccessAPI("order.switchselfdelivery", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
// 查看订单详情
|
||
func (a *API) OrderGet(orderID string) (orderMap map[string]interface{}, err error) {
|
||
result, err := a.AccessAPI("order.get", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
if err == nil {
|
||
return result.Data.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
// 设置订单快递单号
|
||
func (a *API) OrderExpressCreate(shopID string, expressList []*ExpressInfo) (status int, err error) {
|
||
result, err := a.AccessAPI("order.express.create", map[string]interface{}{
|
||
KeyShopID: shopID,
|
||
"express_list": expressList,
|
||
})
|
||
if err == nil {
|
||
return int(utils.MustInterface2Int64(result.Data.(map[string]interface{})["status"])), nil
|
||
}
|
||
return 0, err
|
||
}
|
||
|
||
func (a *API) OrderPrivateInfo(orderID string) (mobileInfo *PrivateMobileInfo, err error) {
|
||
result, err := a.AccessAPI("order.privateinfo", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
if err == nil {
|
||
mapData := result.Data.(map[string]interface{})
|
||
mobileInfo = &PrivateMobileInfo{
|
||
ShortNumber: mapData["short_number"].(string),
|
||
}
|
||
expireDate := utils.Interface2String(mapData["expire_date"])
|
||
if expireDate != "" {
|
||
tmpTime := utils.Str2Time(expireDate)
|
||
mobileInfo.ExpireDate = &tmpTime
|
||
}
|
||
return mobileInfo, nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
func (a *API) OrderDeliveryGet(orderID string) (deliveryInfo map[string]interface{}, err error) {
|
||
result, err := a.AccessAPI("order.delivery.get", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
if err == nil {
|
||
return result.Data.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
func (a *API) OrderIdConvert(orderID string, isElemeOrder bool) (convertedOrderID string, err error) {
|
||
key := "order_id"
|
||
resultKey := "eleme_order_id"
|
||
if isElemeOrder {
|
||
key = "eleme_order_id"
|
||
resultKey = "order_id"
|
||
}
|
||
result, err := a.AccessAPI("order.id.convert", map[string]interface{}{
|
||
key: orderID,
|
||
})
|
||
if err == nil {
|
||
return utils.Interface2String(result.Data.(map[string]interface{})[resultKey]), nil
|
||
}
|
||
return "", err
|
||
}
|
||
|
||
// 查看售后订单详情
|
||
func (a *API) OrderPartrefundGet(orderID string) (orderMap map[string]interface{}, err error) {
|
||
result, err := a.AccessAPI("order.partrefund.get", map[string]interface{}{
|
||
"order_id": orderID,
|
||
})
|
||
if err == nil {
|
||
return result.Data.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
func (a *API) SmartOrderIdConvert(orderID string) (convertedOrderID string, err error) {
|
||
return a.OrderIdConvert(orderID, isOrderIDEleme(orderID))
|
||
}
|
||
|
||
func isOrderIDEleme(orderID string) bool {
|
||
return len(orderID) == len("3026328756122155111")
|
||
}
|