Index.php
4.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<?php
namespace app\api\controller;
use app\common\controller\Api;
use app\common\controller\Resource;
use app\common\model\Users;
/**
* 首页接口
*/
class Index extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
/**
* 首页
* @ApiParams (name="lng", type="integer", required=true, description="经度")
* @ApiParams (name="lat", type="integer", required=true, description="纬度")
* @ApiParams (name="radius", type="integer", required=true, description="半径[单位米]")
* @ApiReturn ({
"code":1,
"msg":"返回成功"
"data": [
{
"id": "用户id",
"name": "用户姓名",
"avatar": "用户头像",
"grade": "性别",
"age": "年龄",
"lng": "经度",
"lat": "纬度",
"address": "详细地址",
"createtime": "创建时间",
"updatetime": "更新时间",
"distance": "距离我多远"
},
]
})
*/
public function index()
{
$latitude = $this->request->param('lat');
$longitude = $this->request->param('lng');
$radius = $this->request->param('radius');
$address = new Resource();
$data = $address->getAround($latitude, $longitude, $radius);
//dump($data);
//查询数据库中经纬度符合的数据
$model = new Users();
$res = $model
->where('lng','between',[$data['minLng'],$data['maxLng']])
->where('lng','between',[$data['minLng'],$data['maxLng']])
->select();
foreach ($res as $k => $v){
$res[$k]['avatar'] = cdnurl($v['avatar']);
//计算两地距离
$res[$k]['distance'] = $address->getDistance($longitude,$latitude,$v['lng'],$v['lat']).'米';
}
$this->success('',$res);
}
/**
* @ApiTitle (获取城市列表)
*/
public function getCity(){
$like = db('city')->field('*')->select();
$data = [];
$kone = 0;
foreach ($like as $v) {
if ($v['pid'] == 0) {
$data[$kone] = $v;
$ktwo = 0;
foreach ($like as $v2) {
if ($v2['pid'] == $v['id']) {
$data[$kone]['subclass'][$ktwo] = $v2;
$kthree = 0;
foreach ($like as $v3){
if ($v3['pid'] == $v2['id']){
$data[$kone]['subclass'][$ktwo]['zsubclass'][$kthree] = $v3;
$kthree += 1;
}
}
$ktwo += 1;
}
}
$kone += 1;
}
}
$this->success('返回成功', $data);
}
/**
* 计算距离
* @ApiParams (name="lng1", type="integer", required=true, description="经度1")
* @ApiParams (name="lat1", type="integer", required=true, description="纬度1")
* @ApiParams (name="lng2", type="integer", required=true, description="经度2")
* @ApiParams (name="lat2", type="integer", required=true, description="纬度2")
*/
public function test2()
{
$param = $this->request->param();
$address = new Resource();
$data = $address->getDistance($param['lng1'],$param['lat1'],$param['lng2'],$param['lat2'],1);
$this->success('',$data);
}
/**
* [正方形4个点]
* @ApiParams (name="lng", type="integer", required=true, description="经度")
* @ApiParams (name="lat", type="integer", required=true, description="纬度")
* @ApiParams (name="radius", type="integer", required=true, description="半径[单位千米]")
*/
public function test4()
{
$latitude = $this->request->param('lat');
$longitude = $this->request->param('lng');
$radius = $this->request->param('radius');
$address = new Resource();
$data = $address->returnSquarePoint($longitude,$latitude, $radius);
$this->success('',$data);
}
}