HomeController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <?php
  2. namespace App\Http\Controllers\Jkq;
  3. use App\Models\Ad;
  4. use App\Models\Article;
  5. use App\Models\SubsiteAd;
  6. use App\Repositories\MemberInfoRepository;
  7. use App\Services\Company\CompanyService;
  8. use App\Services\Company\JobsService;
  9. use Illuminate\Support\Facades\DB;
  10. class HomeController extends JkqBaseController
  11. {
  12. private $memberInfoRepository;
  13. private $companyService;
  14. private $jobsService;
  15. public function __construct(MemberInfoRepository $memberInfoRepository, CompanyService $companyService, JobsService $jobsService)
  16. {
  17. $this->memberInfoRepository = $memberInfoRepository;
  18. $this->companyService = $companyService;
  19. $this->jobsService = $jobsService;
  20. }
  21. /**
  22. * 首页
  23. */
  24. public function index()
  25. {
  26. $return_data = [];
  27. $subsite_id = get_subsite_id();
  28. //公司
  29. $return_data['seatmeal_companies'] = $this->_dealCompany();
  30. //个人登录
  31. if (auth('web-member')->check()) {
  32. $return_data['memberInfo'] = $this->memberInfoRepository->getMemberInfo(auth('web-member')->id());
  33. }
  34. //首页轮播图
  35. $return_data['ad_list'] = [];
  36. $ad_ids = SubsiteAd::where('subsite_id', $subsite_id)->get(['ad_id'])->pluck('ad_id')->toArray();
  37. if (!empty($ad_ids)) {
  38. $return_data['ad_list'] = Ad::whereIn('id', $ad_ids)->get();
  39. }
  40. //文章列表
  41. $return_data['article_list'] = (new Article())->whereHas('subsites', function ($query) {
  42. $query->where('subsite_id', get_subsite_id());
  43. })->orderByRaw('list_order desc,created_at desc')->limit(10)->get();
  44. //办理人数
  45. $jkq_order = collect(DB::table('configs')->where('type_id','=',73)->get(['alias','value']))->keyBy('alias');
  46. $return_data['jkq_order'] = $jkq_order;
  47. return view('jkq.index', $return_data);
  48. }
  49. /**
  50. * 首页公司信息
  51. */
  52. private function _dealCompany()
  53. {
  54. $seatmeal_companies = $this->companyService->getCompaniesByConditions(['subsite_id' => 14], 20);
  55. $res = [];
  56. foreach ($seatmeal_companies as $v) {
  57. $jobs = [];
  58. if (!empty($v['jobs'])) {
  59. foreach ($v['jobs'] as $k => $job) {
  60. if ($k == 4) {
  61. break;
  62. }
  63. $jobs[] = [
  64. 'id' => $job['id'],
  65. 'jobs_name' => $job['jobs_name'],
  66. 'amount' => $job['amount'],
  67. ];
  68. }
  69. }
  70. $res[] = [
  71. 'id' => $v['id'],
  72. 'logo' => $v['logo'],
  73. 'companyname' => $v['companyname'],
  74. 'jobs' => $jobs,
  75. ];
  76. }
  77. return json_encode($res, JSON_UNESCAPED_UNICODE + JSON_UNESCAPED_SLASHES);
  78. //公司信息
  79. $seatmeal_companies = [];
  80. $seatmeal_arr = ['14', '11', '26,27,28', '13,35,153', '25', '3,4,6,9,10,16,17,20,21,25,28,30,31,34,36,37,40,41,44,45,151,165,213,314'];
  81. $company_ids = [];
  82. foreach ($seatmeal_arr as $key => $val) {
  83. $temp_company = [];
  84. $seat_company = $this->companyService->getSetmailCompanies(['trade' => $val], 4);
  85. if (!empty($seat_company)) {
  86. foreach ($seat_company as $v) {
  87. $temp_company[] = [
  88. 'id' => $v->id,
  89. 'logo' => $v->logo,
  90. 'companyname' => $v->companyname,
  91. ];
  92. $company_ids[] = $v->id;
  93. }
  94. }
  95. $seatmeal_companies[] = $temp_company;
  96. }
  97. //处理公司职位
  98. if (!empty($company_ids)) {
  99. //获取职位
  100. $jobs_where = [
  101. ['valid', '=', 1],
  102. ['display', '=', 1],
  103. ];
  104. $jobs_where[] = [function ($query) use ($company_ids) {
  105. $query->whereIn('company_id', $company_ids);
  106. }];
  107. $jobs_display = config('aix.companyset.comset.show_set.jobs_display');
  108. if ($jobs_display == 1) {
  109. $jobs_where[] = ['audit', '=', '1'];
  110. } else {
  111. $jobs_where[] = ['audit', '<>', '3'];
  112. }
  113. $jobs = $this->jobsService->getOtherJobs($jobs_where, 4);
  114. //组装数据
  115. if (!empty($jobs)) {
  116. $job_list = [];
  117. foreach ($jobs as $v) {
  118. $job_list[$v['company_id']][] = [
  119. 'id' => $v->id,
  120. 'jobs_name' => $v->jobs_name,
  121. 'amount' => $v->amount,
  122. ];
  123. }
  124. foreach ($seatmeal_companies as $k => $company_list) {
  125. foreach ($company_list as $key => $company) {
  126. if (!empty($job_list[$company['id']])) {
  127. $seatmeal_companies[$k][$key]['jobs'] = $job_list[$company['id']];
  128. } else {
  129. $seatmeal_companies[$k][$key]['jobs'] = [];
  130. }
  131. }
  132. }
  133. }
  134. }
  135. return json_encode($seatmeal_companies,JSON_UNESCAPED_UNICODE+JSON_UNESCAPED_SLASHES);
  136. }
  137. }