JobController.php 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 Illuminate\Http\Request;
  8. use PhpOffice\PhpSpreadsheet\IOFactory;
  9. class JobController extends ApiBaseController
  10. {
  11. public function import(Request $request)
  12. {
  13. return '完成';
  14. $spreadsheet = IOFactory::load(public_path() . '/job.xls');
  15. $sheet = $spreadsheet->getActiveSheet();
  16. $rowCount = $sheet->getHighestRow();
  17. $record = [];
  18. for ($row = 5; $row <= $rowCount; $row++) {
  19. if (empty($sheet->getCell("D{$row}")->getValue())) {
  20. continue;
  21. }
  22. $record[] = [
  23. 'company_name' => $sheet->getCell("D{$row}")->getValue(),
  24. 'job_name' => $sheet->getCell("G{$row}")->getValue(),
  25. 'amount' => $sheet->getCell("I{$row}")->getValue(),
  26. 'max_age' => $sheet->getCell("K{$row}")->getValue(),
  27. 'sex' => $sheet->getCell("L{$row}")->getValue(),
  28. 'education' => $sheet->getCell("O{$row}")->getValue(),
  29. 'xuewei' => $sheet->getCell("P{$row}")->getValue(),
  30. 'major' => $sheet->getCell("Q{$row}")->getValue(),
  31. 'jobs_content' => $sheet->getCell("R{$row}")->getValue(),
  32. ];
  33. }
  34. $company_name_list = array_unique(array_column($record, 'company_name'));
  35. $company_list = Company::whereIn('companyname', $company_name_list)->get()->keyBy('companyname');
  36. $education = Category::categoryTypeByDemand('AIX_education');
  37. foreach ($record as $k => $v) {
  38. if (empty($company_list[$v['company_name']])) {
  39. return $v['company_name'] . '还未创建';
  40. }
  41. $item = [];
  42. $item['valid'] = 1;
  43. $item['jobs_name'] = $v['job_name'];
  44. $item['company_id'] = $company_list[$v['company_name']]['id'];
  45. $item['company_name'] = $company_list[$v['company_name']]['companyname'];
  46. $item['company_addtime'] = strtotime($company_list[$v['company_name']]['created_at']);
  47. $item['company_audit'] = 1;
  48. $item['amount'] = $v['amount'];
  49. $item['topclass'] = 225;
  50. $item['category'] = 226;
  51. $item['subclass'] = 992;
  52. $item['trade'] = $company_list[$v['company_name']]['trade'];
  53. $item['scale'] = $company_list[$v['company_name']]['scale'];
  54. $item['district'] = $company_list[$v['company_name']]['district'];
  55. $item['education'] = $education[$v['education']];
  56. $item['wage'] = -1;
  57. $item['age'] = [18,$v['max_age']];
  58. $item['jobs_content'] = "学位要求:" . $v['xuewei'] . ";专业要求:" . $v['major'] . $v['jobs_content'] . "\n";
  59. $item['audit'] = 1;
  60. $item['setmeal_id'] = 1;
  61. $item['setmeal_name'] = "免费会员";
  62. $item['display'] = 1;
  63. $item['is_health'] = 1;
  64. $item['health_type'] = 1;
  65. Jobs::create($item);
  66. }
  67. return '完成';
  68. }
  69. }