TransPutJobs.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Console\Commands\Transfer;
  3. use App\Models\Jobfair\JobfairPutJob;
  4. use App\Models\Jobfair\JobfairJob;
  5. use Illuminate\Console\Command;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Log;
  8. class TransPutJobs extends Command
  9. {
  10. /**
  11. * The name and signature of the console command.
  12. *
  13. * @var string
  14. */
  15. protected $signature = 'aix:transfer-put-jobs';
  16. /**
  17. * The console command description.
  18. *
  19. * @var string
  20. */
  21. protected $description = '舟山旧数据招聘会职位修改';
  22. /**
  23. * Create a new command instance.
  24. *
  25. * @return void
  26. */
  27. public function __construct()
  28. {
  29. parent::__construct();
  30. }
  31. /**
  32. * Execute the console command.
  33. *
  34. * @return mixed
  35. */
  36. public function handle()
  37. {
  38. $this->info("开始更新招聘会职位数据...");
  39. $total = JobfairPutJob::withTrashed()->get()->count();
  40. $bar=$this->output->createProgressBar($total);
  41. JobfairPutJob::withTrashed()->orderBy('id', 'asc')->chunk(1000, function ($jobs) use ($bar) {
  42. foreach ($jobs as $job) {
  43. $jobfair = JobfairJob::where(['company_id'=>$job->company_id,'jobs_name'=>$job->jobs_name])->first();
  44. if($jobfair){
  45. $job->job_id=$jobfair->id;
  46. $job->save();
  47. }else{
  48. Log::info($job->id.'_'.$job->company_id.'_'.$job->jobs_name);
  49. }
  50. }
  51. $bar->advance(1000);
  52. });
  53. $bar->finish();
  54. $this->line(" 完成!");
  55. $this->info("更新招聘会职位职位成功.");
  56. }
  57. }