Files
nuhodds_fi4/app/Filament/Imports/Helper/ImportEvents.php
T
2026-06-03 08:06:31 +02:00

106 lines
4.5 KiB
PHP

<?php
namespace App\Filament\Imports\Helper;
use App\Models\StatistikoEvent;
use Illuminate\Support\Carbon;
use Illuminate\Support\LazyCollection;
use Spatie\SimpleExcel\SimpleExcelReader;
class ImportEvents
{
public static function run(string $filePath, string $importmode): void
{
$now = now()->format('Y-m-d H:i:s');
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
->getRows()
->chunk(1000)
->each(function (LazyCollection $chunk) use ($now, $importmode) {
foreach ($chunk as $row) {
$row = array_values($row);
if ($importmode == 'update') {
/*
0 => 14082828
1 => 1
2 => 12
3 => 1661
4 => 4781
*/
StatistikoEvent::where('match_id', $row[0])
->where('sport_id', $row[1])
->where('league_id', $row[2])
->where('home_id', $row[3])
->where('away_id', $row[4])
->where('starttime', Carbon::parse($row[5])->toIso8601String())
->update(
[
'season' => $row[6],
'gls_h' => $row[7],
'gls_a' => $row[8],
'crn_h' => $row[9],
'crn_a' => $row[10],
'fls_h' => $row[11],
'fls_a' => $row[12],
'ofs_h' => $row[13],
'ofs_a' => $row[14],
'snt_h' => $row[15],
'snt_a' => $row[16],
'tsh_h' => $row[17],
'tsh_a' => $row[18],
'crd_h' => $row[19],
'crd_a' => $row[20],
'exp_home' => $row[21],
'exp_away' => $row[22],
'exp_handicap' => $row[23],
'exp_total' => $row[24],
'result_code' => $row[25], // w, d, l
'created_at' => $now,
'updated_at' => $now,
],
['upsert' => true],
);
} else {
StatistikoEvent::import(
[
'match_id', $row[0],
'sport_id', $row[1],
'league_id', $row[2],
'home_id', $row[3],
'away_id', $row[4],
'starttime', Carbon::parse($row[5])->toIso8601String(),
'season' => $row[6],
'gls_h' => $row[7],
'gls_a' => $row[8],
'crn_h' => $row[9],
'crn_a' => $row[10],
'fls_h' => $row[11],
'fls_a' => $row[12],
'ofs_h' => $row[13],
'ofs_a' => $row[14],
'snt_h' => $row[15],
'snt_a' => $row[16],
'tsh_h' => $row[17],
'tsh_a' => $row[18],
'crd_h' => $row[19],
'crd_a' => $row[20],
'exp_home' => $row[21],
'exp_away' => $row[22],
'exp_handicap' => $row[23],
'exp_total' => $row[24],
'result_code' => $row[25], // w, d, l
'created_at' => $now,
'updated_at' => $now,
]
);
}
}
});
}
}