HomeController.php 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. return json_encode($seatmeal_companies,JSON_UNESCAPED_UNICODE+JSON_UNESCAPED_SLASHES);
  56. dd($seatmeal_companies);
  57. //公司信息
  58. $seatmeal_companies = [];
  59. $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'];
  60. $company_ids = [];
  61. foreach ($seatmeal_arr as $key => $val) {
  62. $temp_company = [];
  63. $seat_company = $this->companyService->getSetmailCompanies(['trade' => $val], 4);
  64. if (!empty($seat_company)) {
  65. foreach ($seat_company as $v) {
  66. $temp_company[] = [
  67. 'id' => $v->id,
  68. 'logo' => $v->logo,
  69. 'companyname' => $v->companyname,
  70. ];
  71. $company_ids[] = $v->id;
  72. }
  73. }
  74. $seatmeal_companies[] = $temp_company;
  75. }
  76. //处理公司职位
  77. if (!empty($company_ids)) {
  78. //获取职位
  79. $jobs_where = [
  80. ['valid', '=', 1],
  81. ['display', '=', 1],
  82. ];
  83. $jobs_where[] = [function ($query) use ($company_ids) {
  84. $query->whereIn('company_id', $company_ids);
  85. }];
  86. $jobs_display = config('aix.companyset.comset.show_set.jobs_display');
  87. if ($jobs_display == 1) {
  88. $jobs_where[] = ['audit', '=', '1'];
  89. } else {
  90. $jobs_where[] = ['audit', '<>', '3'];
  91. }
  92. $jobs = $this->jobsService->getOtherJobs($jobs_where, 4);
  93. //组装数据
  94. if (!empty($jobs)) {
  95. $job_list = [];
  96. foreach ($jobs as $v) {
  97. $job_list[$v['company_id']][] = [
  98. 'id' => $v->id,
  99. 'jobs_name' => $v->jobs_name,
  100. 'amount' => $v->amount,
  101. ];
  102. }
  103. foreach ($seatmeal_companies as $k => $company_list) {
  104. foreach ($company_list as $key => $company) {
  105. if (!empty($job_list[$company['id']])) {
  106. $seatmeal_companies[$k][$key]['jobs'] = $job_list[$company['id']];
  107. } else {
  108. $seatmeal_companies[$k][$key]['jobs'] = [];
  109. }
  110. }
  111. }
  112. }
  113. }
  114. return json_encode($seatmeal_companies,JSON_UNESCAPED_UNICODE+JSON_UNESCAPED_SLASHES);
  115. }
  116. }