Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
goods
Project
Project
Details
Activity
Releases
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
bp
goods
Commits
9eca48be
Commit
9eca48be
authored
Aug 11, 2021
by
suntengda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update 自提点列表支持按经纬度距离排序
parent
9f3e8549
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
1 deletion
+33
-1
TakePlaceService.php
application/services/marketing/TakePlaceService.php
+33
-1
No files found.
application/services/marketing/TakePlaceService.php
View file @
9eca48be
...
...
@@ -7,6 +7,7 @@ use Api\PhpUtils\Http\Request;
use
App\Models\marketing\mysql\MarketingTakePlace
;
use
App\Models\marketing\mysql\TakePlace
;
use
App\Exception\custom\MarketingException
;
use
Api\PhpUtils\Common\Geo
;
class
TakePlaceService
{
...
...
@@ -113,6 +114,8 @@ class TakePlaceService
{
$marketingId
=
$params
[
'marketing_id'
];
$keywords
=
$params
[
'keywords'
]
??
''
;
$longitude
=
$params
[
'longitude'
]
??
''
;
$latitude
=
$params
[
'latitude'
]
??
''
;
$page
=
$params
[
'page'
]
??
1
;
$limit
=
$params
[
'limit'
]
??
20
;
...
...
@@ -139,7 +142,8 @@ class TakePlaceService
//获取自提点信息
$makePlaceIds
=
array_column
(
$relations
,
'take_place_id'
);
$takePlaceWhere
=
[
'take_place_id'
=>
$makePlaceIds
];
$res
[
'list'
]
=
TakePlace
::
select
(
'*'
,
$takePlaceWhere
);
//本页按距离返回列表
$res
[
'list'
]
=
self
::
sortByDistance
(
$latitude
,
$longitude
,
TakePlace
::
select
(
'*'
,
$takePlaceWhere
));
unset
(
$where
[
'ORDER'
],
$where
[
'LIMIT'
]);
$res
[
'total'
]
=
MarketingTakePlace
::
count
(
'*'
,
$where
);
$res
[
'total_page'
]
=
ceil
(
$res
[
'total'
]
/
$limit
);
...
...
@@ -147,4 +151,32 @@ class TakePlaceService
return
$res
;
}
/**
* 根据经纬度按距离排序
* @param $lat
* @param $lng
* @param $list
* @return array
*/
private
static
function
sortByDistance
(
$lat
,
$lng
,
$list
)
{
//未传经纬度
if
(
empty
(
$lat
)
||
empty
(
$lng
))
{
return
$list
;
}
//按距离返回自提点列表
if
(
!
empty
(
$list
)
&&
is_array
(
$list
))
{
foreach
(
$list
as
&
$item
)
{
if
(
$item
[
'longitude'
]
&&
$item
[
'latitude'
])
{
$item
[
'distance'
]
=
Geo
::
geoDistance
(
$lat
,
$lng
,
$item
[
'longitude'
],
$item
[
'latitude'
],
true
);
}
else
{
$item
[
'distance'
]
=
''
;
}
}
unset
(
$item
);
return
$list
;
}
}
}
\ No newline at end of file
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