$dict) { $parents = UserDict::where('dict_id', $dict) ->select('parent') ->groupBy('parent')->cursor(); foreach ($parents as $key => $parent) { $words = UserDict::where('dict_id', $dict) ->where('parent', $parent->parent) ->select('word') ->groupBy('word')->get(); $wordsList = []; foreach ($words as $word) { $wordsList[$word->word] = 1; } $teams = DhammaTerm::where('word', $parent->parent) ->select(['meaning'])->get(); foreach ($teams as $term) { $wordsList[$term->meaning] = 1; } $this->info("[{$parent->parent}] " . count($words) . " team=" . count($teams)); // 合并 $parent->parent, $words->word, $team->meaning 为一个字符串数组 $combinedArray = []; $combinedArray[] = $parent->parent; foreach ($wordsList as $word => $value) { $combinedArray[] = $word; } // 将 $combinedArray 写入 CSV 文件 fputcsv($fp, $combinedArray); } } // 关闭文件 fclose($fp); $this->info('done'); return 0; } }