sfps
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -12,7 +14,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
||||
//补全默认参数
|
||||
preOrder.PushTime = time.Now().Unix()
|
||||
preOrder.DevId = a.devId
|
||||
|
||||
globals.SugarLogger.Debugf("PreCreateOrder req=%s", utils.Format4Output(preOrder, false))
|
||||
resp := a.HttpPostJson("precreateorder", preOrder)
|
||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||
return 0, errors.New("HTTP请求错误,请检查重试")
|
||||
@@ -23,6 +25,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
||||
retVal := PreCreateOrderResp{}
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||
globals.SugarLogger.Debugf("PreCreateOrder resp=%s", utils.Format4Output(retVal, false))
|
||||
return retVal.EstimatePayMoney, nil
|
||||
} else {
|
||||
return 0, err
|
||||
@@ -30,30 +33,31 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
||||
}
|
||||
|
||||
// CreateOrder 创建订单(店铺)
|
||||
func (a *API) CreateOrder(order *CreateOrderReq) (sfOrderID, sfBillID string, totalPrice int, err error) {
|
||||
func (a *API) CreateOrder(order *CreateOrderReq) (sfOrderID, sfBillID string, totalPrice, reallyPayPrice float64, err error) {
|
||||
//补全默认参数
|
||||
order.PushTime = time.Now().Unix()
|
||||
order.Version = DefaultVersion
|
||||
order.DevId = a.devId
|
||||
|
||||
globals.SugarLogger.Debugf("CreateOrder req=%s", utils.Format4Output(order, false))
|
||||
resp := a.HttpPostJson("createorder", order)
|
||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||
return "", "", 0, errors.New("HTTP请求错误,请检查重试")
|
||||
return "", "", 0, 0, errors.New("HTTP请求错误,请检查重试")
|
||||
}
|
||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||
return "", "", 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
return "", "", 0, 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
}
|
||||
retVal := CreateOrderResp{}
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||
return retVal.SFOrderID, retVal.SFBillID, retVal.TotalPrice, nil
|
||||
globals.SugarLogger.Debugf("CreateOrder resp=%s", utils.Format4Output(retVal, false))
|
||||
return retVal.SFOrderID, retVal.SFBillID, retVal.TotalPrice, retVal.RealPayMoney, nil
|
||||
} else {
|
||||
return "", "", 0, err
|
||||
return "", "", 0, 0, err
|
||||
}
|
||||
}
|
||||
|
||||
// PreCancelOrder 预取消订单
|
||||
func (a *API) PreCancelOrder(sfOrderID string) (isCancel bool, err error) {
|
||||
func (a *API) PreCancelOrder(sfOrderID string) (deductionFee float64, err error) {
|
||||
param := PreCancelOrderReq{
|
||||
DevId: a.devId,
|
||||
OrderID: sfOrderID,
|
||||
@@ -61,17 +65,18 @@ func (a *API) PreCancelOrder(sfOrderID string) (isCancel bool, err error) {
|
||||
}
|
||||
resp := a.HttpPostJson("precancelorder", param)
|
||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||
return false, errors.New("HTTP请求错误,请检查重试")
|
||||
return 0, errors.New("HTTP请求错误,请检查重试")
|
||||
}
|
||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||
return false, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
}
|
||||
retVal := PreCancelOrderResp{}
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||
return retVal.CouldCancel, nil
|
||||
globals.SugarLogger.Debugf("PreCancelOrder resp=%s", utils.Format4Output(retVal, false))
|
||||
return retVal.DeductionFee, nil
|
||||
} else {
|
||||
return false, err
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
@@ -110,6 +115,7 @@ func (a *API) GetOrderStatus(sfOrderID string) (retVal *GetOrderStatusResp, err
|
||||
}
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||
globals.SugarLogger.Debugf("GetOrderStatus resp=%s", utils.Format4Output(retVal, false))
|
||||
return retVal, nil
|
||||
} else {
|
||||
return nil, err
|
||||
@@ -133,6 +139,7 @@ func (a *API) GetRiderLatestPosition(sfOrderID string) (retVal *RiderLatestPosit
|
||||
}
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err = json.Unmarshal(s, &retVal); err == nil {
|
||||
globals.SugarLogger.Debugf("GetRiderLatestPosition resp=%s", utils.Format4Output(retVal, false))
|
||||
return retVal, nil
|
||||
} else {
|
||||
return nil, err
|
||||
|
||||
Reference in New Issue
Block a user