Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
tl_estate
Project
Project
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujun
tl_estate
Commits
ecda759e
Commit
ecda759e
authored
Sep 17, 2019
by
hujun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增定位
parent
ec25f110
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
141 additions
and
1 deletion
+141
-1
Location.php
application/api_broker/controller/Location.php
+68
-0
PositionService.php
application/index/service/PositionService.php
+23
-1
ALocationListModel.php
application/model/ALocationListModel.php
+49
-0
route.php
application/route.php
+1
-0
No files found.
application/api_broker/controller/Location.php
View file @
ecda759e
...
@@ -3,7 +3,10 @@
...
@@ -3,7 +3,10 @@
namespace
app\api_broker\controller
;
namespace
app\api_broker\controller
;
use
app\api_broker\extend\Basic
;
use
app\api_broker\extend\Basic
;
use
app\api_broker\service\RedisCacheService
;
use
app\extra\RedisExt
;
use
app\extra\RedisExt
;
use
app\index\service\PositionService
;
use
app\model\ALocationListModel
;
use
think\Request
;
use
think\Request
;
/**
/**
...
@@ -50,4 +53,68 @@ class Location extends Basic
...
@@ -50,4 +53,68 @@ class Location extends Basic
return
$this
->
response
(
"200"
,
"success"
,
[]);
return
$this
->
response
(
"200"
,
"success"
,
[]);
}
}
/**
* 新增定位
*
* @return \think\Response
*/
public
function
addLocation
()
{
$code
=
101
;
$params
=
&
$this
->
params
;
if
(
!
isset
(
$params
[
'longitude'
])
||
!
isset
(
$params
[
'latitude'
])
||
!
isset
(
$params
[
'source'
])
)
{
return
$this
->
response
(
$code
,
'参数错误'
);
}
if
(
$params
[
'agent_id'
]
!=
$this
->
agentId
)
{
return
$this
->
response
(
$code
,
'账号异常'
);
}
$m_location
=
new
ALocationListModel
();
$position_service
=
new
PositionService
();
$s_redis
=
new
RedisCacheService
();
$where
[
'agent_id'
]
=
$params
[
'agent_id'
];
$data
=
$m_location
->
findData
(
'longitude,latitude'
,
$where
,
'id desc'
);
if
(
$params
[
'longitude'
]
.
$params
[
'latitude'
]
==
$data
[
'longitude'
]
.
$data
[
'latitude'
])
{
return
$this
->
response
(
101
,
'经纬度重复'
);
}
if
(
!
empty
(
$data
))
{
$is_
=
$position_service
->
checkDistance
(
$params
[
'latitude'
],
$params
[
'longitude'
],
$data
[
'latitude'
],
$data
[
'longitude'
],
500
);
if
(
$is_
)
{
return
$this
->
response
(
200
,
'距离没有超过500米'
);
}
}
$agent_data
=
$s_redis
->
getRedisCache
(
2
,
$params
[
'agent_id'
]);
if
(
empty
(
$params
[
'source'
]))
{
$save_data
[
"source"
]
=
0
;
$save_data
[
"source_id"
]
=
0
;
}
else
{
$save_data
[
"source"
]
=
$params
[
'source'
];
$save_data
[
"source_id"
]
=
$params
[
'source_id'
];
}
$save_data
[
"agent_id"
]
=
$params
[
'agent_id'
];
$save_data
[
"store_id"
]
=
$agent_data
[
'store_id'
];
$save_data
[
"district_id"
]
=
$agent_data
[
'district_id'
];
$save_data
[
"location_time"
]
=
date
(
'Y-m-d H:i:s'
);
$save_data
[
"longitude"
]
=
$params
[
'longitude'
];
$save_data
[
"latitude"
]
=
$params
[
'latitude'
];
$num
=
$m_location
->
insertData
(
$data
);
if
(
$num
>
0
)
{
$code
=
200
;
$msg
=
'操作完成'
;
}
else
{
$msg
=
'插入定位数据失败'
;
}
return
$this
->
response
(
$code
,
$msg
);
}
}
}
\ No newline at end of file
application/index/service/PositionService.php
View file @
ecda759e
...
@@ -20,7 +20,7 @@ class PositionService
...
@@ -20,7 +20,7 @@ class PositionService
* @param $end_position //终点(举个栗子:'31.079655,121.51713')
* @param $end_position //终点(举个栗子:'31.079655,121.51713')
* @return string 返回数值单位 '米'
* @return string 返回数值单位 '米'
*/
*/
function
getPositionDistance
(
$first_position
,
$end_position
)
public
function
getPositionDistance
(
$first_position
,
$end_position
)
{
{
if
(
!
$first_position
or
!
$end_position
){
if
(
!
$first_position
or
!
$end_position
){
return
''
;
return
''
;
...
@@ -41,5 +41,26 @@ class PositionService
...
@@ -41,5 +41,26 @@ class PositionService
}
}
}
}
/**
* @param $a_latitude
* @param $a_longitude
* @param $b_latitude
* @param $b_longitude
* @param int $limit_distance
* @return bool
*/
public
function
checkDistance
(
$a_latitude
,
$a_longitude
,
$b_latitude
,
$b_longitude
,
$limit_distance
=
0
)
{
$first_position
=
$a_latitude
.
','
.
$a_longitude
;
$end_position
=
$b_latitude
.
','
.
$b_longitude
;
$distance
=
$this
->
getPositionDistance
(
$first_position
,
$end_position
);
if
(
$distance
<=
$limit_distance
)
{
$result
=
true
;
}
else
{
$result
=
false
;
}
return
$result
;
}
}
}
\ No newline at end of file
application/model/ALocationListModel.php
0 → 100644
View file @
ecda759e
<?php
namespace
app\model
;
use
think\Db
;
use
think\Model
;
/**
* Created by PhpStorm.
* User : zhuwei
* Date : 2018-06-14
* Time : 14:26:58
* Intro:
*/
class
ALocationListModel
extends
Model
{
protected
$table
=
"a_location_list"
;
private
$db_
;
function
__construct
(
$data
=
[])
{
parent
::
__construct
(
$data
);
$this
->
db_
=
Db
::
name
(
$this
->
table
);
}
/**
* @param $data
* @return int|string
*/
public
function
insertData
(
$data
)
{
$data
[
'create_time'
]
=
date
(
"Y-m-d H:i:s"
,
time
());
return
$this
->
db_
->
insert
(
$data
);
}
/**
* @param $field
* @param $where
* @param $order
* @return array|false|\PDOStatement|string|Model
*/
public
function
findData
(
$field
,
$where
,
$order
=
'id asc'
)
{
return
$this
->
db_
->
field
(
$field
)
->
where
(
$where
)
->
order
(
$order
)
->
find
();
}
}
\ No newline at end of file
application/route.php
View file @
ecda759e
...
@@ -1003,6 +1003,7 @@ Route::group('broker', [
...
@@ -1003,6 +1003,7 @@ Route::group('broker', [
'saveSiteCity'
=>
[
'api_broker/Location/saveSiteCity'
,
[
'method'
=>
'POST|GET'
]],
//保存默认城市选择
'saveSiteCity'
=>
[
'api_broker/Location/saveSiteCity'
,
[
'method'
=>
'POST|GET'
]],
//保存默认城市选择
'addLocation'
=>
[
'api_broker/Location/addLocation'
,
[
'method'
=>
'POST'
]],
//新增定位
'bargainMain'
=>
[
'api_broker/Bargain/bargainList'
,
[
'method'
=>
'POST|GET'
]],
'bargainMain'
=>
[
'api_broker/Bargain/bargainList'
,
[
'method'
=>
'POST|GET'
]],
'bargainMainV2'
=>
[
'api_broker/Bargain/bargainListV2'
,
[
'method'
=>
'POST|GET'
]],
'bargainMainV2'
=>
[
'api_broker/Bargain/bargainListV2'
,
[
'method'
=>
'POST|GET'
]],
'bargainListSearchBargainId'
=>
[
'api_broker/Bargain/bargainListSearchBargainId'
,
[
'method'
=>
'POST|GET'
]],
'bargainListSearchBargainId'
=>
[
'api_broker/Bargain/bargainListSearchBargainId'
,
[
'method'
=>
'POST|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