UpgradePageNumber.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use App\Models\WbwTemplate;
  5. use App\Models\PageNumber;
  6. class UpgradePageNumber extends Command
  7. {
  8. /**
  9. * The name and signature of the console command.
  10. *
  11. * @var string
  12. */
  13. protected $signature = 'upgrade:page.number';
  14. /**
  15. * The console command description.
  16. *
  17. * @var string
  18. */
  19. protected $description = 'Command description';
  20. /**
  21. * Create a new command instance.
  22. *
  23. * @return void
  24. */
  25. public function __construct()
  26. {
  27. parent::__construct();
  28. }
  29. /**
  30. * Execute the console command.
  31. *
  32. * @return int
  33. */
  34. public function handle()
  35. {
  36. if(\App\Tools\Tools::isStop()){
  37. return 0;
  38. }
  39. $table = WbwTemplate::where('type','.ctl.')->orderBy('book')->orderBy('paragraph')->cursor();
  40. $pageHead = ['M','P','T','V','O'];
  41. $bar = $this->output->createProgressBar(WbwTemplate::where('type','.ctl.')->count());
  42. foreach ($table as $key => $value) {
  43. $type = substr($value->word,0,1);
  44. if(in_array($type,$pageHead)){
  45. $arrPage = explode('.',$value->word);
  46. if(count($arrPage)!==2){
  47. continue;
  48. }
  49. $page = PageNumber::firstOrNew(
  50. [
  51. 'book'=>$value->book,
  52. 'paragraph'=>$value->paragraph,
  53. 'wid'=>$value->wid,
  54. ],
  55. [
  56. 'type'=>$type,
  57. 'volume'=>(int)substr($arrPage[0],1),
  58. 'page'=>(int)$arrPage[1],
  59. 'pcd_book_id'=>$value->pcd_book_id,
  60. ]
  61. );
  62. $page->save();
  63. }
  64. $bar->advance();
  65. }
  66. $bar->finish();
  67. return 0;
  68. }
  69. }