JobController.php 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Http\Controllers\Api\Soldier;
  3. use App\Http\Controllers\Api\ApiBaseController;
  4. use App\Models\Category;
  5. use App\Models\CategoryJobs;
  6. use App\Models\Jobs;
  7. use App\Models\JobsContact;
  8. use Illuminate\Http\Request;
  9. class JobController extends ApiBaseController
  10. {
  11. public function getSoldierJobList(Request $request)
  12. {
  13. $page = $request->input('page', 1);
  14. $limit = $request->input('limit', 10);
  15. $update_at = $request->input('update_at', '');
  16. $where = [
  17. ['valid', '=', 1],
  18. ['company_audit', '=', 1],
  19. ['audit', '=', 1],
  20. ['display', '=', 1],
  21. ['is_soldier', '=', 1],
  22. ];
  23. if (!empty($update_at)) {
  24. $where[] = ['updated_at', '>', $update_at];
  25. }
  26. $list = Jobs::select('id', 'jobs_name', 'company_name', 'nature', 'sex', 'age', 'amount', 'topclass', 'category', 'subclass', 'trade', 'scale', 'tag', 'education', 'experience', 'wage', 'wage_max', 'negotiable', 'wage_min', 'wage_str', 'jobs_content', 'department', 'created_at', 'updated_at')
  27. ->where($where)
  28. ->offset(($page - 1) * $limit)
  29. ->limit($limit)
  30. ->get()
  31. ->toArray();
  32. $ids = [];
  33. $category = [];
  34. $category_job = [];
  35. $tag = [];
  36. foreach ($list as $v) {
  37. $ids[] = $v['id'];
  38. $category[] = $v['nature'];
  39. $category_job[] = $v['topclass'];
  40. $category_job[] = $v['category'];
  41. $category_job[] = $v['subclass'];
  42. $category[] = $v['trade'];
  43. $category[] = $v['scale'];
  44. if (!empty($v['tag'][0])) {
  45. $tag = array_merge($tag, $v['tag']);
  46. }
  47. $category[] = $v['education'];
  48. $category[] = $v['experience'];
  49. }
  50. $category = array_merge($category, $tag);
  51. $contact_list = JobsContact::select('job_id', 'contact', 'telephone', 'email', 'address')->whereIn('job_id', $ids)->get()->keyBy('job_id')->toArray();
  52. $category_list = Category::whereIn('id', array_unique($category))->pluck('demand', 'id')->toArray();
  53. $category_job_list = CategoryJobs::whereIn('id', array_unique($category_job))->pluck('name', 'id')->toArray();
  54. foreach ($list as $k => $v) {
  55. $list[$k]['contact_name'] = $contact_list[$v['id']]['contact'];
  56. $list[$k]['contact_telephone'] = $contact_list[$v['id']]['telephone'];
  57. $list[$k]['contact_email'] = $contact_list[$v['id']]['email'];
  58. $list[$k]['contact_address'] = $contact_list[$v['id']]['address'];
  59. $list[$k]['nature'] = empty($category_list[$v['nature']]) ? '' : $category_list[$v['nature']];
  60. $list[$k]['topclass'] = empty($category_job_list[$v['topclass']]) ? '' : $category_job_list[$v['topclass']];
  61. $list[$k]['category'] = empty($category_job_list[$v['category']]) ? '' : $category_job_list[$v['category']];
  62. $list[$k]['subclass'] = empty($category_job_list[$v['subclass']]) ? '' : $category_job_list[$v['subclass']];
  63. $list[$k]['trade'] = empty($category_list[$v['trade']]) ? '' : $category_list[$v['trade']];
  64. $list[$k]['scale'] = empty($category_list[$v['scale']]) ? '' : $category_list[$v['scale']];
  65. $tags = [];
  66. foreach ($v['tag'] as $tag) {
  67. if (!empty($category_list[$tag])) {
  68. $tags[] = $category_list[$tag];
  69. }
  70. }
  71. $list[$k]['tag'] = $tags;
  72. $list[$k]['education'] = empty($category_list[$v['education']]) ? '' : $category_list[$v['education']];
  73. $list[$k]['experience'] = empty($category_list[$v['experience']]) ? '' : $category_list[$v['experience']];
  74. $list[$k]['experience'] = empty($category_list[$v['experience']]) ? '' : $category_list[$v['experience']];
  75. }
  76. return response()->json($list);
  77. }
  78. }