wip fix
This commit is contained in:
1 parent
9bcd4432c6
commit
6f92f9e1d5
1209 files changed
+220940
No files matched your search
@@ -0,0 +1,55 @@
|
||||
<?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]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user