TransferOther.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <?php
  2. namespace App\Console\Commands\Transfer;
  3. use App\Transfer\Company;
  4. use Illuminate\Console\Command;
  5. class TransferOther extends Command
  6. {
  7. /**
  8. * The name and signature of the console command.
  9. *
  10. * @var string
  11. */
  12. protected $signature = 'aix:transfer-other';
  13. /**
  14. * The console command description.
  15. *
  16. * @var string
  17. */
  18. protected $description = '转移旧系统企业数据';
  19. /**
  20. * Create a new command instance.
  21. *
  22. * @return void
  23. */
  24. public function __construct()
  25. {
  26. parent::__construct();
  27. }
  28. /**
  29. * Execute the console command.
  30. *
  31. * @return mixed
  32. */
  33. public function handle()
  34. {
  35. $this->info("清除企业数据表:companys");
  36. //DB::table('companys')->delete();
  37. $this->info("清除企业数据表:companyImg");
  38. //DB::table('companyImg')->delete();
  39. ///其它需要清除的表
  40. $this->info("开始转移数据...");
  41. $total = Company::where(['utype' => 1])->count();
  42. $bar=$this->output->createProgressBar($total);
  43. Company::where(['utype' => 1])->orderBy('uid', 'asc')->chunk(500, function ($companys) use ($bar) {
  44. $company_array=[];
  45. $company_job_array=[];
  46. $company_img_array=[];
  47. /** @var Company $company */
  48. foreach ($companys as $company) {
  49. //处理企业表
  50. $this->handleCompany($company, $company_array);
  51. //处理职业
  52. $this->handleCompanyJob($company->jobs, $company_job_array);
  53. //处理套餐
  54. //处理企业图片...
  55. }
  56. //批量插入数据;
  57. $bar->advance(500);
  58. });
  59. $bar->finish();
  60. $this->line(" 完成!");
  61. $this->info("转移企业数据成功.");
  62. }
  63. public function handleCompany($company, &$result_array)
  64. {
  65. $data['id']=$company->uid;
  66. $data['id']="xx";
  67. $data['id']="xx";
  68. $data['id']="xx";
  69. $data['id']="xx";
  70. $result_array[]= $data;
  71. }
  72. public function handleCompanyJob($jobs, &$result_array)
  73. {
  74. foreach ($jobs as $job) {
  75. $data['id']=$job->uid;
  76. $data['id']="xx";
  77. $data['id']="xx";
  78. $data['id']="xx";
  79. $data['id']="xx";
  80. $result_array[]= $data;
  81. }
  82. }
  83. }