JobController.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. namespace App\Http\Controllers\Api\Test;
  3. use App\Http\Controllers\Api\ApiBaseController;
  4. use App\Models\Category;
  5. use App\Models\Company;
  6. use App\Models\Jobs;
  7. use App\Models\JobsContact;
  8. use Illuminate\Http\Request;
  9. use PhpOffice\PhpSpreadsheet\IOFactory;
  10. class JobController extends ApiBaseController
  11. {
  12. public function import(Request $request)
  13. {
  14. return '完成';
  15. $spreadsheet = IOFactory::load(public_path() . '/job.xls');
  16. $sheet = $spreadsheet->getActiveSheet();
  17. $rowCount = $sheet->getHighestRow();
  18. $record = [];
  19. for ($row = 5; $row <= $rowCount; $row++) {
  20. if (empty($sheet->getCell("D{$row}")->getValue())) {
  21. continue;
  22. }
  23. $record[] = [
  24. 'company_name' => $sheet->getCell("D{$row}")->getValue(),
  25. 'job_name' => $sheet->getCell("G{$row}")->getValue(),
  26. 'amount' => $sheet->getCell("I{$row}")->getValue(),
  27. 'max_age' => $sheet->getCell("K{$row}")->getValue(),
  28. 'sex' => $sheet->getCell("L{$row}")->getValue(),
  29. 'education' => $sheet->getCell("O{$row}")->getValue(),
  30. 'xuewei' => $sheet->getCell("P{$row}")->getValue(),
  31. 'major' => $sheet->getCell("Q{$row}")->getValue(),
  32. 'jobs_content' => $sheet->getCell("R{$row}")->getValue(),
  33. 'contacts' => $sheet->getCell("T{$row}")->getValue(),
  34. ];
  35. }
  36. $company_name_list = array_unique(array_column($record, 'company_name'));
  37. $company_list = Company::whereIn('companyname', $company_name_list)->get()->keyBy('companyname');
  38. $education = Category::categoryTypeByDemand('AIX_education');
  39. foreach ($record as $k => $v) {
  40. if (empty($company_list[$v['company_name']])) {
  41. return $v['company_name'] . '还未创建';
  42. }
  43. $item = [];
  44. $item['valid'] = 1;
  45. $item['jobs_name'] = $v['job_name'];
  46. $item['company_id'] = $company_list[$v['company_name']]['id'];
  47. $item['company_name'] = $company_list[$v['company_name']]['companyname'];
  48. $item['company_addtime'] = strtotime($company_list[$v['company_name']]['created_at']);
  49. $item['company_audit'] = 1;
  50. $item['amount'] = $v['amount'];
  51. $item['topclass'] = 225;
  52. $item['category'] = 226;
  53. $item['subclass'] = 992;
  54. $item['trade'] = $company_list[$v['company_name']]['trade'];
  55. $item['scale'] = $company_list[$v['company_name']]['scale'];
  56. $item['district'] = $company_list[$v['company_name']]['district'];
  57. $item['education'] = $education[$v['education']];
  58. $item['wage'] = -1;
  59. $item['age'] = [18, $v['max_age']];
  60. $item['jobs_content'] = "性别要求:" . $v['sex'] . "学位要求:" . $v['xuewei'] . ";专业要求:" . $v['major'] . $v['jobs_content'] . "\n";
  61. $item['audit'] = 1;
  62. $item['setmeal_id'] = 1;
  63. $item['setmeal_name'] = "免费会员";
  64. $item['display'] = 1;
  65. $item['is_health'] = 1;
  66. $item['health_type'] = 1;
  67. $jobs = Jobs::create($item);
  68. $jobs_contacts = explode(':',$v['contacts']);
  69. JobsContact::create([
  70. 'job_id' => $jobs['id'],
  71. 'contact' => $jobs_contacts[0],
  72. 'telephone' => $jobs_contacts[1],
  73. 'landline' => $jobs_contacts[1],
  74. 'address' => $company_list[$v['company_name']]['address'],
  75. 'email' => $company_list[$v['company_name']]['email'],
  76. 'notify_mobile' => 0,
  77. 'contact_show' => 1,
  78. 'telephone_show' => 1,
  79. 'email_show' => 1,
  80. 'landline_tel_show' => 1,
  81. ]);
  82. }
  83. return '完成';
  84. }
  85. }