sfps
This commit is contained in:
141
platformapi/sfps2/callback.go
Normal file
141
platformapi/sfps2/callback.go
Normal file
@@ -0,0 +1,141 @@
|
||||
package sfps2
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const (
|
||||
// 回调url前缀
|
||||
UrlIndexRiderStatus = "rider_status" //配送状态更改回调
|
||||
UrlIndexRiderRecall = "rider_recall" //骑士撤单状态回调
|
||||
UrlIndexOrderComplete = "order_complete" //订单完成回调
|
||||
UrlIndexSFCancel = "sf_cancel" //顺丰原因订单取消回调
|
||||
UrlIndexRiderException = "rider_exception" //订单异常回调
|
||||
)
|
||||
|
||||
// RiderStatus 配送状态更改回调
|
||||
type RiderStatus struct {
|
||||
ShopId string `json:"shop_id"` // 店铺ID
|
||||
SFOrderID string `json:"sf_order_id"` //顺丰订单ID
|
||||
ShopOrderID string `json:"shop_order_id"` //商家订单ID
|
||||
UrlIndex string `json:"url_index"` //回调url前缀
|
||||
OperatorName string `json:"operator_name"` //配送员姓名
|
||||
OperatorPhone string `json:"operator_phone"` //配送员电话
|
||||
RiderLng string `json:"rider_lng"` //配送员位置经度
|
||||
RiderLat string `json:"rider_lat"` //配送员位置纬度
|
||||
OrderStatus int `json:"order_status"` //10-配送员接单/改派;12:配送员到店;15:配送员配送中
|
||||
StatusDesc string `json:"status_desc"` //状态描述
|
||||
PushTime int `json:"push_time"` //状态变更时间
|
||||
}
|
||||
|
||||
// RiderRecall 骑士撤单状态回调
|
||||
type RiderRecall struct {
|
||||
ShopId string `json:"shop_id"` // 店铺ID
|
||||
SFOrderID string `json:"sf_order_id"` //顺丰订单ID
|
||||
ShopOrderID string `json:"shop_order_id"` //商家订单ID
|
||||
UrlIndex string `json:"url_index"` //回调url前缀
|
||||
OrderStatus int `json:"order_status"` //22-配送员撤单
|
||||
StatusDesc string `json:"status_desc"` //状态描述
|
||||
PushTime int `json:"push_time"` //状态变更时间
|
||||
}
|
||||
|
||||
// OrderComplete 订单完成回调
|
||||
type OrderComplete struct {
|
||||
ShopId string `json:"shop_id"` // 店铺ID
|
||||
SFOrderID string `json:"sf_order_id"` //顺丰订单ID
|
||||
ShopOrderID string `json:"shop_order_id"` //商家订单ID
|
||||
UrlIndex string `json:"url_index"` //回调url前缀
|
||||
OperatorName string `json:"operator_name"` //配送员姓名
|
||||
RiderLng string `json:"rider_lng"` //配送员位置经度
|
||||
RiderLat string `json:"rider_lat"` //配送员位置纬度
|
||||
OrderStatus int `json:"order_status"` //17配送员点击完成
|
||||
StatusDesc string `json:"status_desc"` //状态描述
|
||||
PickUpPic string `json:"pickup_pic"` //只有在店铺打开妥投照片回调开关且有妥投照片时才有此字段
|
||||
PushTime int `json:"push_time"` //完成时间
|
||||
ReceiptType int `json:"receipt_type"` //1:正常签收, 2:商家退回签收
|
||||
}
|
||||
|
||||
// SFCancel 顺丰原因订单取消回调
|
||||
type SFCancel struct {
|
||||
ShopId string `json:"shop_id"` // 店铺ID
|
||||
SFOrderID string `json:"sf_order_id"` //顺丰订单ID
|
||||
ShopOrderID string `json:"shop_order_id"` //商家订单ID
|
||||
UrlIndex string `json:"url_index"` //回调url前缀
|
||||
OperatorName string `json:"operator_name"` //配送员姓名
|
||||
OperatorPhone string `json:"operator_phone"` //配送员电话
|
||||
OrderStatus int `json:"order_status"` //2:订单取消
|
||||
StatusDesc string `json:"status_desc"` //状态描述
|
||||
CancelReason string `json:"cancel_reason"` //取消原因
|
||||
CancelCode string `json:"cancel_code"` //取消码
|
||||
RiderLng string `json:"rider_lng"` //配送员位置经度
|
||||
RiderLat string `json:"rider_lat"` //配送员位置纬度
|
||||
PushTime int `json:"push_time"` //状态变更时间
|
||||
}
|
||||
|
||||
// RiderException 配送状态更改回调
|
||||
type RiderException struct {
|
||||
ShopId string `json:"shop_id"` // 店铺ID
|
||||
SFOrderID string `json:"sf_order_id"` //顺丰订单ID
|
||||
ShopOrderID string `json:"shop_order_id"` //商家订单ID
|
||||
UrlIndex string `json:"url_index"` //回调url前缀
|
||||
OperatorName string `json:"operator_name"` //配送员姓名
|
||||
OperatorPhone string `json:"operator_phone"` //配送员电话
|
||||
OrderStatus int `json:"order_status"` //固定为91
|
||||
StatusDesc string `json:"status_desc"` //状态描述
|
||||
ExID int `json:"ex_id"` //异常ID
|
||||
ExContent string `json:"ex_content"` //异常详情
|
||||
ExpectTime string `json:"expect_time"` //新的预计送达时间
|
||||
PushTime int `json:"push_time"` //顺丰推送时间
|
||||
}
|
||||
|
||||
type CallbackResponse struct {
|
||||
ErrorCode int `json:"error_code"`
|
||||
ErrorMsg string `json:"error_msg"`
|
||||
}
|
||||
|
||||
var (
|
||||
SuccessResponse = &CallbackResponse{ErrorCode: SuccessCode, ErrorMsg: SuccessMsg}
|
||||
)
|
||||
|
||||
func Err2CallbackResponse(err error) *CallbackResponse {
|
||||
if err == nil {
|
||||
return SuccessResponse
|
||||
}
|
||||
return &CallbackResponse{
|
||||
ErrorCode: -1,
|
||||
ErrorMsg: fmt.Sprint(err),
|
||||
}
|
||||
}
|
||||
|
||||
// GetRiderStatusCallback 配送状态更改回调
|
||||
func (a *API) GetRiderStatusCallback(request *http.Request) (riderStatus *RiderStatus, response *CallbackResponse) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
response = &CallbackResponse{ErrorCode: -1}
|
||||
return nil, response
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &riderStatus); err != nil {
|
||||
response = &CallbackResponse{ErrorCode: -1}
|
||||
return nil, response
|
||||
}
|
||||
return riderStatus, SuccessResponse
|
||||
}
|
||||
|
||||
// GetRiderExceptionCallback 订单异常回调
|
||||
func (a *API) GetRiderExceptionCallback(request *http.Request) (riderException *RiderException, response *CallbackResponse) {
|
||||
data, err := ioutil.ReadAll(request.Body)
|
||||
if err != nil {
|
||||
response = &CallbackResponse{ErrorCode: -1}
|
||||
return nil, response
|
||||
}
|
||||
|
||||
if err = json.Unmarshal(data, &riderException); err != nil {
|
||||
response = &CallbackResponse{ErrorCode: -1}
|
||||
return nil, response
|
||||
}
|
||||
return riderException, SuccessResponse
|
||||
}
|
||||
Reference in New Issue
Block a user