61 lines
2.2 KiB
PHP
61 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports\Helper;
|
|
|
|
use App\Models\StatisticFixtures;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\LazyCollection;
|
|
use Spatie\SimpleExcel\SimpleExcelReader;
|
|
|
|
class ImportFixtures
|
|
{
|
|
public static function run(string $filePath, string $importmode): void
|
|
{
|
|
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
|
->getRows()
|
|
->chunk(200)
|
|
->each(function (LazyCollection $chunk) use ($importmode) {
|
|
|
|
foreach ($chunk as $row) {
|
|
|
|
$row = array_values($row);
|
|
|
|
/*
|
|
0 => 1
|
|
1 => 87
|
|
2 => 3614
|
|
3 => 1491
|
|
4 => DateTimeImmutable @1777334400 {#2722 ▶}
|
|
5 => 0.90433699503783
|
|
6 => 1.035168989838
|
|
*/
|
|
|
|
if ($importmode == 'update') {
|
|
StatisticFixtures::updateOrCreate(
|
|
[
|
|
'sport_id' => (int) $row[0],
|
|
'league_id' => (int) $row[1],
|
|
'home_id' => (int) $row[2],
|
|
'away_id' => (int) $row[3],
|
|
'starttime' => Carbon::parse($row[4])->toDateTimeString(),
|
|
],
|
|
['exp_home' => (float) $row[5], 'exp_away' => (float) $row[6]]
|
|
);
|
|
} else {
|
|
StatisticFixtures::insert(
|
|
[
|
|
'sport_id' => (int) $row[0],
|
|
'league_id' => (int) $row[1],
|
|
'home_id' => (int) $row[2],
|
|
'away_id' => (int) $row[3],
|
|
'starttime' => Carbon::parse($row[4])->toDateTimeString(),
|
|
'exp_home' => (float) $row[5],
|
|
'exp_away' => (float) $row[6],
|
|
]
|
|
);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|