wip
This commit is contained in:
1 parent
9686d3b173
commit
fb85e4cce0
5 files changed
+67
-37
No files matched your search
@@ -11,42 +11,43 @@ class ImportDetails
|
||||
{
|
||||
public static function run(string $filePath): void
|
||||
{
|
||||
$now = now()->format('Y-m-d H:i:s');
|
||||
StatistikoDetail::query()->update(['last_import' => 0]);
|
||||
|
||||
SimpleExcelReader::create(storage_path('app/public/'.$filePath))
|
||||
->getRows()
|
||||
->chunk(1000)
|
||||
->each(function (LazyCollection $chunk) use ($now) {
|
||||
->each(function (LazyCollection $chunk) {
|
||||
|
||||
$collection = [];
|
||||
foreach ($chunk as $row) {
|
||||
|
||||
$row = array_values($row);
|
||||
|
||||
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,
|
||||
]
|
||||
);
|
||||
}
|
||||
$row['is_active'] = 1;
|
||||
$row['last_import'] = 1;
|
||||
$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('updated_at', '!=', $now)->update(['is_active' => 0, 'ss_team_id' => 0]);
|
||||
|
||||
StatistikoDetail::where('last_import', 0)->update(['is_active' => 0, 'ss_team_id' => 0]);
|
||||
}
|
||||
}
|
||||
@@ -111,6 +111,34 @@ class ImportPlayer
|
||||
$update_array
|
||||
);
|
||||
}
|
||||
|
||||
// $collection = [];
|
||||
// foreach ($chunk as $row) {
|
||||
// $update_array = [];
|
||||
// foreach ($row as $name => $value) {
|
||||
// switch ($name) {
|
||||
// case 'SS_MATCH_ID':
|
||||
// $update_array['match_id'] = (int) $value;
|
||||
// break;
|
||||
// case 'SS_PLAYER_ID':
|
||||
// $update_array['ss_player_id'] = (int) $value;
|
||||
// break;
|
||||
// default:
|
||||
// $name = strtolower($name);
|
||||
// $update_array[$name] = $value;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// $collection[] = $update_array;
|
||||
// }
|
||||
|
||||
// StatistikoPlayer::upsert(
|
||||
// $collection,
|
||||
// uniqueBy: [
|
||||
// 'match_id',
|
||||
// 'ss_player_id',
|
||||
// ],
|
||||
// update: $fieldnames);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user