From 20832cb210c36df4459b0d4f02cff543e1886f7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E5=AE=97=E6=A5=A0?= Date: Wed, 31 May 2023 15:38:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=8F=E8=B4=B9=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- platformapi/sfps2/order.go | 59 ++++++++++++++++++++++++++++++++++ platformapi/sfps2/sf_model.go | 22 +++++++++++++ platformapi/uuptapi/waybill.go | 29 +++++++++++++++++ 3 files changed, 110 insertions(+) diff --git a/platformapi/sfps2/order.go b/platformapi/sfps2/order.go index 437a4d5d..8f81a5c1 100644 --- a/platformapi/sfps2/order.go +++ b/platformapi/sfps2/order.go @@ -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 //推送时间 +} diff --git a/platformapi/sfps2/sf_model.go b/platformapi/sfps2/sf_model.go index 9559641d..c743d356 100644 --- a/platformapi/sfps2/sf_model.go +++ b/platformapi/sfps2/sf_model.go @@ -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"` // 推送时间 +} diff --git a/platformapi/uuptapi/waybill.go b/platformapi/uuptapi/waybill.go index 0e10fc3e..4e06a18d 100644 --- a/platformapi/uuptapi/waybill.go +++ b/platformapi/uuptapi/waybill.go @@ -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"` +}