From 2ae94c589adb646c759bb822662f882d35adc6ee Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 1 May 2019 13:36:21 +0800 Subject: [PATCH] - mtwm.GetOrderRefundDetail --- platformapi/mtwmapi/callback.go | 5 +++ platformapi/mtwmapi/callback_test.go | 19 +++++++++++ platformapi/mtwmapi/order.go | 48 ++++++++++++++++++++++++++++ platformapi/mtwmapi/order_test.go | 14 ++++++-- 4 files changed, 84 insertions(+), 2 deletions(-) create mode 100644 platformapi/mtwmapi/callback_test.go diff --git a/platformapi/mtwmapi/callback.go b/platformapi/mtwmapi/callback.go index e37b8b90..6ab2c8f0 100644 --- a/platformapi/mtwmapi/callback.go +++ b/platformapi/mtwmapi/callback.go @@ -98,3 +98,8 @@ func (a *API) GetCallbackMsg(request *http.Request) (msg *CallbackMsg, callbackR } return msg, callbackResponse } + +func (a *API) GetRefundSkuDetailFromMsg(msg *CallbackMsg) (refundSkuDetail []*RefundSkuDetail) { + utils.UnmarshalUseNumber([]byte(msg.Data.Get("food")), &refundSkuDetail) + return refundSkuDetail +} diff --git a/platformapi/mtwmapi/callback_test.go b/platformapi/mtwmapi/callback_test.go new file mode 100644 index 00000000..6c2ef1b4 --- /dev/null +++ b/platformapi/mtwmapi/callback_test.go @@ -0,0 +1,19 @@ +package mtwmapi + +import ( + "net/url" + "testing" + + "git.rosy.net.cn/baseapi/utils" +) + +func TestGetRefundSkuDetailFromMsg(t *testing.T) { + data, _ := url.ParseQuery(` + /mtwm/orderPartialRefund?timestamp=1556595759&reason=%E5%BA%97%E9%93%BA%E5%A4%AA%E5%BF%99%E4%BA%86%21%E5%AE%A2%E5%AE%98%E6%88%91%E6%80%95%E6%82%A8%E7%AD%89%E7%9A%84%E5%A4%AA%E4%B9%85&food=%5B%7B%22app_food_code%22%3A%2231458%22%2C%22box_num%22%3A0%2C%22box_price%22%3A0%2C%22count%22%3A1%2C%22food_name%22%3A%22%E9%B2%9C%E7%AB%B9%E7%AC%8B%EF%BC%88%E9%B8%A1%E5%A9%86%E7%AC%8B%EF%BC%89%5B%E6%9C%AA%E6%B3%A1%E6%B0%B4%5D%E7%BA%A6250g%2F%E4%BB%BD%22%2C%22food_price%22%3A7.97%2C%22origin_food_price%22%3A7.97%2C%22refund_price%22%3A7.97%2C%22sku_id%22%3A%2231458%22%2C%22spec%22%3A%22250g%22%7D%5D&money=7.97&is_appeal=0&pictures=¬ify_type=agree&app_id=589&order_id=67413510345111009&res_type=2&sig=0cef69f37b4a0e924ac4119c3d75117b + `) + msg := &CallbackMsg{ + Data: data, + } + result := api.GetRefundSkuDetailFromMsg(msg) + t.Log(utils.Format4Output(result, false)) +} diff --git a/platformapi/mtwmapi/order.go b/platformapi/mtwmapi/order.go index 093507cd..e8d59dd7 100644 --- a/platformapi/mtwmapi/order.go +++ b/platformapi/mtwmapi/order.go @@ -55,12 +55,45 @@ const ( UserApplyCancelWaitMinute = 30 // 用户申请退款后,商家未在30分钟内(大连锁商家为3小时内)处理退款请求,系统将自动同意退款 ) +const ( + RefundTypeAll = 1 + RefundTypePart = 2 +) + type RefundSku struct { AppFoodCode string `json:"app_food_code"` SkuID string `json:"sku_id,omitempty"` Count int `json:"count"` } +type RefundSkuDetail struct { + AppFoodCode string `json:"app_food_code"` + BoxNum float32 `json:"box_num"` + BoxPrice float32 `json:"box_price"` + Count int `json:"count"` + FoodName string `json:"food_name"` + FoodPrice float32 `json:"food_price"` + OriginFoodPrice float32 `json:"origin_food_price"` + RefundPrice float32 `json:"refund_price"` + SkuID string `json:"sku_id"` + Spec string `json:"spec"` +} + +type RefundOrderDetail struct { + ApplyReason string `json:"apply_reason"` + ApplyType int `json:"apply_type"` + CTime int64 `json:"ctime"` + Money float32 `json:"money"` + OrderID int64 `json:"order_id"` + Pictures []string `json:"pictures"` + RefundType int `json:"refund_type"` + ResReason string `json:"res_reason"` + ResType int `json:"res_type"` + UTime int64 `json:"utime"` + WmAppRetailForOrderPartRefundList []*RefundSkuDetail `json:"wmAppRetailForOrderPartRefundList"` + WmOrderIDView int64 `json:"wm_order_id_view"` +} + func (a *API) OrderReceived(orderID int64) (err error) { _, err = a.AccessAPI("order/poi_received", true, map[string]interface{}{ KeyOrderID: orderID, @@ -195,3 +228,18 @@ func (a *API) OrderLogisticsChange2Self(orderID int64) (err error) { }) return err } + +func (a *API) GetOrderRefundDetail(orderID int64, refundType int) (refundOrderDetail *RefundOrderDetail, err error) { + params := map[string]interface{}{ + "wm_order_id_view": orderID, + } + if refundType > 0 { + params["refund_type"] = refundType + } + result, err := a.AccessAPI("ecommerce/order/getOrderRefundDetail", true, params) + if err == nil { + utils.Map2StructByJson(result.([]interface{})[0], &refundOrderDetail, false) + return refundOrderDetail, nil + } + return nil, err +} diff --git a/platformapi/mtwmapi/order_test.go b/platformapi/mtwmapi/order_test.go index 5ebb06bf..940805b2 100644 --- a/platformapi/mtwmapi/order_test.go +++ b/platformapi/mtwmapi/order_test.go @@ -2,6 +2,8 @@ package mtwmapi import ( "testing" + + "git.rosy.net.cn/baseapi/utils" ) func TestOrderViewStatus(t *testing.T) { @@ -13,14 +15,14 @@ func TestOrderViewStatus(t *testing.T) { } func TestOrderGetOrderDetail(t *testing.T) { - result, err := api.OrderGetOrderDetail(33762863658107006, false) + result, err := api.OrderGetOrderDetail(67413510345111009, false) if err != nil { t.Fatal(err) } if len(result) == 0 { t.Fatal("result should have value") } - // t.Log(utils.Format4Output(result, false)) + t.Log(utils.Format4Output(result, false)) } func TestOrderLogisticsStatus(t *testing.T) { @@ -51,3 +53,11 @@ func TestOrderConfirm(t *testing.T) { t.Fatal(err) } } + +func TestGetOrderRefundDetail(t *testing.T) { + result, err := api.GetOrderRefundDetail(67413510345111009, 0) + if err != nil { + t.Fatal(err) + } + t.Log(utils.Format4Output(result, false)) +}