193 lines
5.8 KiB
Go
193 lines
5.8 KiB
Go
package mtwmapi
|
||
|
||
import (
|
||
"git.rosy.net.cn/baseapi/utils"
|
||
)
|
||
|
||
const (
|
||
MaxBatchPullPhoneNumberLimit = 1000
|
||
)
|
||
|
||
// http://developer.waimai.meituan.com/home/doc/food/99
|
||
const (
|
||
OrderStatusUserCommitted = "1" // 用户已提交订单
|
||
OrderStatusNew = "2" // 向商家推送订单
|
||
OrderStatusReceived = "3" // 商家已收到
|
||
OrderStatusAccepted = "4" // 商家已确认
|
||
OrderStatusDelivering = "6" // 订单配送中
|
||
OrderStatusDelivered = "7" // 订单已送达
|
||
OrderStatusFinished = "8" // 订单已完成
|
||
OrderStatusCanceled = "9" // 订单已取消
|
||
)
|
||
|
||
const (
|
||
WaybillStatusWait4Delivery = "0" // 配送单发往配送
|
||
WaybillStatusAccepted = "10" // 配送单已确认
|
||
WaybillStatusCourierArrived = "15" // 骑手已到店
|
||
WaybillStatusPickedup = "20" // 骑手已取餐
|
||
WaybillStatusDelivered = "40" // 骑手已送达
|
||
WaybillStatusCanceled = "100" // 配送单已取消
|
||
)
|
||
|
||
const (
|
||
CancelReasonAcceptTimeout = 1001 // 系统取消,超时未确认
|
||
CancelReasonPayTimeout = 1002 // 系统取消,在线支付订单15分钟未支付
|
||
CancelReasonPayCanceled = 1101 // 用户取消,在线支付中取消
|
||
CancelReasonCancelBeforeAccepted = 1102 // 用户取消,商家确认前取消
|
||
CancelReasonRefundCanceled = 1103 // 用户取消,用户退款取消
|
||
CancelReasonWrongOrder = 1201 // 客服取消,用户下错单
|
||
CancelReasonUserTest = 1202 // 客服取消,用户测试
|
||
CancelReasonDuplicatedOrder = 1203 // 客服取消,重复订单
|
||
CancelReasonCSOther = 1204 // 客服取消,其他原因
|
||
CancelReasonOther = 1301 // 其他原因
|
||
)
|
||
|
||
const (
|
||
NotifyTypeSuccess = "agree"
|
||
)
|
||
|
||
const (
|
||
UserApplyCancelWaitMinute = 30 // 用户申请退款后,商家未在30分钟内(大连锁商家为3小时内)处理退款请求,系统将自动同意退款
|
||
)
|
||
|
||
type RefundSku struct {
|
||
AppFoodCode string `json:"app_food_code"`
|
||
SkuID string `json:"sku_id,omitempty"`
|
||
Count int `json:"count"`
|
||
}
|
||
|
||
func (a *API) OrderReceived(orderID int64) (err error) {
|
||
_, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderConfirm(orderID int64) (err error) {
|
||
_, err = a.AccessAPI("order/confirm", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderCancel(orderID int64, cancelReason string, cancelReasonCode int) (err error) {
|
||
_, err = a.AccessAPI("order/cancel", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
"reason": cancelReason,
|
||
"reason_code": cancelReasonCode,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderDelivering(orderID int64) (err error) {
|
||
_, err = a.AccessAPI("order/delivering", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderArrived(orderID int64) (err error) {
|
||
_, err = a.AccessAPI("order/arrived", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderRefundAgree(orderID int64, reason string) (err error) {
|
||
_, err = a.AccessAPI("order/refund/agree", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
"reason": reason,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderRefundReject(orderID int64, reason string) (err error) {
|
||
_, err = a.AccessAPI("order/refund/reject", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
"reason": reason,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderApplyPartRefund(orderID int64, reason string, removeSkuList []*RefundSku) (err error) {
|
||
_, err = a.AccessAPI("order/applyPartRefund", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
"reason": reason,
|
||
"food_data": removeSkuList,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderViewStatus(orderID int64) (status int, err error) {
|
||
result, err := a.AccessAPI("order/viewstatus", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
if err == nil {
|
||
// baseapi.SugarLogger.Debug(result)
|
||
return int(utils.MustInterface2Int64(result.(map[string]interface{})["status"])), nil
|
||
}
|
||
return 0, err
|
||
}
|
||
|
||
func (a *API) OrderGetOrderDetail(orderID int64, isMTLogistics bool) (orderInfo map[string]interface{}, err error) {
|
||
params := map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
}
|
||
if isMTLogistics {
|
||
params["is_mt_logistics"] = 1
|
||
}
|
||
result, err := a.AccessAPI("order/getOrderDetail", true, params)
|
||
if err == nil {
|
||
return result.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
func (a *API) OrderLogisticsPush(orderID int64, reason string) (err error) {
|
||
_, err = a.AccessAPI("order/logistics/push", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderLogisticsCancel(orderID int64, reason string) (err error) {
|
||
_, err = a.AccessAPI("order/logistics/cancel", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|
||
|
||
func (a *API) OrderLogisticsStatus(orderID int64) (status map[string]interface{}, err error) {
|
||
result, err := a.AccessAPI("order/logistics/status", true, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
if err == nil {
|
||
return result.(map[string]interface{}), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
// limit最大为MaxBatchPullPhoneNumberLimit = 1000
|
||
func (a *API) OrderBatchPullPhoneNumber(poiCode string, offset, limit int) (realNumberList []map[string]interface{}, err error) {
|
||
params := map[string]interface{}{
|
||
"offset": offset,
|
||
"limit": limit,
|
||
}
|
||
if poiCode != "" {
|
||
params[KeyAppPoiCode] = poiCode
|
||
}
|
||
result, err := a.AccessAPI("order/batchPullPhoneNumber", false, params)
|
||
if err == nil {
|
||
return utils.Slice2MapSlice(result.([]interface{})), nil
|
||
}
|
||
return nil, err
|
||
}
|
||
|
||
// 专快混配送转为商家自配送
|
||
func (a *API) OrderLogisticsChange2Self(orderID int64) (err error) {
|
||
_, err = a.AccessAPI("order/logistics/change/poi_self", false, map[string]interface{}{
|
||
KeyOrderID: orderID,
|
||
})
|
||
return err
|
||
}
|