JobController.php 3.3 KB

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