小费接口
This commit is contained in:
@@ -145,3 +145,62 @@ func (a *API) GetRiderLatestPosition(sfOrderID string) (retVal *RiderLatestPosit
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// 添加小费
|
||||
func (a *API) AddTipFee(deliveryId string, fee int64) error {
|
||||
param := &Addordergratuityfee{
|
||||
DevId: a.devId,
|
||||
OrderId: deliveryId,
|
||||
PushTime: time.Now().Unix(),
|
||||
GratuityFee: fee,
|
||||
OrderType: 0,
|
||||
ShopId: 0,
|
||||
ShopType: 0,
|
||||
serialNumber: "",
|
||||
}
|
||||
resp := a.HttpPostJson("addordergratuityfee", param)
|
||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||
return errors.New("HTTP请求错误,请检查重试")
|
||||
}
|
||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||
return fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
}
|
||||
var retVal *AddordergratuityfeeResp
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err := json.Unmarshal(s, &retVal); err == nil {
|
||||
return nil
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// 获取运单小费
|
||||
func (a *API) QueryTipFee(sfOrderId string) (int64, error) {
|
||||
resp := a.HttpPostJson("getordergratuityfee", map[string]interface{}{
|
||||
"dev_id": a.devId,
|
||||
"order_id": sfOrderId,
|
||||
"push_time": time.Now().Unix()},
|
||||
)
|
||||
if resp.HttpStatusCode != HttpStatusSuccessCode {
|
||||
return 0, errors.New("HTTP请求错误,请检查重试")
|
||||
}
|
||||
if resp.BaseRetVal.ErrorCode != SuccessCode {
|
||||
return 0, fmt.Errorf("%s", resp.BaseRetVal.ErrorMsg)
|
||||
}
|
||||
var retVal *QueryOrderTipFee
|
||||
s, _ := json.Marshal(resp.BaseRetVal.Result)
|
||||
if err := json.Unmarshal(s, &retVal); err == nil {
|
||||
return retVal.TotalGratuityFee, nil
|
||||
} else {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
type QueryOrderTipFee struct {
|
||||
SfOrderId string //顺丰订单号,新版本V1.9+升级为JS开头的15位字符串类型, 老版本为int类型
|
||||
ShopOrderId string //商家订单号
|
||||
TotalGratuityFee int64 //该订单总的加小费金额
|
||||
TotalGratuityTimes int64 //该订单总的加小费次数
|
||||
GratuityFeeList interface{} // 加小费列表,未加则是空数组
|
||||
PushTime string //推送时间
|
||||
}
|
||||
|
||||
@@ -495,3 +495,25 @@ type MultiPickupInfo struct {
|
||||
}
|
||||
|
||||
//#endregion
|
||||
|
||||
// 添加小费请求参数
|
||||
type Addordergratuityfee struct {
|
||||
DevId int64 `json:"dev_id"` // 开发者ID
|
||||
OrderId string `json:"order_id"` // 订单id
|
||||
PushTime int64 `json:"push_time"` // 推送时间;秒级时间戳
|
||||
GratuityFee int64 `json:"gratuity_fee"` // 订单小费,单位分,加小费最低不能少于100分
|
||||
|
||||
OrderType int64 `json:"order_type"` // 订单ID类型
|
||||
ShopId int64 `json:"shop_id"` // 店铺id
|
||||
ShopType int64 `json:"shop_type"` // 店铺ID类型
|
||||
serialNumber string `json:"serial_number"` // 加小费传入的唯一标识,用来幂等处理
|
||||
}
|
||||
|
||||
// 添加小费返回参数
|
||||
type AddordergratuityfeeResp struct {
|
||||
SfOrderId string `json:"sf_order_id"` // 顺丰订单号
|
||||
ShopOrderId string `json:"shop_order_id"` // 商家订单号
|
||||
GratuityFee int `json:"gratuity_fee"` // 本次加小费金额
|
||||
TotalGratuityFee int `json:"total_gratuity_fee"` // 该订单总的加小费金额
|
||||
PushTime string `json:"push_time"` // 推送时间
|
||||
}
|
||||
|
||||
@@ -128,3 +128,32 @@ type LiquidatedDamagesFee struct {
|
||||
ReturnMsg string `json:"return_msg"` // 返回信息,如非空,为错误原因,如签名失败、参数格式校验错误
|
||||
ReturnCode string `json:"return_code"` // 状态,ok/fail表示成功
|
||||
}
|
||||
|
||||
// 支付小费
|
||||
func (a *API) AddTip(orderId, deliveryId string, tipFee int) error {
|
||||
param := a.MakeUURequestHead()
|
||||
param["order_code"] = deliveryId // 运单号
|
||||
param["origin_id"] = orderId // 订单单号
|
||||
param["onlinefee"] = tipFee // 小费金额
|
||||
|
||||
resp, err := a.AccessAPI(BaseURL, "payonlinefee.ashx", RequestPost, param)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var result *AddTipResult
|
||||
if err := utils.Map2StructByJson(resp, result, false); err != nil {
|
||||
return err
|
||||
}
|
||||
if result.ReturnCode != "ok" {
|
||||
return fmt.Errorf(result.ReturnMsg)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type AddTipResult struct {
|
||||
ReturnCode string `json:"return_code"` // 状态,ok/fail表示成功
|
||||
ReturnMsg string `json:"return_msg"` // 通知消息
|
||||
AppID string `json:"appid"`
|
||||
NonceStr string `json:"nonce_str"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user