Skip to content

Commit 89f4f81

Browse files
committed
管理员操作写入日志
1 parent b281c64 commit 89f4f81

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

app/Events/userActionEvent.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
class userActionEvent extends Event
1010
{
1111
use SerializesModels;
12-
public $uid,$model,$aid,$type,$content;
12+
public $uid,$adminName,$model,$aid,$type,$content;
1313

1414
/**
1515
* userActionEvent constructor.
@@ -20,7 +20,8 @@ class userActionEvent extends Event
2020
*/
2121
public function __construct(string $model, int $aid, int $type, string $content)
2222
{
23-
$this->uid = auth()->user()->id;
23+
$this->uid = auth('admin')->user()->id;
24+
$this->adminName = auth('admin')->user()->name;
2425
$this->model = $model;
2526
$this->aid = $aid;
2627
$this->type = $type;

app/Http/Controllers/Admin/PermissionController.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ public function index(Request $request, $cid = 0)
4545
$data['recordsFiltered'] = Permission::where('cid', $cid)->where(function ($query) use ($search) {
4646
$query
4747
->where('name', 'LIKE', '%' . $search['value'] . '%')
48-
->orWhere('description', 'like', '%' . $search['value'] . '%');
48+
->orWhere('description', 'like', '%' . $search['value'] . '%')
49+
->orWhere('label', 'like', '%' . $search['value'] . '%');
4950
})->count();
5051
$data['data'] = Permission::where('cid', $cid)->where(function ($query) use ($search) {
5152
$query->where('name', 'LIKE', '%' . $search['value'] . '%')
52-
->orWhere('description', 'like', '%' . $search['value'] . '%');
53+
->orWhere('description', 'like', '%' . $search['value'] . '%')
54+
->orWhere('label', 'like', '%' . $search['value'] . '%');
5355
})
5456
->skip($start)->take($length)
5557
->orderBy($columns[$order[0]['column']]['data'], $order[0]['dir'])

app/Listeners/userActionListener.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Listeners;
44

5+
use Log;
56
use App\Events\userActionEvent;
67
use Illuminate\Queue\InteractsWithQueue;
78
use Illuminate\Contracts\Queue\ShouldQueue;
@@ -22,17 +23,20 @@ public function __construct()
2223
/**
2324
* Handle the event.
2425
*
25-
* @param userActionEvent $event
26+
* @param userActionEvent $event
2627
* @return void
2728
*/
2829
public function handle(userActionEvent $event)
2930
{
30-
$log=new \App\Models\OperatorLog();
31-
$log->uid=$event->uid;
32-
$log->model=$event->model;
33-
$log->aid = $event->aid;
34-
$log->type= $event->type;
35-
$log->content = $event->content;
36-
$log->save();
31+
$str = '管理员:' . $event->adminName . '(id:' . $event->uid . ')' . $event->content;
32+
33+
Log::info($str);
34+
// $log=new \App\Models\OperatorLog();
35+
// $log->uid=$event->uid;
36+
// $log->model=$event->model;
37+
// $log->aid = $event->aid;
38+
// $log->type= $event->type;
39+
// $log->content = $event->content;
40+
// $log->save();
3741
}
3842
}

app/Providers/EventServiceProvider.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ class EventServiceProvider extends ServiceProvider
1313
* @var array
1414
*/
1515
protected $listen = [
16-
'App\Events\SomeEvent' => [
17-
'App\Listeners\EventListener',
16+
'App\Events\permChangeEvent' => [
17+
'App\Listeners\permChangeListener',
18+
],
19+
'App\Events\userActionEvent' => [
20+
'App\Listeners\userActionListener',
1821
],
1922
];
2023

0 commit comments

Comments
 (0)