rows = $rows; $this->id = $id; } public function handle(): void { Log::warning('匯入啟動', [ 'model' => "ImportUserChunkJob", 'rows_id' =>$this->id, ]); $now = now(); foreach ($this->rows as $index => $row) { try { $name = $this->normalizeName($row['歌手姓名'] ?? ''); if (empty($name) || User::where('name', $name)->exists()) { continue; } // 準備 song 資料 $toInsert[] = [ 'name' => $name, 'category' => ArtistCategory::tryFrom(trim($row['歌手分類'] ?? '未定義')) ?? ArtistCategory::Unset, 'simplified' => $simplified, 'phonetic_abbr' => $phoneticAbbr, 'pinyin_abbr' => $pinyinAbbr, 'strokes_abbr' => $strokesAbbr, 'enable' =>trim($row['狀態'] ?? 1), 'created_at' => $now, 'updated_at' => $now, ]; } catch (\Throwable $e) { \Log::error("Row {$index} failed: {$e->getMessage()}", [ 'row' => $row, 'trace' => $e->getTraceAsString() ]); } } User::insert($toInsert); } public function normalizeName(?string $str): string { return strtoupper(mb_convert_kana(trim($str ?? ''), 'as')); } }