本例中 是用来记录后台的操作日志
/**
* @Date: 2023/3/18
* @Author: WasonCheung
* 操作日志记录
*/
class AdminOperationLogger
{
/**
* @var AdminLogEntity[]
*/
public static array $logs = [];
public static function addRecord(AdminLogEntity $adminLogEntity): void
{
self::$logs[] = $adminLogEntity;
}
#[RequestCompletion]
public static function save(): void
{
foreach (self::$logs as $adminLogEntity) {
$logs[] = $adminLogEntity->toArray(true);
}
if (isset($logs)) {
AdminLogModel::saveAll($logs);
}
}
}