88 lines
3.0 KiB
Go
88 lines
3.0 KiB
Go
package dadaapi
|
|
|
|
import (
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
"github.com/fatih/structs"
|
|
)
|
|
|
|
type OperateOrderRequiredParams struct {
|
|
ShopNo string `json:"shop_no"`
|
|
OriginId string `json:"origin_id"`
|
|
CityCode string `json:"city_code"`
|
|
CargoPrice float64 `json:"cargo_price"`
|
|
IsPrepay int `json:"is_prepay"`
|
|
ReceiverName string `json:"receiver_name"`
|
|
ReceiverAddress string `json:"receiver_address"`
|
|
ReceiverLat float64 `json:"receiver_lat"`
|
|
ReceiverLng float64 `json:"receiver_lng"`
|
|
ReceiverPhone string `json:"receiver_phone"`
|
|
ReceiverTel string `json:"receiver_tel"`
|
|
}
|
|
|
|
type CreateOrderResponse struct {
|
|
Distance float64
|
|
Fee float64
|
|
DeliverFee float64
|
|
CouponFee float64
|
|
Tips float64
|
|
InsuranceFee float64
|
|
}
|
|
|
|
func (d *DadaAPI) QueryOrderInfo(orderId string) (retVal map[string]interface{}, err error) {
|
|
params := make(map[string]interface{})
|
|
params["order_id"] = orderId
|
|
result, err := d.AccessDada("api/order/status/query", params)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return result.Result.(map[string]interface{}), nil
|
|
}
|
|
|
|
func map2CreateOrderResponse(mapData map[string]interface{}) *CreateOrderResponse {
|
|
retVal := new(CreateOrderResponse)
|
|
retVal.Distance = utils.MustInterface2Float64(mapData["distance"])
|
|
retVal.Fee = utils.MustInterface2Float64(mapData["fee"])
|
|
retVal.DeliverFee = utils.MustInterface2Float64(mapData["deliverFee"])
|
|
|
|
if value, ok := mapData["couponFee"]; ok {
|
|
retVal.CouponFee = utils.MustInterface2Float64(value)
|
|
}
|
|
if value, ok := mapData["tips"]; ok {
|
|
retVal.CouponFee = utils.MustInterface2Float64(value)
|
|
}
|
|
if value, ok := mapData["insuranceFee"]; ok {
|
|
retVal.CouponFee = utils.MustInterface2Float64(value)
|
|
}
|
|
|
|
return retVal
|
|
}
|
|
|
|
func (d *DadaAPI) operateOrder(action string, orderInfo *OperateOrderRequiredParams, addParams map[string]interface{}) (retVal *CreateOrderResponse, err error) {
|
|
params := structs.Map(orderInfo)
|
|
params["callback"] = d.callbackURL
|
|
allParams := utils.MergeMaps(params, addParams)
|
|
|
|
result, err := d.AccessDada(action, allParams)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return map2CreateOrderResponse(result.Result.(map[string]interface{})), nil
|
|
}
|
|
|
|
func (d *DadaAPI) AddOrder(orderInfo *OperateOrderRequiredParams, addParams map[string]interface{}) (retVal *CreateOrderResponse, err error) {
|
|
return d.operateOrder("api/order/addOrder", orderInfo, addParams)
|
|
}
|
|
|
|
func (d *DadaAPI) ReaddOrder(orderInfo *OperateOrderRequiredParams, addParams map[string]interface{}) (retVal *CreateOrderResponse, err error) {
|
|
return d.operateOrder("api/order/reAddOrder", orderInfo, addParams)
|
|
}
|
|
|
|
func (d *DadaAPI) QueryDeliverFee(orderInfo *OperateOrderRequiredParams, addParams map[string]interface{}) (retVal *CreateOrderResponse, err error) {
|
|
return d.operateOrder("api/order/queryDeliverFee", orderInfo, addParams)
|
|
}
|
|
|
|
func (d *DadaAPI) AddOrderAfterQuery(orderInfo *OperateOrderRequiredParams, addParams map[string]interface{}) (retVal *CreateOrderResponse, err error) {
|
|
return d.operateOrder("api/order/addAfterQuery", orderInfo, addParams)
|
|
}
|