You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
81 lines
2.7 KiB
81 lines
2.7 KiB
<?php
|
|
|
|
namespace App\Exports;
|
|
|
|
use App\Models\AdminMenu;
|
|
use App\Models\AdminOperationLog;
|
|
use App\Models\AdminUsers;
|
|
use Maatwebsite\Excel\Concerns\FromArray;
|
|
use Maatwebsite\Excel\Concerns\WithHeadings;
|
|
|
|
class OperationLogExport implements FromArray, WithHeadings
|
|
{
|
|
public function array(): array
|
|
{
|
|
$data = [];
|
|
$index = 1;
|
|
$columns = [
|
|
'id',
|
|
'user_id',
|
|
'action',
|
|
'description',
|
|
'sub_directory',
|
|
'created_at'
|
|
];
|
|
$actionArr = AdminOperationLog::getActionArr();
|
|
AdminOperationLog::all($columns)->each(
|
|
function ($item) use (&$data, &$index, $actionArr) {
|
|
$username = AdminUsers::getUsername($item['user_id']);
|
|
$item['operation_name'] = $username ?? '';
|
|
$item['action_str'] = $actionArr[$item['action']] ??
|
|
$item['action'];
|
|
$description = __('log.' . $item['description']);
|
|
if (strpos($description, 'log.') === false) {
|
|
$item['description'] = $description;
|
|
}
|
|
$item['main_directory'] = '';
|
|
if ($item['sub_directory']) {
|
|
$item['main_directory']
|
|
= AdminMenu::getLastParentTitle(
|
|
$item['sub_directory']
|
|
);
|
|
$item['sub_directory'] = AdminMenu::getParentTitle(
|
|
$item['sub_directory']
|
|
);
|
|
} else {
|
|
$item['sub_directory'] = '';
|
|
}
|
|
$data[] = [
|
|
'id' => $index,
|
|
'created_at' => $item['created_at'],
|
|
'operation_name' => $item['operation_name'],
|
|
'main_directory' => $item['main_directory'],
|
|
'sub_directory' => $item['sub_directory'],
|
|
'action' => $item['action'],
|
|
'action_str' => $item['action_str'],
|
|
'description' => $item['description'],
|
|
];
|
|
$index += 1;
|
|
}
|
|
);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
public function headings(): array
|
|
{
|
|
return [
|
|
__('exports.global.index'),
|
|
__('exports.operation_log.created_at'),
|
|
__('exports.operation_log.operation_name'),
|
|
__('exports.operation_log.main_directory'),
|
|
__('exports.operation_log.sub_directory'),
|
|
__('exports.operation_log.action'),
|
|
__('exports.operation_log.action_str'),
|
|
__('exports.operation_log.description')
|
|
];
|
|
}
|
|
|
|
}
|
|
|