UpgradeVocabulary.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\UserDict;
  4. use App\Models\WordIndex;
  5. use App\Tools\Tools;
  6. use Illuminate\Console\Command;
  7. class UpgradeVocabulary extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:vocabulary';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = '刷新词汇表完成情况';
  21. /**
  22. * Create a new command instance.
  23. *
  24. * @return void
  25. */
  26. public function __construct()
  27. {
  28. parent::__construct();
  29. }
  30. /**
  31. * Execute the console command.
  32. *
  33. * @return int
  34. */
  35. public function handle()
  36. {
  37. if (Tools::isStop()) {
  38. return 0;
  39. }
  40. $words = UserDict::select('word')->groupBy('word')->cursor();
  41. $count = 0;
  42. foreach ($words as $word) {
  43. $update = WordIndex::where('word', $word->word)->update(['final' => 1]);
  44. if ($update == 1) {
  45. $this->info("{$count}. {$word->word}");
  46. $count++;
  47. }
  48. }
  49. return 0;
  50. }
  51. }