backupAndDelete($table, $where); } } public function backupAndDelete(string $table, array $where): void { $rows = Db::name($table)->where($where)->select()->toArray(); if ($rows) { Db::name('backup_' . $table)->insertAll($rows); Db::name($table)->where($where)->delete(); } } public function restore(string $table, array $where): void { $backupTable = 'backup_' . $table; $rows = Db::name($backupTable)->where($where)->select()->toArray(); if ($rows) { foreach ($rows as &$row) { if (isset($row['del_time'])) unset($row['del_time']); } unset($row); Db::name($table)->insertAll($rows); Db::name($backupTable)->where($where)->delete(); } } public function restoreBatch(array $ops): void { foreach ($ops as [$table, $where]) { $this->restore($table, $where); } } }