From 4813ff4ce60d449a1e66afb2496c5b72e562686e Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 22 Aug 2018 16:16:19 +0800 Subject: [PATCH] - add operator for some jd api. --- platformapi/jdapi/jdapi_test.go | 10 +++++----- platformapi/jdapi/order.go | 29 +++++++++++++++++++---------- utils/utils.go | 8 ++++++-- 3 files changed, 30 insertions(+), 17 deletions(-) diff --git a/platformapi/jdapi/jdapi_test.go b/platformapi/jdapi/jdapi_test.go index a12f29a1..c5194fba 100644 --- a/platformapi/jdapi/jdapi_test.go +++ b/platformapi/jdapi/jdapi_test.go @@ -232,7 +232,7 @@ func TestCallbackMsgPlayback(t *testing.T) { } } func TestOrderAcceptOperate(t *testing.T) { - result, err := jdapi.OrderAcceptOperate("813344594000041", true) + result, err := jdapi.OrderAcceptOperate("813344594000041", true, "") if err != nil { t.Fatal(err.Error()) } @@ -240,7 +240,7 @@ func TestOrderAcceptOperate(t *testing.T) { } func TestOrderJDZBDelivery(t *testing.T) { - result, err := jdapi.OrderJDZBDelivery("813344594000041") + result, err := jdapi.OrderJDZBDelivery("813344594000041", "") if err != nil { t.Fatal(err.Error()) } @@ -248,7 +248,7 @@ func TestOrderJDZBDelivery(t *testing.T) { } func TestModifySellerDelivery(t *testing.T) { - result, err := jdapi.ModifySellerDelivery("813344594000041") + result, err := jdapi.ModifySellerDelivery("813344594000041", "") if err != nil { t.Fatal(err.Error()) } @@ -256,7 +256,7 @@ func TestModifySellerDelivery(t *testing.T) { } func TestOrderSerllerDelivery(t *testing.T) { - result, err := jdapi.OrderSerllerDelivery("813344594000041") + result, err := jdapi.OrderSerllerDelivery("813344594000041", "") if err != nil { t.Fatal(err.Error()) } @@ -264,7 +264,7 @@ func TestOrderSerllerDelivery(t *testing.T) { } func TestDeliveryEndOrder(t *testing.T) { - result, err := jdapi.DeliveryEndOrder("813344594000041") + result, err := jdapi.DeliveryEndOrder("813344594000041", "") if err != nil { t.Fatal(err.Error()) } diff --git a/platformapi/jdapi/order.go b/platformapi/jdapi/order.go index c6fd5e49..5b8e43b7 100644 --- a/platformapi/jdapi/order.go +++ b/platformapi/jdapi/order.go @@ -1,6 +1,8 @@ package jdapi import ( + "errors" + "git.rosy.net.cn/baseapi/utils" ) @@ -49,6 +51,10 @@ const ( PromotionTypeBuyGiveGift = 6 ) +var ( + ErrCanNotFindOrder = errors.New("can not find order") +) + func (a API) OrderQuery(jdParams map[string]interface{}) (retVal []interface{}, err error) { retVal, err = a.AccessAPIHavePage("order/es/query", jdParams, nil, nil, nil) return @@ -65,6 +71,9 @@ func (a API) QuerySingleOrder(orderId string) (map[string]interface{}, error) { if err != nil { return nil, err } + if len(result) == 0 { + return nil, ErrCanNotFindOrder + } return result[0].(map[string]interface{}), nil } @@ -89,51 +98,51 @@ func (a API) LegacyQuerySingleOrder(orderId string) (map[string]interface{}, err return result, nil } -func (a API) OrderAcceptOperate(orderId string, isAgreed bool) (interface{}, error) { +func (a API) OrderAcceptOperate(orderId string, isAgreed bool, userName string) (interface{}, error) { jdParams := map[string]interface{}{ "orderId": orderId, "isAgreed": utils.Bool2String(isAgreed), - "operator": utils.GetAPIOperator(), + "operator": utils.GetAPIOperator(userName), } return a.AccessAPINoPage("ocs/orderAcceptOperate", jdParams, nil, nil) } // 拣货完成且众包配送接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=ed93745b86c6487eaaea5f55a84785ac -func (a API) OrderJDZBDelivery(orderId string) (interface{}, error) { +func (a API) OrderJDZBDelivery(orderId string, userName string) (interface{}, error) { jdParams := map[string]interface{}{ "orderId": orderId, - "operator": utils.GetAPIOperator(), + "operator": utils.GetAPIOperator(userName), } return a.AccessAPINoPage("bm/open/api/order/OrderJDZBDelivery", jdParams, nil, nil) } // 订单达达配送转商家自送接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=e7b4950164754eecac7ea87278c2b071 -func (a API) ModifySellerDelivery(orderId string) (interface{}, error) { +func (a API) ModifySellerDelivery(orderId string, userName string) (interface{}, error) { jdParams := map[string]interface{}{ "orderId": orderId, - "updatePin": utils.GetAPIOperator(), + "updatePin": utils.GetAPIOperator(userName), } return a.AccessAPINoPage("order/modifySellerDelivery", jdParams, nil, nil) } // 拣货完成且商家自送接口(这个接口是商家本身配置为自送模式下才能调用的接口,如果启用了达达配送,是不能调用的) // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=0e08e71a45dc48b6a337e06a852ac33a -func (a API) OrderSerllerDelivery(orderId string) (interface{}, error) { +func (a API) OrderSerllerDelivery(orderId string, userName string) (interface{}, error) { jdParams := map[string]interface{}{ "orderId": orderId, - "operator": utils.GetAPIOperator(), + "operator": utils.GetAPIOperator(userName), } return a.AccessAPINoPage("bm/open/api/order/OrderSerllerDelivery", jdParams, nil, nil) } // 商家自送,订单妥投接口 // https://opendj.jd.com/staticnew/widgets/resources.html?groupid=169&apiid=ecc80f06d35141979f4841f345001f74 -func (a API) DeliveryEndOrder(orderId string) (interface{}, error) { +func (a API) DeliveryEndOrder(orderId string, userName string) (interface{}, error) { jdParams := map[string]interface{}{ "orderId": orderId, - "operPin": utils.GetAPIOperator(), + "operPin": utils.GetAPIOperator(userName), "operTime": utils.GetCurTimeStr(), } return a.AccessAPINoPage("ocs/deliveryEndOrder", jdParams, nil, nil) diff --git a/utils/utils.go b/utils/utils.go index 3a7b6502..06f535e4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -89,8 +89,12 @@ func GetCurTimestamp() int64 { return time.Now().Unix() } -func GetAPIOperator() string { - return "jxc4-admin" +func GetAPIOperator(userName string) string { + retVal := "jxc4-admin" + if userName != "" { + retVal += "-" + userName + } + return retVal } func MergeMaps(firstMap map[string]interface{}, otherMaps ...map[string]interface{}) (retVal map[string]interface{}) {