JobController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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']};\n学位要求:{$v['xuewei']};\n专业要求:{$v['major']};\n其他要求:{$v['jobs_content']};\n联系人:{$v['contacts']};";
  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'] = 4;
  67. $jobs_contacts = '';
  68. if (!empty($v['contacts'])) {
  69. $jobs_contacts = explode(':',$v['contacts']);
  70. }
  71. $jobs = Jobs::create($item);
  72. JobsContact::create([
  73. 'job_id' => $jobs['id'],
  74. 'contact' => empty($jobs_contacts) ? '' : $jobs_contacts[0],
  75. 'telephone' => $company_list[$v['company_name']]['mobile'],
  76. 'landline_tel' => empty($jobs_contacts) ? '' : explode('-', $jobs_contacts[1]),
  77. 'address' => $company_list[$v['company_name']]['address'],
  78. 'email' => $company_list[$v['company_name']]['email'],
  79. 'notify_mobile' => 0,
  80. 'contact_show' => 1,
  81. 'telephone_show' => 0,
  82. 'email_show' => 1,
  83. 'landline_tel_show' => 1,
  84. ]);
  85. }
  86. return '完成';
  87. }
  88. }