CompanyController.php 10.0 KB

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