Browse Source

系统日志导出3

master
wanghongjun 2 days ago
parent
commit
f56644223b
  1. 27
      app/Exports/OperationLogExport.php
  2. 2
      app/Models/AdminMenu.php

27
app/Exports/OperationLogExport.php

@ -23,16 +23,23 @@ class OperationLogExport implements FromArray, WithHeadings
'created_at' 'created_at'
]; ];
$actionArr = AdminOperationLog::getActionArr(); $actionArr = AdminOperationLog::getActionArr();
AdminOperationLog::all($columns)->each( AdminOperationLog::query()->orderBy('created_at', 'desc')->select(
$columns
)->take(1)->each(
function ($item) use (&$data, &$index, $actionArr) { function ($item) use (&$data, &$index, $actionArr) {
if ($item['user_id']) {
$username = AdminUsers::getUsername($item['user_id']); $username = AdminUsers::getUsername($item['user_id']);
$item['operation_name'] = $username ?? ''; $item['operation_name'] = $username ?? '';
$item['action_str'] = $actionArr[$item['action']] ?? }
$item['action']; if (isset($actionArr[$item['action']])) {
$item['action_str'] = $actionArr[$item['action']];
}
if ($item['description']) {
$description = __('log.' . $item['description']); $description = __('log.' . $item['description']);
if (strpos($description, 'log.') === false) { if (strpos($description, 'log.') === false) {
$item['description'] = $description; $item['description'] = $description;
} }
}
$item['main_directory'] = ''; $item['main_directory'] = '';
if ($item['sub_directory']) { if ($item['sub_directory']) {
$item['main_directory'] $item['main_directory']
@ -47,13 +54,13 @@ class OperationLogExport implements FromArray, WithHeadings
} }
$data[] = [ $data[] = [
'id' => $index, 'id' => $index,
'created_at' => $item['created_at'], 'created_at' => $item['created_at'] ?? '',
'operation_name' => $item['operation_name'], 'operation_name' => $item['operation_name'] ?? '',
'main_directory' => $item['main_directory'], 'main_directory' => $item['main_directory'] ?? '',
'sub_directory' => $item['sub_directory'], 'sub_directory' => $item['sub_directory'] ?? '',
'action' => $item['action'], 'action' => $item['action'] ?? '',
'action_str' => $item['action_str'], 'action_str' => $item['action_str'] ?? '',
'description' => $item['description'], 'description' => $item['description'] ?? '',
]; ];
$index += 1; $index += 1;
} }

2
app/Models/AdminMenu.php

@ -68,7 +68,9 @@ class AdminMenu extends Model
public static function getLastParentTitle($parent_id): string public static function getLastParentTitle($parent_id): string
{ {
$last_parent_id = self::query()->where('id', $parent_id)->whereNull('deleted_at')->value('parent_id'); $last_parent_id = self::query()->where('id', $parent_id)->whereNull('deleted_at')->value('parent_id');
if ($last_parent_id) {
$title = self::getTreeTitle($last_parent_id); $title = self::getTreeTitle($last_parent_id);
}
return empty($title) ? '' : __('menu.' . $title); return empty($title) ? '' : __('menu.' . $title);
} }

Loading…
Cancel
Save