CompanyController.php 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <?php
  2. namespace App\Http\Controllers\Jkq\Content;
  3. use App\Http\Controllers\Jkq\JkqBaseController;
  4. use App\Services\Company\JobsService;
  5. use Illuminate\Http\Request;
  6. use App\Exceptions\ResponseException;
  7. use App\Services\Company\CompanyService;
  8. use Illuminate\Support\Facades\View;
  9. class CompanyController extends JkqBaseController
  10. {
  11. protected $jobsService;
  12. protected $companyService;
  13. /**
  14. * JobsController constructor.
  15. * @param $jobsService
  16. * @param $companyService
  17. */
  18. public function __construct(JobsService $jobsService, CompanyService $companyService)
  19. {
  20. $this->jobsService = $jobsService;
  21. $this->companyService = $companyService;
  22. }
  23. public function companyShow(Request $request)
  24. {
  25. //获取企业信息
  26. $preview = $request->input('preview', 0);
  27. $company_id = $request->input('id');
  28. $tpl = $request->input('tpl');
  29. if ($preview && !$tpl) {
  30. $back_url = \Illuminate\Support\Facades\URL::previous();
  31. return $this->showMessage('模板不存在,请联系管理员!', $back_url, true, '上一页', '3');
  32. }
  33. $company_info = $this->companyService->getCompanyInfo(array(array('id','=',$company_id)));
  34. $this->putSeoData('company', $company_info);
  35. //在招职位
  36. $jobs_where = array(
  37. array('company_id','=',$company_info->id),
  38. array('valid','=',1),
  39. array('display','=',1)
  40. );
  41. $jobs_display = config('aix.companyset.comset.show_set.jobs_display');
  42. if ($jobs_display == 1) {
  43. $jobs_where[] = array('audit','=','1');
  44. } else {
  45. $jobs_where[] = array('audit','<>','3');
  46. }
  47. $jobs = $this->jobsService->getOtherJobs($jobs_where, 4);
  48. $all_jobs = $this->jobsService->getOtherJobs($jobs_where);
  49. if ($jobs->total() == 0) {
  50. $jobs = null;
  51. $all_jobs = null;
  52. }
  53. //相似职位信息。
  54. $category_id = [];
  55. $likeJobs = collect([]);
  56. if(!empty($all_jobs)){
  57. foreach ($all_jobs as $key=>$value){
  58. if($value->category){
  59. $category_id[$key] = $value->category;
  60. }
  61. }
  62. $category_id = array_unique($category_id);
  63. }
  64. if($category_id){
  65. $new_jobs = array_diff_key($jobs_where,[0]);
  66. $likeJobs = $this->jobsService->getOtherJobs($new_jobs, 6,1,$category_id);
  67. }
  68. //看过该公司的人还看过(获取相同行业的企业)
  69. $company_where = array(
  70. 'trade' => $company_info->trade,
  71. 'except_id' =>$company_info->id
  72. );
  73. $other_companys = $this->companyService->getOtherCompanies($company_where, 5);
  74. $user = $this->getUser();
  75. if ($user && $user->utype==2) {
  76. //获取当前时间段内申请过的职位
  77. $space_time = (integer)config('aix.personal_set.per_set.per_set.apply_job_space');
  78. if ($space_time>0) {
  79. $stime = date('Y-m-d H:i:s', strtotime(date("Y-m-d", strtotime("-".$space_time." day"))));
  80. $apply_where = array(array('personal_uid','=',auth('web-member')->user()->id),array('created_at','>=',$stime));
  81. } else {
  82. $apply_where = array(array('personal_uid','=',auth('web-member')->user()->id));
  83. }
  84. $applys = $this->jobsService->getApplyJobs($apply_where);
  85. } else {
  86. $applys = array();
  87. }
  88. $return_data = array(
  89. 'info'=>$company_info,
  90. 'jobs'=>$jobs,
  91. 'applys' => $applys,
  92. 'all_jobs'=>$all_jobs,
  93. 'other_companys'=>$other_companys,
  94. 'company_img' => $company_info->img,
  95. 'tpl' => $tpl,
  96. 'likeJobs'=>$likeJobs,
  97. 'category_id'=>implode(',',$category_id)
  98. );
  99. if (!$tpl) {
  100. $tpl = $company_info->tpl;
  101. $is_scan = false;
  102. } else {
  103. $is_scan = true;
  104. }
  105. if ($tpl == 'default') {
  106. return view('jkq.common.tpl_company.default.company_show', $return_data);
  107. } else {
  108. if (View::exists('company.'.$tpl.'.index')) {
  109. $return_data['tpl'] = $tpl;
  110. return view('company.'.$tpl.'.index', $return_data);
  111. } else {
  112. if ($is_scan) {
  113. $back_url = \Illuminate\Support\Facades\URL::previous();
  114. return $this->showMessage('模板不存在,请联系管理员!', $back_url, true, '上一页', '3');
  115. } else {
  116. return view('jkq.common.tpl_company.default.company_show', $return_data);
  117. }
  118. }
  119. }
  120. }
  121. public function moreCompany(Request $request)
  122. {
  123. $company_id = $request->input('id', 0);
  124. if (!$company_id) {
  125. return response()->json(['status'=>0, 'error'=>'参数错误!']);
  126. }
  127. $jobs_where = array(
  128. array('company_id','=',$company_id),
  129. array('valid','=',1),
  130. array('display','=',1)
  131. );
  132. $jobs_display = config('aix.companyset.comset.show_set.jobs_display');
  133. if ($jobs_display == 1) {
  134. $jobs_where[] = array('audit','=','1');
  135. } else {
  136. $jobs_where[] = array('audit','<>','3');
  137. }
  138. $limit = $request->input('limit', 10);
  139. $jobs = $this->jobsService->getOtherJobs($jobs_where, $limit);
  140. if ($jobs->isEmpty()) {
  141. return response()->json(['status'=>0, 'error'=>'没有更多职位了!']);
  142. }
  143. return response()->json(['status'=>1, 'jobs'=>json_encode($jobs->items()), 'jobs_num'=>count($jobs->items())]);
  144. }
  145. //关注企业
  146. public function companyFocus(Request $request)
  147. {
  148. $company_id = $request->input('company_id');
  149. if (!$company_id) {
  150. throw new ResponseException('请选择要关注的企业!');
  151. }
  152. $rst = $this->companyService->focusCompany($company_id, auth('web-member')->user()->id);
  153. return response()->json($rst);
  154. }
  155. //企业访客统计
  156. public function addStatistics(Request $request)
  157. {
  158. $company_id = $request->input('company_id');
  159. $this->companyService->addStatistics($company_id, 0, $this->getUser(), 0, 1);
  160. return response()->json(['status'=>1]);
  161. }
  162. public function getUser()
  163. {
  164. $user = array();
  165. if (auth('web-member')->check()) {
  166. $user = auth('web-member')->user();
  167. } elseif (auth('web-company')->check()) {
  168. $user = auth('web-company')->user();
  169. }
  170. return $user;
  171. }
  172. //在招职位页面
  173. public function jobs(Request $request)
  174. {
  175. //获取企业信息
  176. $company_id = $request->input('id');
  177. $company_info = $this->companyService->getCompanyInfo(array(array('id','=',$company_id)));
  178. $this->putSeoData('company', $company_info);
  179. //在招职位
  180. $jobs_where = array(
  181. array('company_id','=',$company_info->id),
  182. array('valid','=',1),
  183. array('display','=',1)
  184. );
  185. $jobs_display = config('aix.companyset.comset.show_set.jobs_display');
  186. if ($jobs_display == 1) {
  187. $jobs_where[] = array('audit','=','1');
  188. } else {
  189. $jobs_where[] = array('audit','<>','3');
  190. }
  191. $jobs = $this->jobsService->getOtherJobs($jobs_where);
  192. $user = $this->getUser();
  193. if ($user && $user->utype==2) {
  194. //获取当前时间段内申请过的职位
  195. $space_time = (integer)config('aix.personal_set.per_set.per_set.apply_job_space');
  196. if ($space_time>0) {
  197. $stime = date('Y-m-d H:i:s', strtotime(date("Y-m-d", strtotime("-".$space_time." day"))));
  198. $apply_where = array(array('personal_uid','=',auth('web-member')->user()->id),array('created_at','>=',$stime));
  199. } else {
  200. $apply_where = array(array('personal_uid','=',auth('web-member')->user()->id));
  201. }
  202. $applys = $this->jobsService->getApplyJobs($apply_where);
  203. } else {
  204. $applys = array();
  205. }
  206. //看过该公司的人还看过(获取相同行业的企业)
  207. $company_where = array(
  208. 'trade' => $company_info->trade,
  209. 'except_id' =>$company_info->id
  210. );
  211. $other_companys = $this->companyService->getOtherCompanies($company_where, 5);
  212. if ($request->input('tpl', '')) {
  213. $tpl = $request->input('tpl', '');
  214. } else {
  215. $tpl = $company_info->tpl;
  216. }
  217. //相似职位信息。
  218. $category_id = [];
  219. $likeJobs = collect([]);
  220. //在招职位bug,临时修改
  221. if( !empty($jobs)){
  222. foreach ($jobs as $key=>$value){
  223. if($value->category){
  224. $category_id[$key] = $value->category;
  225. }
  226. }
  227. $category_id = array_unique($category_id);
  228. }
  229. if($category_id){
  230. $likeJobs = $this->jobsService->getOtherJobs($jobs_where, 6,1,$category_id);
  231. }
  232. if ($jobs->isEmpty()) {
  233. $jobs = null;
  234. }
  235. $return_data = array(
  236. 'info'=>$company_info,
  237. 'jobs'=>$jobs,
  238. 'other_companys'=>$other_companys,
  239. 'applys' => $applys,
  240. 'tpl' => $tpl,
  241. 'likeJobs'=>$likeJobs,
  242. 'category_id'=>implode(',',$category_id)
  243. );
  244. if ($tpl == 'default') {
  245. return view('jkq.common.tpl_company.default.company_jobs', $return_data);
  246. } else {
  247. if (View::exists('company.'.$tpl.'.company_jobs')) {
  248. $return_data['tpl'] = $tpl;
  249. return view('company.'.$tpl.'.company_jobs', $return_data);
  250. } else {
  251. return view('jkq.common.tpl_company.default.company_jobs', $return_data);
  252. }
  253. }
  254. }
  255. }