68 lines
2.3 KiB
PHP
68 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports\Helper;
|
|
|
|
use App\Actions\PlayerPerSeason;
|
|
use App\Models\StatistikoDetail;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\LazyCollection;
|
|
use Spatie\SimpleExcel\SimpleExcelReader;
|
|
|
|
class ImportDetails
|
|
{
|
|
public static function run(string $filePath): 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) {
|
|
|
|
foreach ($chunk as $row) {
|
|
|
|
$row = array_values($row);
|
|
|
|
// ss_player_id
|
|
// ss_team_id
|
|
// tx_team_id
|
|
// player_name
|
|
// ss_national_team_id
|
|
// birthdate
|
|
// height
|
|
// nationality
|
|
// position
|
|
// preferred_foot
|
|
// last_update
|
|
|
|
if ($row[1] != '') {
|
|
StatistikoDetail::updateOrCreate(
|
|
[
|
|
'ss_player_id' => (int) $row[0],
|
|
],
|
|
[
|
|
'ss_team_id' => (int) $row[1],
|
|
'player_name' => $row[2],
|
|
'ss_national_team_id' => (int) $row[3],
|
|
'birthdate' => Carbon::parse($row[4])->format('Y-m-d'),
|
|
'height' => (int) $row[5],
|
|
'nationality' => $row[6],
|
|
'position' => $row[7],
|
|
'preferred_foot' => $row[8],
|
|
'last_update' => Carbon::parse($row[9])->format('Y-m-d H:i:s'),
|
|
'is_active' => 1,
|
|
'created_at' => $now,
|
|
'updated_at' => $now,
|
|
]
|
|
);
|
|
}
|
|
}
|
|
});
|
|
|
|
StatistikoDetail::where('updated_at', '!=', $now)->update(['is_active' => 0]);
|
|
|
|
/**update statistic player tabel */
|
|
PlayerPerSeason::run();
|
|
}
|
|
}
|