- refactor result parser.
This commit is contained in:
@@ -51,12 +51,34 @@ const (
|
||||
PromotionTypeBuyGiveGift = 6
|
||||
)
|
||||
|
||||
const (
|
||||
QueryOrderRetryCount = 1 // 因为京东到家当前不存在的订单也返回-4,暂时不重试
|
||||
)
|
||||
|
||||
var (
|
||||
ErrCanNotFindOrder = errors.New("can not find order")
|
||||
)
|
||||
|
||||
var (
|
||||
orderOperationResultParser = genNoPageResultParser("code", "msg", "detail", "0")
|
||||
)
|
||||
|
||||
// 订单列表查询接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=ba3027848c3c4fda9674966e2a466482
|
||||
func (a *API) OrderQuery(jdParams map[string]interface{}) (retVal []interface{}, totalCount int, err error) {
|
||||
return a.AccessAPIHavePage("order/es/query", jdParams, nil, nil, nil)
|
||||
// 最多试三次
|
||||
for i := 0; i < QueryOrderRetryCount; i++ {
|
||||
retVal, totalCount, err = a.AccessAPIHavePage("order/es/query", jdParams, nil, nil, nil)
|
||||
if err != nil {
|
||||
if err2, ok := err.(*utils.ErrorWithCode); ok {
|
||||
if err2.IntCode() == -4 {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
return retVal, totalCount, err
|
||||
}
|
||||
|
||||
// orderFreightMoney 基础运费
|
||||
@@ -66,7 +88,7 @@ func (a *API) OrderQuery(jdParams map[string]interface{}) (retVal []interface{},
|
||||
func (a *API) QuerySingleOrder(orderId string) (map[string]interface{}, error) {
|
||||
jdParams := make(map[string]interface{})
|
||||
jdParams["orderId"] = orderId
|
||||
result, _, err := a.AccessAPIHavePage("order/es/query", jdParams, nil, nil, nil)
|
||||
result, _, err := a.OrderQuery(jdParams)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -97,64 +119,71 @@ func (a *API) LegacyQuerySingleOrder(orderId string) (map[string]interface{}, er
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (a *API) OrderAcceptOperate(orderId string, isAgreed bool, userName string) (interface{}, error) {
|
||||
// 商家确认接单接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=c1a15129d1374e9da7fa35487f878604
|
||||
func (a *API) OrderAcceptOperate(orderId string, isAgreed bool, userName string) error {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
"isAgreed": utils.Bool2String(isAgreed),
|
||||
"operator": utils.GetAPIOperator(userName),
|
||||
}
|
||||
return a.AccessAPINoPage("ocs/orderAcceptOperate", jdParams, nil, nil, nil)
|
||||
_, err := a.AccessAPINoPage("ocs/orderAcceptOperate", jdParams, nil, nil, orderOperationResultParser)
|
||||
return err
|
||||
}
|
||||
|
||||
// 拣货完成且众包配送接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=ed93745b86c6487eaaea5f55a84785ac
|
||||
func (a *API) OrderJDZBDelivery(orderId string, userName string) (interface{}, error) {
|
||||
func (a *API) OrderJDZBDelivery(orderId string, userName string) (detail string, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
"operator": utils.GetAPIOperator(userName),
|
||||
}
|
||||
return a.AccessAPINoPage("bm/open/api/order/OrderJDZBDelivery", jdParams, nil, nil, nil)
|
||||
result, err := a.AccessAPINoPage("bm/open/api/order/OrderJDZBDelivery", jdParams, nil, nil, orderOperationResultParser)
|
||||
if err == nil {
|
||||
return result.(string), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 订单达达配送转商家自送接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=e7b4950164754eecac7ea87278c2b071
|
||||
func (a *API) ModifySellerDelivery(orderId string, userName string) (interface{}, error) {
|
||||
func (a *API) ModifySellerDelivery(orderId string, userName string) (detail string, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
"updatePin": utils.GetAPIOperator(userName),
|
||||
}
|
||||
return a.AccessAPINoPage("order/modifySellerDelivery", jdParams, nil, nil, nil)
|
||||
result, err := a.AccessAPINoPage("order/modifySellerDelivery", jdParams, nil, nil, orderOperationResultParser)
|
||||
if err == nil {
|
||||
return result.(string), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 拣货完成且商家自送接口(这个接口是商家本身配置为自送模式下才能调用的接口,如果启用了达达配送,是不能调用的)
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=0e08e71a45dc48b6a337e06a852ac33a
|
||||
func (a *API) OrderSerllerDelivery(orderId string, userName string) (interface{}, error) {
|
||||
func (a *API) OrderSerllerDelivery(orderId string, userName string) (detail string, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
"operator": utils.GetAPIOperator(userName),
|
||||
}
|
||||
return a.AccessAPINoPage("bm/open/api/order/OrderSerllerDelivery", jdParams, nil, nil, nil)
|
||||
result, err := a.AccessAPINoPage("bm/open/api/order/OrderSerllerDelivery", jdParams, nil, nil, orderOperationResultParser)
|
||||
if err == nil {
|
||||
return result.(string), nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 商家自送,订单妥投接口
|
||||
// https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=ecc80f06d35141979f4841f345001f74
|
||||
func (a *API) DeliveryEndOrder(orderId string, userName string) (interface{}, error) {
|
||||
func (a *API) DeliveryEndOrder(orderId string, userName string) (result map[string]interface{}, err error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
"operPin": utils.GetAPIOperator(userName),
|
||||
"operTime": utils.GetCurTimeStr(),
|
||||
}
|
||||
return a.AccessAPINoPage("ocs/deliveryEndOrder", jdParams, nil, nil, nil)
|
||||
}
|
||||
|
||||
//订单金额拆分接口
|
||||
func (a *API) QueryOassBussMoney(orderId string) ([]interface{}, error) {
|
||||
jdParams := map[string]interface{}{
|
||||
"orderId": orderId,
|
||||
tmpResult, err := a.AccessAPINoPage("ocs/deliveryEndOrder", jdParams, nil, nil, nil)
|
||||
if err == nil {
|
||||
return tmpResult.(map[string]interface{}), nil
|
||||
}
|
||||
result, err := a.AccessAPINoPage("oassBussService/queryOassBussMoney", jdParams, nil, nil, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return result.([]interface{}), nil
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user