update import opetion by upload

This commit is contained in:
salam committed 2026-06-03 08:06:31 +02:00
1 parent 37d28eec21
commit 0221ace4d2
15 files changed
+194 -253

No files matched your search

+26 -12
View File
@@ -9,12 +9,12 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportFixtures
{
public static function run(string $filePath): void
public static function run(string $filePath, string $importmode): void
{
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
->getRows()
->chunk(200)
->each(function (LazyCollection $chunk) {
->each(function (LazyCollection $chunk) use ($importmode) {
foreach ($chunk as $row) {
@@ -30,16 +30,30 @@ class ImportFixtures
6 => 1.035168989838
*/
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]]
);
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],
]
);
}
}
});
}