UpgradePageNumber.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace App\Console\Commands;
  3. use App\Models\PageNumber;
  4. use App\Models\WbwTemplate;
  5. use App\Tools\Tools;
  6. use Illuminate\Console\Command;
  7. class UpgradePageNumber extends Command
  8. {
  9. /**
  10. * The name and signature of the console command.
  11. *
  12. * @var string
  13. */
  14. protected $signature = 'upgrade:page.number';
  15. /**
  16. * The console command description.
  17. *
  18. * @var string
  19. */
  20. protected $description = 'Command 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. $table = WbwTemplate::where('type', '.ctl.')->orderBy('book')->orderBy('paragraph')->cursor();
  41. $pageHead = ['M', 'P', 'T', 'V', 'O'];
  42. $bar = $this->output->createProgressBar(WbwTemplate::where('type', '.ctl.')->count());
  43. foreach ($table as $key => $value) {
  44. $type = substr($value->word, 0, 1);
  45. if (in_array($type, $pageHead)) {
  46. $arrPage = explode('.', $value->word);
  47. if (count($arrPage) !== 2) {
  48. continue;
  49. }
  50. $page = PageNumber::firstOrNew(
  51. [
  52. 'book' => $value->book,
  53. 'paragraph' => $value->paragraph,
  54. 'wid' => $value->wid,
  55. ],
  56. [
  57. 'type' => $type,
  58. 'volume' => (int) substr($arrPage[0], 1),
  59. 'page' => (int) $arrPage[1],
  60. 'pcd_book_id' => $value->pcd_book_id,
  61. ]
  62. );
  63. $page->save();
  64. }
  65. $bar->advance();
  66. }
  67. $bar->finish();
  68. return 0;
  69. }
  70. }