LogController.php
14.1 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<?php
namespace App\Admin\Controllers\Auth;
use App\Models\Area\Area;
use App\Admin\Rewrite\Auth\Database\OperationLog;
use Encore\Admin\Controllers\LogController as BaseController;
use Encore\Admin\Grid;
use Illuminate\Support\Str;
class LogController extends BaseController
{
/**
* {@inheritdoc}
*/
protected function title()
{
return trans('admin.operation_log');
}
/**
* @return Grid
*/
protected function grid()
{
$menuModel = config('admin.database.menu_model');
$menu = $menuModel::get()->toArray();
$operations = [];
foreach ($menu as $key => $value) {
if ($value['uri']) {
$operation['url'] = 'admin'.$value['uri'];
if ($value['uri'] == '/') {
$operation['url'] = 'admin';
}
} else {
$operation['url'] = '';
}
$operation['title'] = $value['title'];
$operations[] = $operation;
}
// 增加其他的设置
$grid = new Grid(new OperationLog());
$ignore_path = ['admin/_handle_renderable_', 'admin/user/card','admin/user/password','admin/user/card-reader'];
$grid->model()->whereNotIn('path', $ignore_path)
->where('path', 'NOT LIKE', '%select-options%')
// ->where('path', 'NOT LIKE' ,'%handle-page%')
->where('path', 'NOT LIKE', '%_handle_renderable_%')
->where('path', 'NOT LIKE', '%_handle_action_%')
->orderBy('id', 'DESC');
$grid->column('id', 'ID')->sortable();
$grid->column('user.name', '访问用户');
$grid->path('访问地址')->label('info');
$grid->method_zh('请求方法')->label('primary');
$grid->ip('ip地址')->label('primary');
$grid->show('操作描述')->display(function () use ($operations) {
$path = $this->path;
$method = $this->method;
$input = json_decode($this->input, true);
$operate = '';
if (Str::contains($path, 'area/village/select-options')) {
return '查询 '.Area::VILLAGE_ZH.' options 数据';
} elseif (Str::contains($path, 'area/group/select-options')) {
return '查询 '.Area::GROUP_ZH.' options 数据';
} elseif (Str::contains($path, 'area/building/select-options')) {
return '查询 '.Area::BUILDING_ZH.' options 数据';
} elseif (Str::contains($path, 'area/room/select-options')) {
return '查询 '.Area::ROOM_ZH.' options 数据';
} elseif (Str::contains($path, 'admin/map-data')) {
return '查询 地图 数据';
} elseif (Str::contains($path, 'auth/menu')) {
return '进入 菜单 列表';
} elseif (Str::contains($path, 'map/room')) {
return '地图 查询 房间';
} elseif (Str::contains($path, 'map/data-page')) {
return '地图 地图 数据';
} elseif (Str::contains($path, 'admin/report-locks')) {
return '进入 智能门锁报告 列表';
} elseif (Str::contains($path, 'admin/user/password')) {
return '打开 用户密码 界面';
} elseif (Str::contains($path, 'admin/user/password')) {
return '打开 用户密码 界面';
}
// if ($path == 'admin/area/room/select-options') {
// dump($path);
// }
foreach ($operations as $key => $value) {
if ($value['url']) {
if (Str::startsWith($path, $value['url'])) {
//
if ($path == $value['url']) {
if ($method == 'GET') {
$operate = '进入'.$value['title'] .'列表';
} elseif ($method == 'POST') {
$operate = '新增'.$value['title'];
}
} else {
// 定义操作
$behind = 'ID为<span style="font-weight:bold;font-size:18px;padding:0 3px;">
{id}</span>的<span style="font-weight:bold; padding:0 3px;">'.
$value['title'].
'</span>';
$action = '';
$id = 0;
if (Str::endsWith($path, 'edit')) {
$operate = '进入'.$value['title'] .'编辑页面';
} elseif (Str::endsWith($path, 'create')) {
$operate = '进入'.$value['title'] .'新增页面';
} elseif (Str::endsWith($path, 'chunk-file-upload')) {
return '上传大视频';
} else {
if (strstr($path, 'audit/pass')) {
if ($method == 'PUT') {
$temp = explode('/', $path);
$id =$temp[count($temp)-1];
// $operate = '审核不通过ID为<span class="label label-info">'.$id.'</span>的'.$value['title'];
$action ='<span style="color: green">审核通过</span>';
}
} elseif (strstr($path, 'audit/refusal')) {
if ($method == 'PUT') {
$temp = explode('/', $path);
$id =$temp[count($temp)-1];
// $operate = '审核不通过ID为<span class="label label-info">'.$id.'</span>的'.$value['title'];
$action ='<span style="color:red">审核不通过</span>';
}
} elseif (strstr($path, 'offline')) {
if ($method == 'PUT') {
$temp = explode('/', $path);
$id =$temp[count($temp)-1];
//
$action ='<span style="color:#f39c12">下架</span>';
}
} elseif (strstr($path, 'online')) {
if ($method == 'PUT') {
$temp = explode('/', $path);
$id =$temp[count($temp)-1];
$action ='<span style="color:#398439">上架</span>';
}
} elseif (strstr($path, 'cancelTopping')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/cancelTopping', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#f39c12">取消置顶</span>';
}
} elseif (strstr($path, 'setTopping')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/setTopping', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#398439">置顶</span>';
}
} elseif (strstr($path, 'enable')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/enable', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#398439">启用</span>';
}
} elseif (strstr($path, 'disable')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/disable', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#f39c12">禁用</span>';
}
} elseif (strstr($path, 'restore')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/restore', '', $path));
$id =$temp[count($temp)-1];
$action ='<span class="text text-success">恢复</span>';
}
} elseif (strstr($path, 'drill')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/drill', '', $path));
$id =$temp[count($temp)-1];
$action ='<span class="text text-warning">演习</span>';
}
} elseif (strstr($path, 'notify')) {
if ($method == 'POST') {
$temp = explode('/', str_replace('/notify', '', $path));
$id =$temp[count($temp)-1];
$action ='<span class="text text-success">通知</span>';
}
} elseif (strstr($path, 'update')) {
if ($method == 'PUT') {
$temp = explode('/', str_replace('/update', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#398439">更新</span>';
}
} elseif (strstr($path, 'info')) {
if ($method == 'GET') {
$temp = explode('/', str_replace('/info', '', $path));
$id =$temp[count($temp)-1];
$action ='<span style="color:#398439">查看</span>';
}
} else {
$id = str_replace($value['url'] .'/', '', $path);
// if ($path == 'admin/warnings/16/users') {
// dump($path);dump($value['url']);
// dump($value['title']);
//
// }
if ($method == 'GET') {
$id = str_replace('/edit', '', $id);
$action ='编辑';
if ($path =='admin/auth/login') {
return '<span style="color: green">登录</span>';
} elseif ($path =='admin/auth/logout') {
return '<span style="color:#999">退出登录</span>';
} elseif ($path =='admin/statistics/users') {
return '查看数据面板会员统计图';
} elseif ($path =='admin/statistics/orders') {
return '查看数据面板订单统计图';
} elseif ($path =='admin/statistics/sales') {
return '查看数据面板销售额统计图';
} elseif (strstr($path, 'quotations')) {
return '查看方案的报价单';
}
} elseif ($method == 'DELETE') {
$temp = explode('/', str_replace('/notify', '', $path));
$id =$temp[count($temp)-1];
$action ='<span class="text text-danger">删除</span>';
} elseif ($method == 'PUT') {
$action ='<span style="color:#398439">更新</span>';
}
}
$behind = str_replace('{id}', $id, $behind);
$operate = '<span style="font-weight:bold;padding:0 3px;">'.$action .'</span>'. $behind;
}
}
}
}
}
return $operate;
});
$grid->column('created_at', trans('admin.created_at'));
$grid->actions(function (Grid\Displayers\Actions $actions) {
$actions->disableEdit();
$actions->disableView();
});
$grid->disableCreateButton();
$grid->disableExport();
$grid->disableRowSelector();
$grid->filter(function (Grid\Filter $filter) {
// $userModel = config('admin.database.users_model');
$filter->between('created_at', '操作时间')->date();
// $filter->equal('user_id', 'User')->select($userModel::all()->pluck('name', 'id'));
$filter->equal('method')->select(OperationLog::$methodShows)->placeholder('请求方法');
// $filter->like('path');
// $filter->equal('ip');
//去掉默认的搜索
$filter->disableIdFilter();
});
return $grid;
}
}