- 饿百页面拉取方法调整GetStoreList
This commit is contained in:
@@ -515,22 +515,45 @@ func (a *API) PageGetCustomCatList(baiduShopID int64) (catList []map[string]inte
|
||||
return nil, err
|
||||
}
|
||||
|
||||
func (a *API) GetStoreList(lng string, lat string) (retVal map[string]interface{}, err error) {
|
||||
func (a *API) GetStoreList(lng string, lat string, pageNo, pageSize int) (shopListInfo *PageListInfo, err error) {
|
||||
if pageNo <= 0 {
|
||||
pageNo = 1
|
||||
}
|
||||
if pageSize > 20 || pageSize <= 0 {
|
||||
pageSize = 20
|
||||
}
|
||||
params := map[string]interface{}{
|
||||
"channel": "kitchen",
|
||||
"pn": 1,
|
||||
"rn": 999,
|
||||
"rn": pageSize,
|
||||
"pn": pageNo,
|
||||
"lng": lng,
|
||||
"lat": lat,
|
||||
}
|
||||
retVal, err = a.AccessStorePageNoCookie("/newretail/main/shoplist", params)
|
||||
return retVal, err
|
||||
result, err := a.AccessStorePageNoCookie("newretail/main/shoplist", params)
|
||||
if err == nil && result != nil {
|
||||
err = utils.Map2StructByJson(result, &shopListInfo, true)
|
||||
}
|
||||
return shopListInfo, err
|
||||
}
|
||||
|
||||
func (a *API) GetStoreList2(lng float64, lat float64) (shopListInfo *PageListInfo, err error) {
|
||||
retVal, err := a.GetStoreList(fmt.Sprintf("%.6f", lng), fmt.Sprintf("%.6f", lat))
|
||||
if err == nil {
|
||||
err = utils.Map2StructByJson(retVal, &shopListInfo, true)
|
||||
pageSize := 20
|
||||
pageNo := 1
|
||||
for {
|
||||
retVal, err2 := a.GetStoreList(fmt.Sprintf("%.6f", lng), fmt.Sprintf("%.6f", lat), pageNo, pageSize)
|
||||
if err = err2; err == nil {
|
||||
if shopListInfo == nil {
|
||||
shopListInfo = retVal
|
||||
} else {
|
||||
shopListInfo.ShopList = append(shopListInfo.ShopList, retVal.ShopList...)
|
||||
if len(retVal.ShopList) < pageSize {
|
||||
break
|
||||
}
|
||||
}
|
||||
pageNo++
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
return shopListInfo, err
|
||||
}
|
||||
|
||||
@@ -107,7 +107,7 @@ func TestGetShopHealthByDetail(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStoreList(t *testing.T) {
|
||||
result, err := api.GetStoreList("104.057218", "30.6949")
|
||||
result, err := api.GetStoreList("104.057218", "30.6949", 0, 0)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -115,7 +115,7 @@ func TestGetStoreList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGetStoreList2(t *testing.T) {
|
||||
result, err := api.GetStoreList2(120.074911, 29.306863)
|
||||
result, err := api.GetStoreList2(104.010554, 30.637072)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user