TransferTestApply.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace App\Console\Commands\Transfer;
  3. use App\Models\MemberInfo;
  4. use App\Models\MembersLog;
  5. use App\Models\MembersPoint;
  6. use App\Models\PersonalServiceStick;
  7. use App\Models\PersonalServiceStickLog;
  8. use App\Models\PersonalServiceTag;
  9. use App\Models\PersonalServiceTagLog;
  10. use App\Models\PersonFavorite;
  11. use App\Models\PersonFocusCompany;
  12. use App\Models\PersonJobsSubscribe;
  13. use App\Models\Resume;
  14. use App\Models\ResumeCredent;
  15. use App\Models\ResumeEducation;
  16. use App\Models\ResumeLanguage;
  17. use App\Models\ResumeTrain;
  18. use App\Models\ResumeWork;
  19. use App\Models\SubsiteResume;
  20. use App\Models\Thirdlogin;
  21. use App\Models\ViewJob;
  22. use App\Transfer\CompanyStatistics;
  23. use App\Transfer\Member;
  24. use App\Transfer\MemberBind;
  25. use App\Transfer\MemberLog;
  26. use App\Transfer\Msg;
  27. use App\Transfer\PersonalFavorite;
  28. use App\Transfer\PersonalFocusCompany;
  29. use App\Transfer\PersonalJobsApply;
  30. use App\Transfer\PersonalJobsSubscribe;
  31. use App\Transfer\PersonalStickLog;
  32. use App\Transfer\PersonalTagLog;
  33. use App\Transfer\ResumeImg;
  34. use App\Transfer\ViewJobs;
  35. use App\Transfer\ViewResume;
  36. use Illuminate\Console\Command;
  37. use Illuminate\Support\Facades\DB;
  38. class TransferTestApply extends Command
  39. {
  40. /**
  41. * The name and signature of the console command.
  42. *
  43. * @var string
  44. */
  45. protected $signature = 'aix:transfer-member-apply';
  46. /**
  47. * The console command description.
  48. *
  49. * @var string
  50. */
  51. protected $description = '转移旧系统个人数据';
  52. /**
  53. * Create a new command instance.
  54. *
  55. * @return void
  56. */
  57. public function __construct()
  58. {
  59. parent::__construct();
  60. }
  61. /**
  62. * Execute the console command.
  63. *
  64. * @return mixed
  65. */
  66. public function handle()
  67. {
  68. $this->info('清除企业统计数据表companyStatistics');
  69. DB::table('company_statistics')->delete();
  70. //转移company_statistics数据
  71. $this->info("开始转移数据...");
  72. $total = CompanyStatistics::get()->count();
  73. $bar=$this->output->createProgressBar($total);
  74. CompanyStatistics::with('companyProfile')->orderBy('id', 'asc')->chunk(3000, function ($companyStatistics) use ($bar) {
  75. $statistics_arr = [];
  76. $this->handleStatistics($companyStatistics, $statistics_arr);
  77. if ($statistics_arr) {
  78. \App\Models\CompanyStatistics::insert($statistics_arr);
  79. }
  80. $bar->advance(3000);
  81. });
  82. $bar->finish();
  83. $this->line(" 完成!");
  84. $this->info("转移company_statistics数据成功.");
  85. }
  86. public function handleStatistics($companyStatistics, &$statistics_arr)
  87. {
  88. $statisticsData = [];
  89. foreach ($companyStatistics as $key => $val) {
  90. if ($val->companyProfile) {
  91. $statisticsData['id'] = $val->id;
  92. if ($val->comid) {
  93. $statisticsData['company_id'] = $val->companyProfile->uid;
  94. } else {
  95. $statisticsData['company_id'] = $val->comid;
  96. };
  97. $statisticsData['uid'] = $val->uid;
  98. if ($val->uid) {
  99. if ($val->companys) {
  100. $statisticsData['utype'] = 1;
  101. } else {
  102. $statisticsData['utype'] = 2;
  103. }
  104. } else {
  105. $statisticsData['utype'] = 0;
  106. }
  107. $statisticsData['job_id'] = $val->jobid;
  108. $statisticsData['source'] = $val->source;
  109. $statisticsData['apply'] = $val->apply;
  110. $statisticsData['created_at'] = date('Y-m-d H:i:s', $val->addtime);
  111. $statisticsData['updated_at'] = date('Y-m-d H:i:s', $val->addtime);
  112. $statistics_arr[] = $statisticsData;
  113. }
  114. }
  115. }
  116. }