HomeController.php 4.4 KB

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