123 lines
5.0 KiB
Go
123 lines
5.0 KiB
Go
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
|
|
}
|