Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
H
hdg_user_api
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
杨苏杭
hdg_user_api
Commits
d1e2c132
Commit
d1e2c132
authored
Oct 26, 2018
by
banice
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
附近网点附近站点站点搜索
parent
c331301f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
6 deletions
+136
-6
app/Console/Commands/station/GeoHash.php
+4
-3
app/Http/Controllers/v1/service/NeighbourController.php
+73
-0
app/Http/Controllers/v1/station/NeighbourController.php
+35
-3
app/model/ServiceModel.php
+20
-0
routes/web.php
+4
-0
No files found.
app/Console/Commands/station/GeoHash.php
View file @
d1e2c132
...
...
@@ -9,6 +9,7 @@
namespace
App\Console\Commands\station
;
use
App\model\ServiceModel
;
use
App\model\SiteModel
;
use
Illuminate\Console\Command
;
use
League\Geotools\Coordinate\Coordinate
;
...
...
@@ -27,8 +28,8 @@ class GeoHash extends Command
*/
public
function
handle
()
{
$sites
=
SiteModel
::
all
([
'id'
,
'longitude'
,
'latitude'
])
->
toArray
();
//
$sites = SiteModel::all(['id', 'longitude', 'latitude'])->toArray();
$sites
=
ServiceModel
::
all
([
'id'
,
'longitude'
,
'latitude'
])
->
toArray
();
$geoTools
=
new
Geotools
();
foreach
(
$sites
as
$site
)
{
...
...
@@ -38,7 +39,7 @@ class GeoHash extends Command
$encoded
=
$geoTools
->
geohash
()
->
encode
(
$coorToGeoHash
,
5
);
$geoHashValue
=
$encoded
->
getGeohash
();
DB
::
table
(
's
it
es'
)
->
where
(
'id'
,
$site
[
'id'
])
->
update
([
DB
::
table
(
's
ervic
es'
)
->
where
(
'id'
,
$site
[
'id'
])
->
update
([
'geo_hash'
=>
$geoHashValue
]);
...
...
app/Http/Controllers/v1/service/NeighbourController.php
0 → 100644
View file @
d1e2c132
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/26
* Time: 下午2:25
*/
namespace
App\Http\Controllers\v1\service
;
use
App\Http\Controllers\Controller
;
use
App\model\ServiceModel
;
use
Illuminate\Http\Request
;
use
League\Geotools\Coordinate\Coordinate
;
use
League\Geotools\Geotools
;
use
Validator
;
class
NeighbourController
extends
Controller
{
public
function
get
(
Request
$request
)
{
$validator
=
Validator
::
make
(
$request
->
all
(),
[
'lng'
=>
'required'
,
'lat'
=>
'required'
]);
if
(
$validator
->
fails
())
{
abort
(
400
,
$validator
->
errors
()
->
first
());
}
$geoTools
=
new
Geotools
();
$lng
=
$request
->
get
(
'lng'
);
$lat
=
$request
->
get
(
'lat'
);
$centerPoint
=
new
Coordinate
([
$lat
,
$lng
]);
$encoded
=
$geoTools
->
geohash
()
->
encode
(
$centerPoint
,
5
);
$geoHashValue
=
$encoded
->
getGeohash
();
//比对相同的value
$services
=
ServiceModel
::
where
(
'geo_hash'
,
$geoHashValue
)
->
get
([
'id'
,
'type'
,
'service_time'
,
'address'
,
'longitude'
,
'latitude'
,
'service_phone'
])
->
toArray
();
$neighbourSite
=
[];
foreach
(
$services
as
$service
)
{
$point
=
new
Coordinate
([
$service
[
'latitude'
],
$service
[
'longitude'
]]);
$distance
=
$geoTools
->
distance
()
->
setFrom
(
$centerPoint
)
->
setTo
(
$point
);
$distanceValue
=
$distance
->
flat
();
if
(
$distanceValue
<=
2000
)
{
$tmp
=
$service
;
if
(
blank
(
$service
[
'address'
]))
{
$tmp
[
'address'
]
=
''
;
}
$tmp
[
'distance'
]
=
$distanceValue
;
array_push
(
$neighbourSite
,
$tmp
);
}
}
$serviceCount
=
count
(
$neighbourSite
);
$data
=
[];
$data
[
'service_count'
]
=
$serviceCount
;
if
(
$serviceCount
!==
0
)
{
$data
[
'service'
]
=
$neighbourSite
;
}
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
$data
]);
}
}
\ No newline at end of file
app/Http/Controllers/v1/station/NeighbourController.php
View file @
d1e2c132
...
...
@@ -10,6 +10,7 @@ namespace App\Http\Controllers\v1\station;
use
App\Http\Controllers\Controller
;
use
App\model\DoorModel
;
use
App\model\SiteModel
;
use
Illuminate\Http\Request
;
use
Illuminate\Support\Facades\Log
;
...
...
@@ -21,8 +22,40 @@ use League\Geotools\Coordinate\Ellipsoid;
class
NeighbourController
extends
Controller
{
p
rivate
function
test
(
)
p
ublic
function
siteDetail
(
Request
$request
,
$id
)
{
$validator
=
Validator
::
make
([
'site_id'
=>
$id
],
[
'site_id'
=>
'required|exists:sites,id'
]);
if
(
$validator
->
fails
()
===
true
)
{
abort
(
400
,
$validator
->
errors
()
->
first
());
}
$boxCount
=
DoorModel
::
where
(
'site_id'
,
$id
)
->
count
();
$boxes
=
DoorModel
::
where
(
'site_id'
,
$id
)
->
get
()
->
groupBy
(
'box_id'
)
->
toArray
();
$responseBox
=
[];
foreach
(
$boxes
as
$boxId
=>
$doors
)
{
$tmp
=
[];
$tmp
[
'box_code'
]
=
$doors
[
0
][
'box_code'
];
$tmp
[
'box_id'
]
=
$doors
[
0
][
'box_id'
];
$tmp
[
'door_count'
]
=
count
(
$doors
);
$tmp
[
'door'
]
=
$doors
;
array_push
(
$responseBox
,
$tmp
);
}
return
$this
->
response
->
array
(
$this
->
getResponseCode
()
+
[
'data'
=>
[
'box_code'
=>
$boxCount
,
'box'
=>
$responseBox
]
]);
}
...
...
@@ -45,11 +78,9 @@ class NeighbourController extends Controller
$centerPoint
=
new
Coordinate
([
$lat
,
$lng
]);
$encoded
=
$geoTools
->
geohash
()
->
encode
(
$centerPoint
,
5
);
$geoHashValue
=
$encoded
->
getGeohash
();
//比对相同的value
Log
::
debug
(
$geoHashValue
);
$sites
=
SiteModel
::
where
(
'geo_hash'
,
$geoHashValue
)
->
get
([
'longitude'
,
'latitude'
,
'img'
,
'status'
,
'name'
,
'id'
,
'province'
,
'city'
,
'area'
,
'area_name'
,
'address'
,
'service_time'
])
->
toArray
();
$neighbourSite
=
[];
foreach
(
$sites
as
$site
)
{
$point
=
new
Coordinate
([
$site
[
'latitude'
],
$site
[
'longitude'
]]);
$distance
=
$geoTools
->
distance
()
->
setFrom
(
$centerPoint
)
->
setTo
(
$point
);
...
...
@@ -71,6 +102,7 @@ class NeighbourController extends Controller
$data
=
[];
$data
[
'site_count'
]
=
$sitesCount
;
if
(
$sitesCount
!==
0
)
{
$data
[
'img_domain'
]
=
'.com'
;
//fixme
$data
[
'site'
]
=
$neighbourSite
;
}
...
...
app/model/ServiceModel.php
0 → 100644
View file @
d1e2c132
<?php
/**
* Created by PhpStorm.
* User: banice
* Date: 2018/10/26
* Time: 下午2:23
*/
namespace
App\model
;
use
Illuminate\Database\Eloquent\Model
;
class
ServiceModel
extends
Model
{
protected
$table
=
'services'
;
}
\ No newline at end of file
routes/web.php
View file @
d1e2c132
...
...
@@ -70,6 +70,10 @@ $api->version('v1', ['namespace' => 'App\Http\Controllers\v1', 'prefix' => 'api/
$api
->
get
(
'sites/neighbour'
,
'station\NeighbourController@get'
);
$api
->
get
(
'site{id}'
,
'station\NeighbourController@siteDetail'
);
$api
->
get
(
'service/neighbour'
,
'service\NeighbourController@get'
);
});
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment