diff --git a/platformapi/sfps2/callback.go b/platformapi/sfps2/callback.go index dd83ac6b..a4e5ae99 100644 --- a/platformapi/sfps2/callback.go +++ b/platformapi/sfps2/callback.go @@ -40,6 +40,10 @@ type RiderRecall struct { OrderStatus int `json:"order_status"` //22-配送员撤单 StatusDesc string `json:"status_desc"` //状态描述 PushTime int `json:"push_time"` //状态变更时间 + //OperatorName string `json:"operator_name"` //配送员姓名 + //OperatorPhone string `json:"operator_phone"` //配送员电话 + //RiderLng string `json:"rider_lng"` //配送员位置经度 + //RiderLat string `json:"rider_lat"` //配送员位置纬度 } // OrderComplete 订单完成回调 @@ -110,19 +114,53 @@ func Err2CallbackResponse(err error) *CallbackResponse { } } -// GetRiderStatusCallback 配送状态更改回调 -func (a *API) GetRiderStatusCallback(request *http.Request) (riderStatus *RiderStatus, response *CallbackResponse) { +// GetCallbackUrlIndex 配送状态更改回调 +func (a *API) GetCallbackUrlIndex(request *http.Request) (map[string]interface{}, *CallbackResponse) { data, err := ioutil.ReadAll(request.Body) if err != nil { - response = &CallbackResponse{ErrorCode: -1} - return nil, response + return nil, CallbackResponseErr(false) } - if err = json.Unmarshal(data, &riderStatus); err != nil { - response = &CallbackResponse{ErrorCode: -1} - return nil, response + var ( + urlIndex = "" + temp = map[string]interface{}{} + ) + if err = json.Unmarshal(data, &temp); err == nil { + urlIndex = temp["url_index"].(string) + fmt.Println(urlIndex) } - return riderStatus, SuccessResponse + + result := make(map[string]interface{}, 0) + + switch urlIndex { + case UrlIndexRiderStatus: + retVal := RiderStatus{} + if err = json.Unmarshal(data, &retVal); err != nil { + return nil, CallbackResponseErr(false) + } + result[UrlIndexRiderStatus] = retVal + case UrlIndexRiderRecall: + retVal := RiderRecall{} + if err := json.Unmarshal(data, &retVal); err != nil { + return nil, CallbackResponseErr(false) + } + result[UrlIndexRiderRecall] = retVal + case UrlIndexOrderComplete: + retVal := OrderComplete{} + if err = json.Unmarshal(data, &retVal); err != nil { + return nil, CallbackResponseErr(false) + } + result[UrlIndexOrderComplete] = retVal + case UrlIndexSFCancel: + retVal := SFCancel{} + if err = json.Unmarshal(data, &retVal); err != nil { + return nil, CallbackResponseErr(false) + } + result[UrlIndexSFCancel] = retVal + default: + return nil, CallbackResponseErr(false) + } + return result, SuccessResponse } // GetRiderExceptionCallback 订单异常回调 diff --git a/platformapi/sfps2/sfpsapi.go b/platformapi/sfps2/sfpsapi.go index 54005307..f82e1b0c 100644 --- a/platformapi/sfps2/sfpsapi.go +++ b/platformapi/sfps2/sfpsapi.go @@ -96,3 +96,10 @@ func (a *API) HttpPostJson(url string, data interface{}) *Response { return &result } + +func CallbackResponseErr(param bool) (callbackResponse *CallbackResponse) { + if param { + return &CallbackResponse{ErrorCode: FailCode, ErrorMsg: FailMsg} + } + return &CallbackResponse{ErrorCode: SuccessCode, ErrorMsg: SuccessMsg} +}