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

+53 -19
View File
@@ -9,37 +9,71 @@ use Spatie\SimpleExcel\SimpleExcelReader;
class ImportEvents
{
public static function run(string $filePath): void
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) {
->each(function (LazyCollection $chunk) use ($now, $importmode) {
foreach ($chunk as $row) {
$row = array_values($row);
dd($row);
if ($importmode == 'update') {
/*
0 => 14082828
1 => 1
2 => 12
3 => 1661
4 => 4781
*/
/*
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(
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],
@@ -62,9 +96,9 @@ class ImportEvents
'result_code' => $row[25], // w, d, l
'created_at' => $now,
'updated_at' => $now,
],
['upsert' => true],
]
);
}
}
});
}