From 6c52170bb854c0cc903eb1326144ec8e2169c563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=8B=8F=E5=B0=B9=E5=B2=9A?= <770236076@qq.com> Date: Thu, 26 Dec 2019 14:44:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BE=8E=E5=9B=A2=E6=9F=A5=E8=AF=A2=E5=B0=8F?= =?UTF-8?q?=E8=B4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/mtwmapi/order_page.go | 122 +++++++++++++++++++++++++ platformapi/mtwmapi/order_page_test.go | 23 +++++ 2 files changed, 145 insertions(+) create mode 100644 platformapi/mtwmapi/order_page.go create mode 100644 platformapi/mtwmapi/order_page_test.go diff --git a/platformapi/mtwmapi/order_page.go b/platformapi/mtwmapi/order_page.go new file mode 100644 index 00000000..0552fc7a --- /dev/null +++ b/platformapi/mtwmapi/order_page.go @@ -0,0 +1,122 @@ +package mtwmapi + +import ( + "encoding/json" + "fmt" + "net/http" + "strings" + + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/platformapi" + "git.rosy.net.cn/baseapi/utils" +) + +const ( + orderURL = "https://shangoue.meituan.com/v2" +) + +type DistributeOrderDetail struct { + WmOrderID int `json:"wm_order_id"` + WmPoiID int `json:"wm_poi_id"` + LogisticsStatus int `json:"logistics_status"` + LogisticsCode string `json:"logistics_code"` + LogisticsID int `json:"logistics_id"` + LogisticsName string `json:"logistics_name"` + PoiShippingFee float64 `json:"poi_shipping_fee"` + TipAmount float64 `json:"tip_amount"` + SelfDispatch int `json:"self_dispatch"` + DispatchCancelAllow int `json:"dispatch_cancel_allow"` + DispatcherName string `json:"dispatcher_name"` + DispatcherPhone interface{} `json:"dispatcher_phone"` + OrgLeaderPhone interface{} `json:"org_leader_phone"` + OrgEmergencyPhone interface{} `json:"org_emergency_phone"` + LatestDeliveryTime int `json:"latest_delivery_time"` + WaitingTime int `json:"waiting_time"` + IsThirdPartShipping int `json:"is_third_part_shipping"` + ThirdPartShippingName interface{} `json:"third_part_shipping_name"` + ThirdPartShippingPhone interface{} `json:"third_part_shipping_phone"` + IsKS int `json:"isKS"` + DispatchTeam interface{} `json:"dispatchTeam"` + HhKS bool `json:"hhKS"` + PreCheckJuHeMsg interface{} `json:"preCheckJuHeMsg"` + HasJuheAndZB bool `json:"hasJuheAndZB"` + PtGray int `json:"ptGray"` + ShippingFeeDetailVo interface{} `json:"shippingFeeDetailVo"` + AssignTime int `json:"assignTime"` + AssignDegrade bool `json:"assignDegrade"` + CurrentTime int `json:"currentTime"` + SubLogisticsCode int `json:"subLogisticsCode"` + DelayPushSecond int `json:"delay_push_second"` +} + +func (a *API) AccessOrderPage(subURL string, params map[string]interface{}, isPost bool) (retVal map[string]interface{}, err error) { + if a.GetCookieCount() == 0 { + return nil, fmt.Errorf("需要设置User Cookie才能使用此方法") + } + err = platformapi.AccessPlatformAPIWithRetry(a.client, + func() *http.Request { + var request *http.Request + if !isPost { + request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(orderURL, subURL, params), nil) + } else { + fullURL := utils.GenerateGetURL(orderURL, subURL, nil) + request, _ = http.NewRequest(http.MethodPost, fullURL, strings.NewReader(utils.Map2URLValues(params).Encode())) + } + request.Header.Set("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8") + request.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36") + request.Header.Set("Pragma", "no-cache") + + a.FillRequestCookies(request) + return request + }, + a.config, + func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) { + if jsonResult1 == nil { + return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil") + } + retVal = jsonResult1 + code := int(utils.MustInterface2Int64(jsonResult1["code"])) + if code == ResponseCodeSuccess { + retVal, _ = jsonResult1["data"].(map[string]interface{}) + return platformapi.ErrLevelSuccess, nil + } + newErr := utils.NewErrorIntCode(jsonResult1["msg"].(string), code) + baseapi.SugarLogger.Debugf("mt AccessStorePage failed, jsonResult1:%s", utils.Format4Output(jsonResult1, true)) + return platformapi.ErrLevelCodeIsNotOK, newErr + }) + return retVal, err +} + +//美团骑手修改小费,单位为元,最多小数点后一位 +//order/receive/processed/w/distribute/tipAmount/v2?ignoreSetRouterProxy=true +func (a *API) OrderModityTips(orderID, poiID string, tipAmount float64) (err error) { + params := map[string]interface{}{ + "wmOrderViewId": orderID, + "wmPoiId": poiID, + "tipAmount": tipAmount, + } + _, err = a.AccessOrderPage("order/receive/processed/w/distribute/tipAmount/v2", params, true) + return err +} + +//获取美团订单小费 +//https://shangoue.meituan.com/v2/order/receive/processed/r/distribute/list/v2 +func (a *API) GetDistributeOrderDetail(orderID, poiID string) (distributeOrderDetail *DistributeOrderDetail, err error) { + params1 := map[string]interface{}{ + "wmOrderViewId": orderID, + "wmPoiId": poiID, + } + result1, err := json.MarshalIndent(params1, "", "") + if err != nil { + return distributeOrderDetail, err + } + params := map[string]interface{}{ + "orderInfos": []string{string(result1)}, + } + result, err2 := a.AccessOrderPage("order/receive/processed/r/distribute/list/v2", params, false) + if err2 != nil { + return distributeOrderDetail, err + } + utils.Map2StructByJson(result[orderID], &distributeOrderDetail, true) + return distributeOrderDetail, err +} diff --git a/platformapi/mtwmapi/order_page_test.go b/platformapi/mtwmapi/order_page_test.go new file mode 100644 index 00000000..9efca940 --- /dev/null +++ b/platformapi/mtwmapi/order_page_test.go @@ -0,0 +1,23 @@ +package mtwmapi + +import ( + "testing" + + "git.rosy.net.cn/baseapi" + "git.rosy.net.cn/baseapi/utils" +) + +func TestOrderAddTips(t *testing.T) { + err := api.OrderModityTips("69761763472881638", "6976176", 0.2) + if err != nil { + t.Fatal(err) + } +} + +func TestGetDistributeOrderDetail(t *testing.T) { + result, err := api.GetDistributeOrderDetail("69761763472881638", "6976176") + if err != nil { + t.Fatal(err) + } + baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) +}