diff --git a/platformapi/ebaiapi/ebaiapi.go b/platformapi/ebaiapi/ebaiapi.go index 4772729f..eb97766f 100644 --- a/platformapi/ebaiapi/ebaiapi.go +++ b/platformapi/ebaiapi/ebaiapi.go @@ -25,10 +25,11 @@ type ResponseResult struct { } type API struct { - source string - secret string - client *http.Client - config *platformapi.APIConfig + source string + secret string + encrypt string + client *http.Client + config *platformapi.APIConfig } func New(source, secret string, config ...*platformapi.APIConfig) *API { @@ -72,6 +73,7 @@ func (a *API) AccessAPI(cmd string, body map[string]interface{}) (retVal *Respon "source": []string{a.source}, "body": []string{string(utils.MustMarshal(body))}, "secret": []string{a.secret}, + "encrypt": []string{a.encrypt}, } params[signKey] = []string{a.signParams(params)} encodedParams := params.Encode() diff --git a/platformapi/ebaiapi/ebaiapi_test.go b/platformapi/ebaiapi/ebaiapi_test.go index 2fcb5c3e..9ba4e2f9 100644 --- a/platformapi/ebaiapi/ebaiapi_test.go +++ b/platformapi/ebaiapi/ebaiapi_test.go @@ -9,6 +9,11 @@ import ( "go.uber.org/zap" ) +const ( + testShopBaiduID = 2233043816 + testShopID = "test_708706_63032" +) + var ( api *API sugarLogger *zap.SugaredLogger @@ -20,7 +25,7 @@ func init() { baseapi.Init(sugarLogger) // sandbox - api = New("source", "secret") + api = New("63032", "8c8b66720b69ae85") // prod // api = New("source", "secret") } @@ -30,13 +35,15 @@ func TestTest(t *testing.T) { } func TestAccessAPI(t *testing.T) { - result, err := api.AccessAPI("shop.get", utils.Params2Map("baidu_shop_id", "2232527731")) + // + result, err := api.AccessAPI("shop.get", utils.Params2Map("baidu_shop_id", testShopBaiduID)) if err != nil { t.Fatalf("Error when accessing AccessAPI result:%v, error:%v", result, err) } else { - shopInfo := result.Data.(map[string]interface{}) - if len(shopInfo) > 0 { - t.Fatalf("data is not correct:%v", shopInfo) - } + t.Log(utils.Format4Output(result, false)) + // shopInfo := result.Data.(map[string]interface{}) + // if len(shopInfo) > 0 { + // t.Fatalf("data is not correct:%v", shopInfo) + // } } } diff --git a/platformapi/ebaiapi/shop.go b/platformapi/ebaiapi/shop.go index 5eb04f2a..09cad7c1 100644 --- a/platformapi/ebaiapi/shop.go +++ b/platformapi/ebaiapi/shop.go @@ -4,9 +4,54 @@ import ( "git.rosy.net.cn/baseapi/utils" ) +const ( + SysStatusAll = -1 + SysStatusNew = 1 + SysStatusModifiedWait = 3 + SysStatusFailedVerify = 4 + SysStatusOpening = 6 + SysStatusNewWait = 7 + SysStatusOnlineRejected = 8 + SysStatusPassQC = 12 +) + +const ( + ShopBusStatusOffline = 1 + ShopBusStatusCanBooking = 2 + ShopBusStatusOpening = 3 + ShopBusStatusSuspended = 4 + ShopBusStatusBookingNextDay = 5 +) + +const ( + PlatformFlagElm = "1" + PlatformFlagBaidu = "2" +) + +const ( + KeyShopID = "shop_id" + KeyBaiduShopID = "baidu_shop_id" + + KeyName = "name" + KeyPhone = "phone" +) + +const ( + CoordTypeBaidu = "bdll" + CoordTypeAutonavi = "amap" +) + +const ( + DeliveryTypeBaiduLogistics = 1 + DeliveryTypeBaiduDeliveryBySelf = 2 + DeliveryTypeBaiduCrowdSourcing = 3 + DeliveryTypeBaiduXiaofeixia = 7 + DeliveryTypeBaiduKuaidipeisong = 8 +) + type ShopInfo struct { - ShopID int `json:"shop_id"` - BaiduShopID int `json:"baidu_shop_id"` + ShopID string `json:"shop_id"` + BaiduShopID int64 `json:"baidu_shop_id"` Name string `json:"name"` Status int `json:"status"` SysStatus int `json:"sys_status"` @@ -14,17 +59,30 @@ type ShopInfo struct { OrderStatusPush int `json:"order_status_push"` } -func (a *API) ShopList(orderPush, orderStatusPush, status, sysStatus int) (shopList []*ShopInfo, err error) { +func (a *API) genParams(shopID string, baiduShopID int64) map[string]interface{} { + if shopID == "" && baiduShopID == 0 || shopID != "" && baiduShopID != 0 { + panic("shopID and baiduShopID can not all be empty or all not be empty") + } + params := map[string]interface{}{} + if shopID != "" { + params[KeyShopID] = shopID + } else { + params[KeyBaiduShopID] = baiduShopID + } + return params +} + +func (a *API) ShopList( /*orderPush, orderStatusPush, status, */ sysStatus int) (shopList []*ShopInfo, err error) { body := map[string]interface{}{} - if orderPush >= 0 { - body["order_push"] = orderPush - } - if orderStatusPush >= 0 { - body["order_status_push"] = orderStatusPush - } - if status >= 0 { - body["status"] = status - } + // if orderPush >= 0 { + // body["order_push"] = orderPush + // } + // if orderStatusPush >= 0 { + // body["order_status_push"] = orderStatusPush + // } + // if status >= 0 { + // body["status"] = status + // } if sysStatus >= 0 { body["sys_status"] = sysStatus } @@ -35,11 +93,38 @@ func (a *API) ShopList(orderPush, orderStatusPush, status, sysStatus int) (shopL for k, v := range list { mapData := v.(map[string]interface{}) shopList[k] = &ShopInfo{ - ShopID: int(utils.MustInterface2Int64(mapData["shop_id"])), - BaiduShopID: int(utils.MustInterface2Int64(mapData["baidu_shop_id"])), + ShopID: utils.Interface2String(mapData[KeyShopID]), + BaiduShopID: utils.Str2Int64(utils.Interface2String(mapData[KeyBaiduShopID])), } } return shopList, nil } return nil, err } + +func (a *API) ShopGet(shopID string, baiduShopID int64) (shop map[string]interface{}, err error) { + params := a.genParams(shopID, baiduShopID) + result, err := a.AccessAPI("shop.get", params) + if err == nil { + return result.Data.(map[string]interface{}), nil + } + return nil, err +} + +func (a *API) ShopUpdate(params map[string]interface{}) (err error) { + _, err = a.AccessAPI("shop.update", params) + if err == nil { + return nil + } + return err +} + +func (a *API) ShopBusStatusGet(shopID string, baiduShopID int64, platformFlag string) (busStatus int, err error) { + params := a.genParams(shopID, baiduShopID) + params["platformFlag"] = platformFlag + result, err := a.AccessAPI("shop.busstatus.get", params) + if err == nil { + return int(utils.MustInterface2Int64(result.Data.(map[string]interface{})["shop_busstatus"])), nil + } + return 0, err +} diff --git a/platformapi/ebaiapi/shop_test.go b/platformapi/ebaiapi/shop_test.go new file mode 100644 index 00000000..95269924 --- /dev/null +++ b/platformapi/ebaiapi/shop_test.go @@ -0,0 +1,55 @@ +package ebaiapi + +import ( + "testing" + + "git.rosy.net.cn/baseapi/utils" +) + +func TestShopList(t *testing.T) { + result, err := api.ShopList(SysStatusAll) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } +} + +func TestShopGet(t *testing.T) { + result, err := api.ShopGet("", testShopBaiduID) + if err != nil { + t.Fatal(err) + } else { + t.Log(utils.Format4Output(result, false)) + } + + // result, err = api.ShopGet(testShopID, 0) + // if err != nil { + // t.Fatal(err) + // } else { + // t.Log(utils.Format4Output(result, false)) + // } +} + +func TestShopUpdate(t *testing.T) { + params := map[string]interface{}{ + KeyShopID: testShopID, + // KeyName: "hello", + "phone": "13812345678", + } + err := api.ShopUpdate(params) + if err != nil { + t.Fatal(err) + } else { + + } +} + +func TestShopBusStatusGet(t *testing.T) { + result, err := api.ShopBusStatusGet(testShopID, 0, PlatformFlagBaidu) + if err != nil { + t.Fatal(err) + } else { + t.Log(result) + } +}