Files
baseapi/platformapi/sfps2/order.go
richboo111 f9c168a1c4 sfps
2023-05-29 15:01:49 +08:00

148 lines
4.8 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package sfps2
import (
"encoding/json"
"errors"
"fmt"
"git.rosy.net.cn/baseapi/utils"
"git.rosy.net.cn/jx-callback/globals"
"time"
)
// PreCreateOrder 预创建订单(店铺)
func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err error) {
//补全默认参数
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请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
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.ChargePriceList.ShopPayPrice, nil
} else {
return 0, err
}
}
// CreateOrder 创建订单(店铺)
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, 0, errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
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 {
globals.SugarLogger.Debugf("CreateOrder resp=%s", utils.Format4Output(retVal, false))
return retVal.SFOrderID, retVal.SFBillID, retVal.TotalPrice, retVal.RealPayMoney, nil
} else {
return "", "", 0, 0, err
}
}
// PreCancelOrder 预取消订单
func (a *API) PreCancelOrder(sfOrderID string) (deductionFee float64, err error) {
param := PreCancelOrderReq{
DevId: a.devId,
OrderID: sfOrderID,
PushTime: time.Now().Unix(),
}
resp := a.HttpPostJson("precancelorder", param)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return 0, errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
retVal := PreCancelOrderResp{}
s, _ := json.Marshal(resp.BaseRetVal.Result)
if err = json.Unmarshal(s, &retVal); err == nil {
globals.SugarLogger.Debugf("PreCancelOrder resp=%s", utils.Format4Output(retVal, false))
return retVal.DeductionFee, nil
} else {
return 0, err
}
}
// CancelOrder 取消订单
func (a *API) CancelOrder(sfOrderID string) (err error) {
param := &CancelOrderReq{
DevId: a.devId,
OrderID: sfOrderID,
PushTime: time.Now().Unix(),
CancelCode: CancelCodeChangePlan,
}
resp := a.HttpPostJson("cancelorder", param)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
return nil
}
// GetOrderStatus 订单实时信息查询
func (a *API) GetOrderStatus(sfOrderID string) (retVal *GetOrderStatusResp, err error) {
param := &GetOrderStatusReq{
DevId: a.devId,
OrderID: sfOrderID,
PushTime: time.Now().Unix(),
//OrderType: orderType,
}
resp := a.HttpPostJson("getorderstatus", param)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return nil, errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return nil, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
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
}
}
// GetRiderLatestPosition 获取骑手实时坐标
func (a *API) GetRiderLatestPosition(sfOrderID string) (retVal *RiderLatestPositionResp, err error) {
param := &RiderLatestPositionReq{
DevId: a.devId,
OrderID: sfOrderID,
PushTime: time.Now().Unix(),
OrderType: OrderTypeSF, //暂时默认
}
resp := a.HttpPostJson("riderlatestposition", param)
if resp.HttpStatusCode != HttpStatusSuccessCode {
return nil, errors.New("HTTP请求错误请检查重试")
}
if resp.BaseRetVal.ErrorCode != SuccessCode {
return nil, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
}
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
}
}