MapsController.php
5.4 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
/**
+-----------------------------------------------------------------------------------------------------------------------
* 管理端控制层: 卫星地图 控制类
+-----------------------------------------------------------------------------------------------------------------------
*
* PHP version 7
*
* @category App\Admin\Controllers
* @package App\Admin\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2021年6月15日16:18:26
* @copyright 2020-2021 Richer (http://www.pwyld.com/)
* @license http://www.pwyld.com/ License
* @link http://www.pwyld.com/
*/
namespace App\Admin\Controllers;
use App\Models\Area\Village;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
/**
* Class MapsController
*
* @category App\Admin\Controllers
* @package App\Admin\Controllers
* @author Richer <yangzi1028@163.com>
* @date 2021年6月15日16:18:26
* @copyright 2020-2021 Richer (http://www.pwyld.com/)
* @license http://www.pwyld.com/ License
* @link http://www.pwyld.com/
*/
class MapsController extends BaseController
{
public function index(Content $content)
{
// 获取社区、村
$villages = Village::where('status', config('constants.STATUS_OK'))->get(['id', 'title']);//->pluck('id', 'title');
// $villages = Area::where('level', Area::LEVEL_VILLAGE)->get(['id', 'title']);//->pluck('id', 'title');
return $content
// ->title('Dashboard')
// ->description('Description...')
// ->row(Dashboard::title())
->row(function (Row $row) use ($villages) {
$row->column(12, function (Column $column) use ($villages) {
$column->append(view('admin::map.index', compact('villages')));
});
});
}
public function simple(Content $content)
{
return view('admin::map.simple-map');
}
/**
* 根据查询条件获取数据,并渲染到地图上面
*
* @return \Illuminate\Http\JsonResponse
*/
public function getData()
{
// 获取楼栋的信息
$village = request('village');
$group = request('group');
// $building = request('building');
$query = Building::where('status', config('constants.STATUS_OK'));
// $query = Area::where('level', Area::LEVEL_BUILDING);
if ($village) {
$query->where('village_id', $village);
// $query->where('path', 'like', ','.$village.',%');
}
if ($group) {
$query->where('group_id', $group);
// $query->where('path', 'like', '%,'.$group.',%');
}
$building = $query->get(['id','village_id','group_id','title','latitude','longitude','address']);
// $building = $query->get(['id','title','longitude','latitude','level','path']);
return response()->json(
[
'status' => 1,
'msg' => 'success',
'data' => $building->toArray(),
]
);
}
/**
* 根据查询条件获取数据,并渲染到地图上面
*
* @return \Illuminate\Http\JsonResponse
*/
public function getDataByPage()
{
// 获取楼栋的信息
$list = Building::where('status', config('constants.STATUS_OK'))
->when(
$village = request('village'),
function ($query) use ($village) {
$query->where('village_id', $village);
}
)->when(
$group = request('group'),
function ($query) use ($group) {
$query->where('group_id', $group);
}
)
->when(
$keyword = request('keyword'),
function ($query) use ($keyword) {
$query->where(function ($query) use ($keyword) {
$query->where('title', 'like', '%'.$keyword.'%')->orWhere('address', 'like', '%'.$keyword.'%');
});
}
)->paginate(request('per_page', 15));
return response()->json(
[
'code' => 0,
'status' => 1,
'msg' => 'success',
'data' => $list,
]
);
}
public function room()
{
$building = Building::with(['village','group','landlordRoom' => function ($query) {
$query->with(['roomable' => function ($query) {
$query->with(['user']);
}]);
},'rooms' => function ($query) {
$query->with(['tenantRooms' => function ($query) {
$query->with(['roomable' => function ($query) {
$query->with(['user']);
}]);
}]);
}])->find(request('room_id'));
// dd($building->toArray());
return view('admin::map.room', compact('building'));
dd($building->toArray());
$building = Building::with(['village','group','landlord' => function ($query) {
$query->with(['user']);
},'tenants' => function ($query) {
$query->with(['user', 'room']);
},'rooms' => function ($query) {
$query->with(['tenants']);
}])->withCount(['tenants'])->find(request('room_id'));
dd($building->toArray());
return view('admin::map.room', compact('building'));
}
}