56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Imports\Helper;
|
|
|
|
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
|
|
{
|
|
StatistikoDetail::query()->update(['last_import' => 'no']);
|
|
|
|
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
|
->getRows()
|
|
->chunk(1000)
|
|
->each(function (LazyCollection $chunk) {
|
|
|
|
$collection = [];
|
|
foreach ($chunk as $row) {
|
|
if ($row['player_name'] != '') {
|
|
$row['is_active'] = 1;
|
|
$row['last_import'] = 'yes';
|
|
$row['birthdate'] = isset($row['birthday']) ? Carbon::parse($row['birthday'])->format('Y-m-d') : '';
|
|
unset($row['birthday']);
|
|
$row['last_update'] = Carbon::parse($row['last_update'])->format('Y-m-d H:i:s');
|
|
$collection[] = $row;
|
|
}
|
|
}
|
|
|
|
StatistikoDetail::upsert(
|
|
$collection,
|
|
uniqueBy: [
|
|
'ss_player_id',
|
|
],
|
|
update: [
|
|
'ss_team_id',
|
|
'player_name',
|
|
'ss_national_team_id',
|
|
'birthdate',
|
|
'height',
|
|
'nationality',
|
|
'position',
|
|
'preferred_foot',
|
|
'last_update',
|
|
'is_active',
|
|
'last_import',
|
|
]);
|
|
});
|
|
|
|
StatistikoDetail::where('last_import', 'no')->update(['is_active' => 0, 'ss_team_id' => 0]);
|
|
}
|
|
}
|