error('no channel'); return 1; } $relations = Relation::get(); $result = []; foreach ($relations as $key => $relation) { $from = json_decode($relation->from, true); $words = []; if (isset($from['spell']) && ! empty($from['spell'])) { $words[] = $from['spell']; } if (isset($from['case']) && count($from['case']) > 0) { $words = array_merge($words, $from['case']); } if (count($words) === 0) { continue; } $word = implode('.', $words); if (! isset($result[$word])) { $result[$word] = []; } $result[$word][] = $relation; } foreach ($result as $key => $rows) { $this->info('## '.$key); $caseLocal = DhammaTerm::where('channal', $channelId) ->where('word', $key) ->value('meaning'); if ($caseLocal) { $title = "**[[{$key}]]** 用法表\n\n"; } else { $title = "**{$key}** 用法表\n\n"; } $relations = []; foreach ($rows as $row) { if (! isset($relations[$row['name']])) { $relations[$row['name']] = []; $local = DhammaTerm::where('channal', $channelId) ->where('word', $row['name']) ->first(); if ($local) { $relations[$row['name']]['meaning'] = $local->meaning; $relations[$row['name']]['note'] = $local->note; } else { $relations[$row['name']]['meaning'] = ''; $relations[$row['name']]['note'] = ''; } $relations[$row['name']]['to'] = []; } $relations[$row['name']]['to'][] = $row['to']; } $table = "|名称|解释|\n"; $table .= "| -- | -- |\n"; foreach ($relations as $relation => $value) { $table .= "| [[{$relation}]] | ".$value['note']." |\n"; } $table .= "\n\n"; echo $title.$table; // 更新字典 $newWord = $key.'.relations'; $new = DhammaTerm::firstOrNew([ 'channal' => $channelId, 'word' => $newWord, ], [ 'id' => app('snowflake')->id(), 'guid' => Str::uuid(), 'create_time' => time() * 1000, ]); if (empty($caseLocal)) { $caseLocal = $key; } $owner = ChannelApi::getById($channelId); if (! $owner) { $this->error('channel id error '.$channelId); continue; } $new->word_en = strtolower($newWord); $new->meaning = $caseLocal.'用法表'; $new->note = $table; $new->language = $lang; $new->editor_id = 1; $new->owner = $owner['studio_id']; $new->modify_time = time() * 1000; $new->save(); } return 0; } }