Merge branch 'master' of e.coding.net:rosydev/baseapi
This commit is contained in:
@@ -3,6 +3,8 @@ package sfps2
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
@@ -40,6 +42,10 @@ type RiderRecall struct {
|
|||||||
OrderStatus int `json:"order_status"` //22-配送员撤单
|
OrderStatus int `json:"order_status"` //22-配送员撤单
|
||||||
StatusDesc string `json:"status_desc"` //状态描述
|
StatusDesc string `json:"status_desc"` //状态描述
|
||||||
PushTime int `json:"push_time"` //状态变更时间
|
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 订单完成回调
|
// OrderComplete 订单完成回调
|
||||||
@@ -110,19 +116,55 @@ func Err2CallbackResponse(err error) *CallbackResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRiderStatusCallback 配送状态更改回调
|
// GetCallbackUrlIndex 配送状态更改回调
|
||||||
func (a *API) GetRiderStatusCallback(request *http.Request) (riderStatus *RiderStatus, response *CallbackResponse) {
|
func (a *API) GetCallbackUrlIndex(request *http.Request) (map[string]interface{}, *CallbackResponse) {
|
||||||
data, err := ioutil.ReadAll(request.Body)
|
data, err := ioutil.ReadAll(request.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response = &CallbackResponse{ErrorCode: -1}
|
return nil, CallbackResponseErr(false)
|
||||||
return nil, response
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = json.Unmarshal(data, &riderStatus); err != nil {
|
var (
|
||||||
response = &CallbackResponse{ErrorCode: -1}
|
urlIndex = ""
|
||||||
return nil, response
|
temp = map[string]interface{}{}
|
||||||
|
)
|
||||||
|
if err = json.Unmarshal(data, &temp); err == nil {
|
||||||
|
globals.SugarLogger.Debugf("GetCallbackUrlIndex temp=%s", utils.Format4Output(temp, false))
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
globals.SugarLogger.Debugf("GetCallbackUrlIndex result=%s", utils.Format4Output(result, false))
|
||||||
|
return result, SuccessResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetRiderExceptionCallback 订单异常回调
|
// GetRiderExceptionCallback 订单异常回调
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
|||||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||||
globals.SugarLogger.Debugf("PreCreateOrder resp=%s", utils.Format4Output(retVal, false))
|
globals.SugarLogger.Debugf("PreCreateOrder resp=%s", utils.Format4Output(retVal, false))
|
||||||
return retVal.EstimatePayMoney, nil
|
return retVal.ChargePriceList.ShopPayPrice, nil
|
||||||
} else {
|
} else {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,8 +15,9 @@ const (
|
|||||||
SuccessMsg = "success" //成功 msg
|
SuccessMsg = "success" //成功 msg
|
||||||
FailCode = -1
|
FailCode = -1
|
||||||
FailMsg = "fail"
|
FailMsg = "fail"
|
||||||
SFShopStoreID = "3243279847393" //默认以一个店铺发单
|
//SFShopStoreID = "3243279847393" //默认以一个店铺发单
|
||||||
DefaultVersion = 19 //参照文档主版本号填写 如:文档版本号1.9,version=19,推荐使用版本19
|
SFShopStoreID = "3263670062849" //默认以一个店铺发单
|
||||||
|
DefaultVersion = 19 //参照文档主版本号填写 如:文档版本号1.9,version=19,推荐使用版本19
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -269,8 +270,8 @@ type CreateOrderReq struct {
|
|||||||
OrderDetail *OrderDetail `json:"order_detail"` // 订单详情
|
OrderDetail *OrderDetail `json:"order_detail"` // 订单详情
|
||||||
MultiPickupInfo []*MultiPickupDetails `json:"multi_pickup_info"` // 多点取货信息
|
MultiPickupInfo []*MultiPickupDetails `json:"multi_pickup_info"` // 多点取货信息
|
||||||
// 非必填
|
// 非必填
|
||||||
//LbsType int `json:"lbs_type"` // 坐标类型 1:百度坐标,2:高德坐标
|
LbsType int `json:"lbs_type"` // 坐标类型 1:百度坐标,2:高德坐标
|
||||||
//ShopType int64 `json:"shop_type"` // 店铺ID类型 1:顺丰店铺ID ;2:接入方店铺ID
|
ShopType int64 `json:"shop_type"` // 店铺ID类型 1:顺丰店铺ID ;2:接入方店铺ID
|
||||||
ShopPreparationTime int64 `json:"shop_preparation_time"` // 商家预计备餐时长(分10)
|
ShopPreparationTime int64 `json:"shop_preparation_time"` // 商家预计备餐时长(分10)
|
||||||
OrderSequence string `json:"order_sequence"` // 取货序号 与order_source配合使用 如:饿了么10号单,表示如下:order_source=2;order_sequence=10。用于骑士快速寻找配送物
|
OrderSequence string `json:"order_sequence"` // 取货序号 与order_source配合使用 如:饿了么10号单,表示如下:order_source=2;order_sequence=10。用于骑士快速寻找配送物
|
||||||
AppointType int `json:"appoint_type"` // 预约单类型 预约单的时候传入,1:预约单送达单;2:预约单上门单
|
AppointType int `json:"appoint_type"` // 预约单类型 预约单的时候传入,1:预约单送达单;2:预约单上门单
|
||||||
@@ -329,7 +330,7 @@ type PreCancelOrderResp struct {
|
|||||||
DeliveryType float64 `json:"delivery_type"` //订单类型 0:预约送达单,1:立即单,2:预约上门单
|
DeliveryType float64 `json:"delivery_type"` //订单类型 0:预约送达单,1:立即单,2:预约上门单
|
||||||
ExpectPickUpTime float64 `json:"expect_pickup_time"` //原始期望上门时间
|
ExpectPickUpTime float64 `json:"expect_pickup_time"` //原始期望上门时间
|
||||||
ExpectTime float64 `json:"expect_time"` //预约时间
|
ExpectTime float64 `json:"expect_time"` //预约时间
|
||||||
ShopCancelTimes string `json:"shop_cancel_times"` //店铺每日取消次数
|
ShopCancelTimes float64 `json:"shop_cancel_times"` //店铺每日取消次数
|
||||||
FreeCancelTimes float64 `json:"free_cancel_times"` //每日免费取消次数
|
FreeCancelTimes float64 `json:"free_cancel_times"` //每日免费取消次数
|
||||||
IsCancelChargePriceRule float64 `json:"is_cancel_charge_price_rule"` //取消收费规则
|
IsCancelChargePriceRule float64 `json:"is_cancel_charge_price_rule"` //取消收费规则
|
||||||
IsOverFreeCancelTimes float64 `json:"is_over_free_cancel_times"` //是否超出免费取消次数
|
IsOverFreeCancelTimes float64 `json:"is_over_free_cancel_times"` //是否超出免费取消次数
|
||||||
@@ -383,7 +384,7 @@ type GetOrderStatusReq struct {
|
|||||||
// GetOrderStatusResp 订单实时信息查询
|
// GetOrderStatusResp 订单实时信息查询
|
||||||
type GetOrderStatusResp struct {
|
type GetOrderStatusResp struct {
|
||||||
OrderID string `json:"order_id"` //新版本V1.9+升级为JS开头的15位字符串类型:“JS1234567890123”, 老版本int类型订单号会长期兼容
|
OrderID string `json:"order_id"` //新版本V1.9+升级为JS开头的15位字符串类型:“JS1234567890123”, 老版本int类型订单号会长期兼容
|
||||||
ShopId int64 `json:"shop_id"` // 店铺ID
|
ShopId float64 `json:"shop_id"` // 店铺ID
|
||||||
OutOrderID string `json:"out_order_id"` //商家订单ID
|
OutOrderID string `json:"out_order_id"` //商家订单ID
|
||||||
OrderStatus float64 `json:"order_status"` //当前状态
|
OrderStatus float64 `json:"order_status"` //当前状态
|
||||||
StatusDesc string `json:"status_desc"` //当前状态描述
|
StatusDesc string `json:"status_desc"` //当前状态描述
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ func TestCreateOrder(t *testing.T) {
|
|||||||
},
|
},
|
||||||
RiderPickMethod: 1,
|
RiderPickMethod: 1,
|
||||||
}
|
}
|
||||||
sfOrderID, sfBillID, totalPrice, err := api.CreateOrder(param)
|
sfOrderID, sfBillID, totalPrice, err, _ := api.CreateOrder(param)
|
||||||
fmt.Println(sfOrderID, sfBillID)
|
fmt.Println(sfOrderID, sfBillID)
|
||||||
fmt.Println(totalPrice)
|
fmt.Println(totalPrice)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
@@ -88,7 +88,7 @@ func TestCreateOrder(t *testing.T) {
|
|||||||
|
|
||||||
//预取消订单
|
//预取消订单
|
||||||
func TestPreCancelOrder(t *testing.T) {
|
func TestPreCancelOrder(t *testing.T) {
|
||||||
resp, err := api.PreCancelOrder("JS4157196256886")
|
resp, err := api.PreCancelOrder("JS4157236257228")
|
||||||
fmt.Println(resp)
|
fmt.Println(resp)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,3 +96,10 @@ func (a *API) HttpPostJson(url string, data interface{}) *Response {
|
|||||||
|
|
||||||
return &result
|
return &result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CallbackResponseErr(param bool) (callbackResponse *CallbackResponse) {
|
||||||
|
if param {
|
||||||
|
return &CallbackResponse{ErrorCode: FailCode, ErrorMsg: FailMsg}
|
||||||
|
}
|
||||||
|
return &CallbackResponse{ErrorCode: SuccessCode, ErrorMsg: SuccessMsg}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user