- serveral store apis for ebai.
This commit is contained in:
@@ -25,10 +25,11 @@ type ResponseResult struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type API struct {
|
type API struct {
|
||||||
source string
|
source string
|
||||||
secret string
|
secret string
|
||||||
client *http.Client
|
encrypt string
|
||||||
config *platformapi.APIConfig
|
client *http.Client
|
||||||
|
config *platformapi.APIConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(source, secret string, config ...*platformapi.APIConfig) *API {
|
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},
|
"source": []string{a.source},
|
||||||
"body": []string{string(utils.MustMarshal(body))},
|
"body": []string{string(utils.MustMarshal(body))},
|
||||||
"secret": []string{a.secret},
|
"secret": []string{a.secret},
|
||||||
|
"encrypt": []string{a.encrypt},
|
||||||
}
|
}
|
||||||
params[signKey] = []string{a.signParams(params)}
|
params[signKey] = []string{a.signParams(params)}
|
||||||
encodedParams := params.Encode()
|
encodedParams := params.Encode()
|
||||||
|
|||||||
@@ -9,6 +9,11 @@ import (
|
|||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
testShopBaiduID = 2233043816
|
||||||
|
testShopID = "test_708706_63032"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
api *API
|
api *API
|
||||||
sugarLogger *zap.SugaredLogger
|
sugarLogger *zap.SugaredLogger
|
||||||
@@ -20,7 +25,7 @@ func init() {
|
|||||||
baseapi.Init(sugarLogger)
|
baseapi.Init(sugarLogger)
|
||||||
|
|
||||||
// sandbox
|
// sandbox
|
||||||
api = New("source", "secret")
|
api = New("63032", "8c8b66720b69ae85")
|
||||||
// prod
|
// prod
|
||||||
// api = New("source", "secret")
|
// api = New("source", "secret")
|
||||||
}
|
}
|
||||||
@@ -30,13 +35,15 @@ func TestTest(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAccessAPI(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 {
|
if err != nil {
|
||||||
t.Fatalf("Error when accessing AccessAPI result:%v, error:%v", result, err)
|
t.Fatalf("Error when accessing AccessAPI result:%v, error:%v", result, err)
|
||||||
} else {
|
} else {
|
||||||
shopInfo := result.Data.(map[string]interface{})
|
t.Log(utils.Format4Output(result, false))
|
||||||
if len(shopInfo) > 0 {
|
// shopInfo := result.Data.(map[string]interface{})
|
||||||
t.Fatalf("data is not correct:%v", shopInfo)
|
// if len(shopInfo) > 0 {
|
||||||
}
|
// t.Fatalf("data is not correct:%v", shopInfo)
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,9 +4,54 @@ import (
|
|||||||
"git.rosy.net.cn/baseapi/utils"
|
"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 {
|
type ShopInfo struct {
|
||||||
ShopID int `json:"shop_id"`
|
ShopID string `json:"shop_id"`
|
||||||
BaiduShopID int `json:"baidu_shop_id"`
|
BaiduShopID int64 `json:"baidu_shop_id"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Status int `json:"status"`
|
Status int `json:"status"`
|
||||||
SysStatus int `json:"sys_status"`
|
SysStatus int `json:"sys_status"`
|
||||||
@@ -14,17 +59,30 @@ type ShopInfo struct {
|
|||||||
OrderStatusPush int `json:"order_status_push"`
|
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{}{}
|
body := map[string]interface{}{}
|
||||||
if orderPush >= 0 {
|
// if orderPush >= 0 {
|
||||||
body["order_push"] = orderPush
|
// body["order_push"] = orderPush
|
||||||
}
|
// }
|
||||||
if orderStatusPush >= 0 {
|
// if orderStatusPush >= 0 {
|
||||||
body["order_status_push"] = orderStatusPush
|
// body["order_status_push"] = orderStatusPush
|
||||||
}
|
// }
|
||||||
if status >= 0 {
|
// if status >= 0 {
|
||||||
body["status"] = status
|
// body["status"] = status
|
||||||
}
|
// }
|
||||||
if sysStatus >= 0 {
|
if sysStatus >= 0 {
|
||||||
body["sys_status"] = sysStatus
|
body["sys_status"] = sysStatus
|
||||||
}
|
}
|
||||||
@@ -35,11 +93,38 @@ func (a *API) ShopList(orderPush, orderStatusPush, status, sysStatus int) (shopL
|
|||||||
for k, v := range list {
|
for k, v := range list {
|
||||||
mapData := v.(map[string]interface{})
|
mapData := v.(map[string]interface{})
|
||||||
shopList[k] = &ShopInfo{
|
shopList[k] = &ShopInfo{
|
||||||
ShopID: int(utils.MustInterface2Int64(mapData["shop_id"])),
|
ShopID: utils.Interface2String(mapData[KeyShopID]),
|
||||||
BaiduShopID: int(utils.MustInterface2Int64(mapData["baidu_shop_id"])),
|
BaiduShopID: utils.Str2Int64(utils.Interface2String(mapData[KeyBaiduShopID])),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return shopList, nil
|
return shopList, nil
|
||||||
}
|
}
|
||||||
return nil, err
|
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
|
||||||
|
}
|
||||||
|
|||||||
55
platformapi/ebaiapi/shop_test.go
Normal file
55
platformapi/ebaiapi/shop_test.go
Normal file
@@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user