diff --git a/platformapi/ebaiapi/order.go b/platformapi/ebaiapi/order.go index 81104334..13c7168e 100644 --- a/platformapi/ebaiapi/order.go +++ b/platformapi/ebaiapi/order.go @@ -79,6 +79,10 @@ const ( UserApplyCancelWaitMinute = 15 // 用户申请取消订单后待处理的最大等待时间(分钟),超时自动同意 ) +const ( + ListOrderPageSize = 100 // order.list的每页条数 +) + type ExpressInfo struct { OrderID string `json:"order_id"` ExpressID string `json:"express_id"` @@ -153,6 +157,26 @@ type PartRefundInfo struct { UserFee int `json:"user_fee"` } +type ListOrderItemInfo struct { + BaiduShopID int64 `json:"baidu_shop_id"` + CreateTime int64 `json:"create_time"` + OrderFrom int `json:"order_from"` + OrderID string `json:"order_id"` + OrderStatus int `json:"order_status"` + PayStatus int `json:"pay_status"` + PayType int `json:"pay_type"` + ShopID string `json:"shop_id"` + Status int `json:"status"` + UserPhone string `json:"user_phone"` +} + +type ListOrderInfo struct { + Total int `json:"total"` + Page int `json:"Page"` + Pages int `json:"pages"` + List []*ListOrderItemInfo `json:"list"` +} + // 提供给合作方确认订单所用。 注:1、10分钟内未确认的订单系统自动取消。2、确认失败的订单请不要做餐。 2016年7月4号起,将由百度外卖负责完成订单。届时,对接方无需调用完成订单接口,继续调用可能导致订单结算有问题。 func (a *API) OrderConfirm(orderID string) (err error) { _, err = a.AccessAPI("order.confirm", map[string]interface{}{ @@ -282,6 +306,46 @@ func (a *API) OrderIdConvert(orderID string, isElemeOrder bool) (convertedOrderI return "", err } +// 查看订单列表 +// https://open-be.ele.me/dev/api/doc/v3/#api-Order_Up-order_list +// page从1开始 +func (a *API) OrderList(shopID string, baiduShopID int64, startTime, endTime int64, status int, page int) (listOrderInfo *ListOrderInfo, err error) { + params := a.genShopIDParams(shopID, baiduShopID, 0) + if startTime > 0 { + params["start_time"] = startTime + } + if endTime > 0 { + params["end_time"] = endTime + } + if status > 0 { + params["status"] = status + } + if page > 0 { + params["page"] = page + } + result, err := a.AccessAPI("order.list", params) + if err == nil { + err = utils.Map2StructByJson(result.Data, &listOrderInfo, true) + } + return listOrderInfo, err +} + +func (a *API) OrderListAll(shopID string, baiduShopID int64, startTime, endTime int64, status int) (listOrder []*ListOrderItemInfo, err error) { + page := 1 + for { + result, err := a.OrderList(shopID, baiduShopID, startTime, endTime, status, page) + if err != nil { + return nil, err + } + listOrder = append(listOrder, result.List...) + if result.Page == result.Pages { + break + } + page++ + } + return listOrder, nil +} + // 查看部分退款订单详情 func (a *API) OrderPartRefundGet(orderID string) (orderMap map[string]interface{}, err error) { result, err := a.AccessAPI("order.partrefund.get", map[string]interface{}{ diff --git a/platformapi/ebaiapi/order_test.go b/platformapi/ebaiapi/order_test.go index 286cd7eb..b4927392 100644 --- a/platformapi/ebaiapi/order_test.go +++ b/platformapi/ebaiapi/order_test.go @@ -15,6 +15,15 @@ func TestOrderGet(t *testing.T) { } } +func TestOrderList(t *testing.T) { + result, err := api.OrderList("", 0, 0, 0, 0, 0) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + func TestOrderPartRefundGet(t *testing.T) { result, err := api.OrderPartRefundGet("1557459492221457830") if err != nil {