From 68a0c24a6a2355b6171d8a7ddfd12caed7ac5163 Mon Sep 17 00:00:00 2001 From: gazebo Date: Fri, 10 May 2019 17:48:58 +0800 Subject: [PATCH] =?UTF-8?q?-=20ebai=E8=B0=83=E6=95=B4=E4=B8=80=E4=BA=9B?= =?UTF-8?q?=E5=B8=B8=E9=87=8F=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/ebaiapi/callback.go | 46 ++++++++++++++ platformapi/ebaiapi/order.go | 102 ++++++++++++++++++++++++------ platformapi/ebaiapi/order_test.go | 13 +++- 3 files changed, 140 insertions(+), 21 deletions(-) diff --git a/platformapi/ebaiapi/callback.go b/platformapi/ebaiapi/callback.go index bc03351b..497400f2 100644 --- a/platformapi/ebaiapi/callback.go +++ b/platformapi/ebaiapi/callback.go @@ -37,6 +37,38 @@ type CallbackMsg struct { Cmd string `json:"cmd"` Timestamp int64 `json:"timestamp"` Body map[string]interface{} `json:"body"` + Data interface{} `json:"data"` +} + +type CBPartRefundInfo struct { + OrderID int64 `json:"order_id"` + RefundID string `json:"refund_id"` + Type int `json:"type"` + Status int `json:"status"` + AdditionReason string `json:"addition_reason"` + Photos []string `json:"photos"` + ReasonType string `json:"reason_type"` + Reason string `json:"reason"` + RefundProducts []*struct { + SkuID string `json:"sku_id"` + Upc string `json:"upc"` + CustomSkuID string `json:"custom_sku_id"` + Name string `json:"name"` + Number int `json:"number"` + TotalRefund int64 `json:"total_refund"` + ShopEleRefund int64 `json:"shop_ele_refund"` + } `json:"refund_products"` + RefundPrice int64 `json:"refund_price"` +} + +type CBUserCancelInfo struct { + OrderID int64 `json:"order_id"` + CancelReason string `json:"cancel_reason"` + AdditionReason string `json:"addition_reason"` + RefuseReason string `json:"refuse_reason"` + Pictures []string `json:"pictures"` + Type int `json:"type"` + CancelType int `json:"cancel_type"` } func (a *API) Err2CallbackResponse(cmd string, err error, data interface{}) *CallbackResponse { @@ -107,6 +139,20 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR } msg.Cmd = GetCmd(request) msg.Timestamp = utils.Str2Int64(utils.Interface2String(request.FormValue("timestamp"))) + var tmpObj interface{} + switch msg.Cmd { + case CmdOrderPartRefund: + var partRefundData CBPartRefundInfo + tmpObj = &partRefundData + case CmdOrderUserCancel: + var userCancelData CBUserCancelInfo + tmpObj = &userCancelData + } + if tmpObj != nil { + if utils.Map2StructByJson(msg.Body, tmpObj, true) == nil { + msg.Data = tmpObj + } + } return msg, nil } return nil, a.Err2CallbackResponse("", err, nil) diff --git a/platformapi/ebaiapi/order.go b/platformapi/ebaiapi/order.go index 8fbd66cf..00a19d23 100644 --- a/platformapi/ebaiapi/order.go +++ b/platformapi/ebaiapi/order.go @@ -45,27 +45,27 @@ const ( const ( // 订单下行 - order.partrefund.push-部分退款订单信息推送 - OrderPartRefuncTypeMerchant = "1" // 表示商户发起的部分退款 - OrderPartRefuncTypeCustomer = "2" // 表示用户发起的部分退款 - OrderPartRefuncTypeCS = "3" // 表示客服直接发起的部分退款 + OrderPartRefuncTypeMerchant = 1 // 表示商户发起的部分退款 + OrderPartRefuncTypeCustomer = 2 // 表示用户发起的部分退款 + OrderPartRefuncTypeCS = 3 // 表示客服直接发起的部分退款 - OrderPartRefundApply = "10" // 表示商家/用户发起部分退款申请 - OrderPartRefundSuccess = "20" // 表示部分退款成功 - OrderPartRefundUserApplyArbitration = "30" // 用户申请仲裁,客服介入 - OrderPartRefundFailed = "40" // 表示部分退款失败 - OrderPartRefundMerchantRefused = "50" // 表示商家拒绝用户发起的部分退款申请 + OrderPartRefundApply = 10 // 表示商家/用户发起部分退款申请 + OrderPartRefundSuccess = 20 // 表示部分退款成功 + OrderPartRefundUserApplyArbitration = 30 // 用户申请仲裁,客服介入 + OrderPartRefundFailed = 40 // 表示部分退款失败 + OrderPartRefundMerchantRefused = 50 // 表示商家拒绝用户发起的部分退款申请 // 订单下行 - order.user.cancel-用户申请订单取消/退款 - OrderUserCancelApply = "10" // 发起申请 - OrderUserCancelCSIntervene = "20" // 客服介入 - OrderUserCancelCSRefused = "30" // 客服拒绝 - OrderUserCancelCSAgreed = "40" // 客服同意 - OrderUserCancelMerchantRefused = "50" // 商户拒绝 - OrderUserCancelMerchantAgreed = "60" // 商家同意 - OrderUserCancelInvalid = "70" // 申请失效 + OrderUserCancelApply = 10 // 发起申请 + OrderUserCancelCSIntervene = 20 // 客服介入 + OrderUserCancelCSRefused = 30 // 客服拒绝 + OrderUserCancelCSAgreed = 40 // 客服同意 + OrderUserCancelMerchantRefused = 50 // 商户拒绝 + OrderUserCancelMerchantAgreed = 60 // 商家同意 + OrderUserCancelInvalid = 70 // 申请失效 - OrderUserCancelTypeBeforeSale = "1" // 表示订单完成前用户全单取消申请流程 - OrderUserCancelTypeAfterSale = "2" // 表示订单完成后用户全单退款申请流程 + OrderUserCancelTypeBeforeSale = 1 // 表示订单完成前用户全单取消申请流程 + OrderUserCancelTypeAfterSale = 2 // 表示订单完成后用户全单退款申请流程 SendImmediatelySelf = 6 // 饿百商家自送的配送状态 ) @@ -97,6 +97,62 @@ type RefundSku struct { Number string `json:"number"` } +type OrderDetailInfo struct { + CustomSkuID string `json:"custom_sku_id"` + Name string `json:"name"` + Number int `json:"number"` + ProductFeatures []interface{} `json:"product_features"` + ProductFee int `json:"product_fee"` + ProductPrice int `json:"product_price"` + ProductSubsidy struct { + AgentRate int `json:"agent_rate"` + BaiduRate int `json:"baidu_rate"` + Discount int `json:"discount"` + DiscountDetail []*struct { + ActivityID string `json:"activity_id"` + BaiduRate int `json:"baidu_rate"` + ShopRate int `json:"shop_rate"` + Type string `json:"type"` + } `json:"discount_detail"` + LogisticsRate int `json:"logistics_rate"` + ShopRate int `json:"shop_rate"` + UserRate int `json:"user_rate"` + } `json:"product_subsidy"` + SkuID string `json:"sku_id"` + TotalWeight int `json:"total_weight"` + Upc string `json:"upc"` +} + +type RefundDetailInfo struct { + ApplyTime string `json:"apply_time"` + CustomSkuID string `json:"custom_sku_id"` + Desc string `json:"desc"` + Name string `json:"name"` + Number int `json:"number"` + RefundID string `json:"refund_id"` + ShopEleRefund int `json:"shop_ele_refund"` + SkuID string `json:"sku_id"` + Status int `json:"status"` + TotalRefund int `json:"total_refund"` + Type int `json:"type"` + Upc string `json:"upc"` +} + +type PartRefundInfo struct { + Commission int `json:"commission"` + Fee int `json:"fee"` + OrderDetail []*OrderDetailInfo `json:"order_detail"` + OrderID string `json:"order_id"` + PackageFee int `json:"package_fee"` + RefundDetail []*RefundDetailInfo `json:"refund_detail"` + RefundPrice int `json:"refund_price"` + SendFee int `json:"send_fee"` + ShopFee int `json:"shop_fee"` + TotalPrice int `json:"total_price"` + Type int `json:"type"` + UserFee int `json:"user_fee"` +} + // 提供给合作方确认订单所用。 注:1、10分钟内未确认的订单系统自动取消。2、确认失败的订单请不要做餐。 2016年7月4号起,将由百度外卖负责完成订单。届时,对接方无需调用完成订单接口,继续调用可能导致订单结算有问题。 func (a *API) OrderConfirm(orderID string) (err error) { _, err = a.AccessAPI("order.confirm", map[string]interface{}{ @@ -226,8 +282,8 @@ func (a *API) OrderIdConvert(orderID string, isElemeOrder bool) (convertedOrderI return "", err } -// 查看售后订单详情 -func (a *API) OrderPartrefundGet(orderID string) (orderMap map[string]interface{}, err error) { +// 查看部分退款订单详情 +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, }) @@ -237,6 +293,14 @@ func (a *API) OrderPartrefundGet(orderID string) (orderMap map[string]interface{ return nil, err } +func (a *API) OrderPartRefundGet2(orderID string) (partRefundInfo *CBPartRefundInfo, err error) { + result, err := a.OrderPartRefundGet(orderID) + if err == nil { + err = utils.Map2StructByJson(result, &partRefundInfo, false) + } + return partRefundInfo, err +} + func (a *API) SmartOrderIdConvert(orderID string) (convertedOrderID string, err error) { return a.OrderIdConvert(orderID, isOrderIDEleme(orderID)) } diff --git a/platformapi/ebaiapi/order_test.go b/platformapi/ebaiapi/order_test.go index 29988f50..286cd7eb 100644 --- a/platformapi/ebaiapi/order_test.go +++ b/platformapi/ebaiapi/order_test.go @@ -15,8 +15,17 @@ func TestOrderGet(t *testing.T) { } } -func TestOrderPartrefundGet(t *testing.T) { - result, err := api.OrderPartrefundGet("1556529608021993938") +func TestOrderPartRefundGet(t *testing.T) { + result, err := api.OrderPartRefundGet("1557459492221457830") + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + +func TestOrderPartRefundGet2(t *testing.T) { + result, err := api.OrderPartRefundGet2("1557459492221457830") if err != nil { t.Fatal(err) } else {