- 达达与美团配送的接口修改为较正式参数
This commit is contained in:
@@ -21,58 +21,78 @@ const (
|
||||
BusinessTypeOther = -5
|
||||
)
|
||||
|
||||
func (a *API) ShopDetail(originShopID string) (shopDetail map[string]interface{}, err error) {
|
||||
const (
|
||||
ShopStatusOffline = 0 // -门店下线
|
||||
ShopStatusOnline = 1 // -门店激活
|
||||
)
|
||||
|
||||
type ShopInfo struct {
|
||||
StationName string `json:"station_name,omitempty"`
|
||||
Business int `json:"business,omitempty"`
|
||||
CityName string `json:"city_name,omitempty"`
|
||||
AreaName string `json:"area_name,omitempty"`
|
||||
StationAddress string `json:"station_address,omitempty"`
|
||||
Lng float64 `json:"lng,omitempty"`
|
||||
Lat float64 `json:"lat,omitempty"`
|
||||
ContactName string `json:"contact_name,omitempty"`
|
||||
Phone string `json:"phone,omitempty"`
|
||||
|
||||
OriginShopID string `json:"origin_shop_id,omitempty"`
|
||||
IDCard string `json:"id_card,omitempty"`
|
||||
UserName string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
|
||||
NewShopID string `json:"new_shop_id,omitempty"` // 修改用
|
||||
|
||||
BDName string `json:"bd_name,omitempty"` // 查询用
|
||||
BDPhone string `json:"bd_phone,omitempty"` // 查询用
|
||||
Status int `json:"status,omitempty"` // 查询用
|
||||
}
|
||||
|
||||
type AddShopFailInfo struct {
|
||||
Code int `json:"code"`
|
||||
ShopNo string `json:"shopNo"`
|
||||
Msg string `json:"msg"`
|
||||
ShopName string `json:"shopName"`
|
||||
}
|
||||
|
||||
type AddShopResult struct {
|
||||
Success int `json:"success"`
|
||||
SuccessList []*ShopInfo `json:"successList"`
|
||||
FailedList []*AddShopFailInfo `json:"failedList"`
|
||||
}
|
||||
|
||||
func (a *API) ShopDetail(originShopID string) (shopDetail *ShopInfo, err error) {
|
||||
params := map[string]interface{}{
|
||||
"origin_shop_id": originShopID,
|
||||
}
|
||||
result, err := a.AccessAPI("api/shop/detail", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(result.Result, &shopDetail, false)
|
||||
}
|
||||
return result.Result.(map[string]interface{}), nil
|
||||
return shopDetail, err
|
||||
}
|
||||
|
||||
func (a *API) ShopAdd(originShopID, stationName string, business int, cityName, areaName, stationAddress string, lng, lat float64, contactName, phone string, addParams map[string]interface{}) (outOriginShopID string, err error) {
|
||||
params := map[string]interface{}{
|
||||
"station_name": stationName,
|
||||
"business": business,
|
||||
"city_name": cityName,
|
||||
"area_name": areaName,
|
||||
"station_address": stationAddress,
|
||||
"lng": lng,
|
||||
"lat": lat,
|
||||
"contact_name": contactName,
|
||||
"phone": phone,
|
||||
}
|
||||
if originShopID != "" {
|
||||
params["origin_shop_id"] = originShopID
|
||||
}
|
||||
if addParams != nil {
|
||||
params = utils.MergeMaps(params, addParams)
|
||||
}
|
||||
successList, failedList, err := a.BatchShopAdd([]map[string]interface{}{params})
|
||||
if err != nil {
|
||||
if len(failedList) == 1 {
|
||||
return "", utils.NewErrorIntCode(failedList[0]["msg"].(string), int(utils.MustInterface2Int64(failedList[0]["code"])))
|
||||
}
|
||||
func (a *API) ShopAdd(shopInfo *ShopInfo) (outOriginShopID string, err error) {
|
||||
addResult, err := a.BatchShopAdd([]*ShopInfo{shopInfo})
|
||||
if addResult != nil && len(addResult.FailedList) == 1 {
|
||||
return "", utils.NewErrorIntCode(addResult.FailedList[0].Msg, int(utils.MustInterface2Int64(addResult.FailedList[0].Code)))
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return utils.Interface2String(successList[0]["originShopId"]), nil
|
||||
return addResult.SuccessList[0].OriginShopID, nil
|
||||
}
|
||||
|
||||
func (a *API) BatchShopAdd(shopInfoList []map[string]interface{}) (successList, failedList []map[string]interface{}, err error) {
|
||||
func (a *API) BatchShopAdd(shopInfoList []*ShopInfo) (addResult *AddShopResult, err error) {
|
||||
result, err := a.AccessAPI("api/shop/add", shopInfoList)
|
||||
mapResult := result.Result.(map[string]interface{})
|
||||
if successList2 := mapResult["successList"]; successList2 != nil {
|
||||
successList = utils.Slice2MapSlice(successList2.([]interface{}))
|
||||
err2 := utils.Map2StructByJson(result.Result, &addResult, false)
|
||||
if err == nil {
|
||||
err = err2
|
||||
}
|
||||
if failedList2 := mapResult["failedList"]; failedList2 != nil {
|
||||
failedList = utils.Slice2MapSlice(failedList2.([]interface{}))
|
||||
}
|
||||
return successList, failedList, err
|
||||
return addResult, err
|
||||
}
|
||||
|
||||
func (a *API) ShopUpdate(originShopID string, shopInfo map[string]interface{}) (err error) {
|
||||
_, err = a.AccessAPI("api/shop/update", utils.MergeMaps(utils.Params2Map("origin_shop_id", originShopID), shopInfo))
|
||||
func (a *API) ShopUpdate(shopInfo *ShopInfo) (err error) {
|
||||
_, err = a.AccessAPI("api/shop/update", shopInfo)
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -15,10 +15,33 @@ func TestShopDetail(t *testing.T) {
|
||||
baseapi.SugarLogger.Debug(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
func TestShopAddl(t *testing.T) {
|
||||
result, err := dadaapi.ShopAdd("18180948107", "京西大本营", BusinessTypeFruitVegetable, "成都市", "金牛区", "西南交通大学科技大厦二楼", 104.056844, 30.695151, "徐先生", "18180948107", nil)
|
||||
func TestShopAdd(t *testing.T) {
|
||||
shopInfo := &ShopInfo{
|
||||
OriginShopID: "181809481071",
|
||||
StationName: "京西大本营2",
|
||||
Business: BusinessTypeFruitVegetable,
|
||||
CityName: "成都市",
|
||||
AreaName: "金牛区",
|
||||
StationAddress: "西南交通大学科技大厦二楼",
|
||||
Lng: 104.056844,
|
||||
Lat: 30.695151,
|
||||
ContactName: "徐先生",
|
||||
Phone: "18180948107",
|
||||
}
|
||||
result, err := dadaapi.ShopAdd(shopInfo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
baseapi.SugarLogger.Debug(result)
|
||||
}
|
||||
|
||||
func TestShopUpdate(t *testing.T) {
|
||||
shopInfo := &ShopInfo{
|
||||
OriginShopID: "18180948107",
|
||||
StationName: "京西大本营234",
|
||||
}
|
||||
err := dadaapi.ShopUpdate(shopInfo)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user