sfps
This commit is contained in:
@@ -4,6 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"git.rosy.net.cn/jx-callback/globals"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
|||||||
//补全默认参数
|
//补全默认参数
|
||||||
preOrder.PushTime = time.Now().Unix()
|
preOrder.PushTime = time.Now().Unix()
|
||||||
preOrder.DevId = a.devId
|
preOrder.DevId = a.devId
|
||||||
|
globals.SugarLogger.Debugf("PreCreateOrder req=%s", utils.Format4Output(preOrder, false))
|
||||||
resp := a.HttpPostJson("precreateorder", preOrder)
|
resp := a.HttpPostJson("precreateorder", preOrder)
|
||||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||||
return 0, errors.New("HTTP请求错误,请检查重试")
|
return 0, errors.New("HTTP请求错误,请检查重试")
|
||||||
@@ -23,6 +25,7 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
|||||||
retVal := PreCreateOrderResp{}
|
retVal := PreCreateOrderResp{}
|
||||||
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))
|
||||||
return retVal.EstimatePayMoney, nil
|
return retVal.EstimatePayMoney, nil
|
||||||
} else {
|
} else {
|
||||||
return 0, err
|
return 0, err
|
||||||
@@ -30,30 +33,31 @@ func (a *API) PreCreateOrder(preOrder *PreCreateOrderReq) (price float64, err er
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateOrder 创建订单(店铺)
|
// 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.PushTime = time.Now().Unix()
|
||||||
order.Version = DefaultVersion
|
order.Version = DefaultVersion
|
||||||
order.DevId = a.devId
|
order.DevId = a.devId
|
||||||
|
globals.SugarLogger.Debugf("CreateOrder req=%s", utils.Format4Output(order, false))
|
||||||
resp := a.HttpPostJson("createorder", order)
|
resp := a.HttpPostJson("createorder", order)
|
||||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||||
return "", "", 0, errors.New("HTTP请求错误,请检查重试")
|
return "", "", 0, 0, errors.New("HTTP请求错误,请检查重试")
|
||||||
}
|
}
|
||||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||||
return "", "", 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
return "", "", 0, 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||||
}
|
}
|
||||||
retVal := CreateOrderResp{}
|
retVal := CreateOrderResp{}
|
||||||
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 {
|
||||||
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 {
|
} else {
|
||||||
return "", "", 0, err
|
return "", "", 0, 0, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreCancelOrder 预取消订单
|
// PreCancelOrder 预取消订单
|
||||||
func (a *API) PreCancelOrder(sfOrderID string) (isCancel bool, err error) {
|
func (a *API) PreCancelOrder(sfOrderID string) (deductionFee float64, err error) {
|
||||||
param := PreCancelOrderReq{
|
param := PreCancelOrderReq{
|
||||||
DevId: a.devId,
|
DevId: a.devId,
|
||||||
OrderID: sfOrderID,
|
OrderID: sfOrderID,
|
||||||
@@ -61,17 +65,18 @@ func (a *API) PreCancelOrder(sfOrderID string) (isCancel bool, err error) {
|
|||||||
}
|
}
|
||||||
resp := a.HttpPostJson("precancelorder", param)
|
resp := a.HttpPostJson("precancelorder", param)
|
||||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||||
return false, errors.New("HTTP请求错误,请检查重试")
|
return 0, errors.New("HTTP请求错误,请检查重试")
|
||||||
}
|
}
|
||||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||||
return false, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||||
}
|
}
|
||||||
retVal := PreCancelOrderResp{}
|
retVal := PreCancelOrderResp{}
|
||||||
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 {
|
||||||
return retVal.CouldCancel, nil
|
globals.SugarLogger.Debugf("PreCancelOrder resp=%s", utils.Format4Output(retVal, false))
|
||||||
|
return retVal.DeductionFee, nil
|
||||||
} else {
|
} 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)
|
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("GetOrderStatus resp=%s", utils.Format4Output(retVal, false))
|
||||||
return retVal, nil
|
return retVal, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -133,6 +139,7 @@ func (a *API) GetRiderLatestPosition(sfOrderID string) (retVal *RiderLatestPosit
|
|||||||
}
|
}
|
||||||
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("GetRiderLatestPosition resp=%s", utils.Format4Output(retVal, false))
|
||||||
return retVal, nil
|
return retVal, nil
|
||||||
} else {
|
} else {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -293,20 +293,21 @@ type CreateOrderResp struct {
|
|||||||
ShopOrderID string `json:"shop_order_id"` //商家订单号
|
ShopOrderID string `json:"shop_order_id"` //商家订单号
|
||||||
PushTime int `json:"push_time"` //推送时间
|
PushTime int `json:"push_time"` //推送时间
|
||||||
//以下字段受请求参数中 return_flag 控制:return_flag中未包含的,此字段将不存在,请注意!
|
//以下字段受请求参数中 return_flag 控制:return_flag中未包含的,此字段将不存在,请注意!
|
||||||
TotalPrice int `json:"total_price"` //配送费总额,当return_flag中包含1时返回,单位分(值为计算出来此单总价)
|
TotalPrice float64 `json:"total_price"` //配送费总额,当return_flag中包含1时返回,单位分(值为计算出来此单总价)
|
||||||
DeliveryDistanceMeter int `json:"delivery_distance_meter"` //配送距离,当return_flag中包含2时返回,单位米(值为计算出来实际配送距离)
|
DeliveryDistanceMeter float64 `json:"delivery_distance_meter"` //配送距离,当return_flag中包含2时返回,单位米(值为计算出来实际配送距离)
|
||||||
WeightGram int `json:"weight_gram"` //商品重量,当return_flag中包含4时返回,单位克(值为下单传入参数回传)
|
WeightGram float64 `json:"weight_gram"` //商品重量,当return_flag中包含4时返回,单位克(值为下单传入参数回传)
|
||||||
StartTime int `json:"start_time"` //起送时间,当return_flag中包含8时返回,时间格式为Unix时间戳,注意转换
|
StartTime float64 `json:"start_time"` //起送时间,当return_flag中包含8时返回,时间格式为Unix时间戳,注意转换
|
||||||
ExpectTime int `json:"expect_time"` //预计送达时间,当return_flag中包含16时返回,时间格式为Unix时间戳,注意转换
|
ExpectTime float64 `json:"expect_time"` //预计送达时间,当return_flag中包含16时返回,时间格式为Unix时间戳,注意转换
|
||||||
TotalPayMoney int `json:"total_pay_money"` //支付费用,当return_flag中包含32时返回,单位分
|
TotalPayMoney float64 `json:"total_pay_money"` //支付费用,当return_flag中包含32时返回,单位分
|
||||||
RealPayMoney int `json:"real_pay_money"` //实际支付金额,当return_flag中包含64时返回,单位分(实际支付金额=总金额-优惠券总金额)
|
RealPayMoney float64 `json:"real_pay_money"` //实际支付金额,当return_flag中包含64时返回,单位分(实际支付金额=总金额-优惠券总金额)
|
||||||
CouponsTotalFee int `json:"coupons_total_fee"` //优惠券总金额,当return_flag中包含128时返回,单位分
|
CouponsTotalFee float64 `json:"coupons_total_fee"` //优惠券总金额,当return_flag中包含128时返回,单位分
|
||||||
SettlementType int `json:"settlement_type"` //结算方式,当return_flag中包含256时返回
|
SettlementType float64 `json:"settlement_type"` //结算方式,当return_flag中包含256时返回
|
||||||
|
|
||||||
PickUPCode int `json:"pick_up_code"` //取件码。在顺丰同城商户侧配置,配置后有此字段
|
PickUPCode float64 `json:"pick_up_code"` //取件码。在顺丰同城商户侧配置,配置后有此字段
|
||||||
CompleteCode int `json:"complete_code"` //签收码。在顺丰同城商户侧配置,配置后有此字段
|
CompleteCode float64 `json:"complete_code"` //签收码。在顺丰同城商户侧配置,配置后有此字段
|
||||||
OverflowFee int `json:"overflow_fee"` //爆单费,单位分
|
OverflowFee float64 `json:"overflow_fee"` //爆单费,单位分
|
||||||
InsureFee int `json:"insure_fee"` //保价费,单位分
|
InsureFee float64 `json:"insure_fee"` //保价费,单位分
|
||||||
|
SubsidyFee float64 `json:"subsidy_fee"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreCancelOrderReq 预取消订单
|
// PreCancelOrderReq 预取消订单
|
||||||
|
|||||||
@@ -9,8 +9,12 @@ import (
|
|||||||
var api = New(AppID, AppKey)
|
var api = New(AppID, AppKey)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
AppID = 1663705378 //开发者ID
|
//正式环境
|
||||||
AppKey = "0838426b310fd2530c57dd6e770ddff1" //开发者密钥
|
AppID2 = 1663705444
|
||||||
|
AppKey2 = "600e22db5deb6402e527e58f0d6636a0"
|
||||||
|
|
||||||
|
AppID = 1663705378 //测试开发者ID
|
||||||
|
AppKey = "0838426b310fd2530c57dd6e770ddff1" //测试开发者密钥
|
||||||
TestSFStoreID = "3243279847393" //open测试平台型店铺
|
TestSFStoreID = "3243279847393" //open测试平台型店铺
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,7 +28,7 @@ func TestPreCreateOrder(t *testing.T) {
|
|||||||
UserAddress: "北京市海淀区学清嘉创大厦A座15层",
|
UserAddress: "北京市海淀区学清嘉创大厦A座15层",
|
||||||
Weight: 1000,
|
Weight: 1000,
|
||||||
ProductType: 4,
|
ProductType: 4,
|
||||||
PushTime: 1684379930,
|
PushTime: 1684996039,
|
||||||
ShopType: 1,
|
ShopType: 1,
|
||||||
LbsType: LbsTypeGD,
|
LbsType: LbsTypeGD,
|
||||||
RiderPickMethod: 1,
|
RiderPickMethod: 1,
|
||||||
@@ -49,12 +53,13 @@ func TestCreateOrder(t *testing.T) {
|
|||||||
param := &CreateOrderReq{
|
param := &CreateOrderReq{
|
||||||
DevId: AppID,
|
DevId: AppID,
|
||||||
ShopId: TestSFStoreID,
|
ShopId: TestSFStoreID,
|
||||||
ShopOrderId: "20230518Test",
|
ShopOrderId: "20230525Test",
|
||||||
OrderSequence: "测试",
|
OrderSequence: "测试",
|
||||||
OrderSource: OrderSourceELM,
|
OrderSource: OrderSourceELM,
|
||||||
OrderTime: 1684302448,
|
OrderTime: 1684997166,
|
||||||
PushTime: 1684399264,
|
PushTime: 1684997166,
|
||||||
Version: 19,
|
Version: 19,
|
||||||
|
ReturnFlag: 511,
|
||||||
Receive: &ReceiveAddress{
|
Receive: &ReceiveAddress{
|
||||||
UserLng: "116.339392",
|
UserLng: "116.339392",
|
||||||
UserLat: "40.002349",
|
UserLat: "40.002349",
|
||||||
|
|||||||
@@ -25,14 +25,14 @@ type BaseRetVal struct {
|
|||||||
Result interface{} `json:"result"`
|
Result interface{} `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(devId int64, devKey string, config ...*platformapi.APIConfig) *API {
|
func New(devId int, devKey string, config ...*platformapi.APIConfig) *API {
|
||||||
curConfig := platformapi.DefAPIConfig
|
curConfig := platformapi.DefAPIConfig
|
||||||
if len(config) > 0 {
|
if len(config) > 0 {
|
||||||
curConfig = *config[0]
|
curConfig = *config[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
return &API{
|
return &API{
|
||||||
devId: devId,
|
devId: int64(devId),
|
||||||
devKey: devKey,
|
devKey: devKey,
|
||||||
locker: sync.RWMutex{},
|
locker: sync.RWMutex{},
|
||||||
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
client: &http.Client{Timeout: curConfig.ClientTimeout},
|
||||||
|
|||||||
Reference in New Issue
Block a user