JobfairController.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Administrator
  5. * Date: 2019/3/28
  6. * Time: 14:30
  7. */
  8. namespace App\Http\Controllers\Web\Hardware\Aio;
  9. use App\Http\Controllers\Web\WebBaseController;
  10. use App\Repositories\Jobfair\JobfairCompanyRepository;
  11. use App\Repositories\Jobfair\JobfairPersonalJobsApplyRepository;
  12. use App\Repositories\Jobfair\JobfairPutJobRepository;
  13. use App\Repositories\Jobfair\JobfairRepository;
  14. use App\Repositories\ResumeRepository;
  15. use App\Services\Common\CategoryService;
  16. use App\Services\Jobfair\JobfairPersonalJopApplyService;
  17. use App\Services\Jobfair\JobfairService;
  18. use App\Services\Person\ResumeService;
  19. use Illuminate\Http\Request;
  20. use App\Services\Company\CompanyDownResumeService;
  21. use App\Services\Jobfair\JobfairPutJobService;
  22. use App\Services\Jobfair\JobfairCompanyService;
  23. use Illuminate\Support\Facades\DB;
  24. class JobfairController extends WebBaseController
  25. {
  26. protected $jobfairRepository;
  27. protected $jobfairCompanyRepository;
  28. protected $jobfairPutJobRepository;
  29. protected $categoryService;
  30. protected $jobfairService;
  31. protected $jobfairPersonalJopApplyService;
  32. protected $jobfairPersonalJobsApplyRepository;
  33. protected $resumeRepository;
  34. protected $companyDownResumeService;
  35. protected $resumeService;
  36. protected $jobfairPutJobService;
  37. protected $jobfairCompanyService;
  38. /**
  39. * JobfairController constructor.
  40. * @param $jobfairRepository
  41. * @param $jobfairCompanyRepository
  42. * @param $jobfairService
  43. * @param $jobfairPersonalJobsApplyRepository
  44. * @param $resumeRepository
  45. * @param $companyDownResumeService
  46. * @param $jobfairPutJobService
  47. * @param $jobfairCompanyService
  48. */
  49. public function __construct(JobfairRepository $jobfairRepository, ResumeRepository $resumeRepository, JobfairPersonalJobsApplyRepository $jobfairPersonalJobsApplyRepository, JobfairPersonalJopApplyService $jobfairPersonalJopApplyService, JobfairService $jobfairService, CategoryService $categoryService, JobfairPutJobRepository $jobfairPutJobRepository, JobfairCompanyRepository $jobfairCompanyRepository, CompanyDownResumeService $companyDownResumeService,ResumeService $resumeService,JobfairPutJobService $jobfairPutJobService,JobfairCompanyService $jobfairCompanyService)
  50. {
  51. $this->jobfairRepository = $jobfairRepository;
  52. $this->jobfairCompanyRepository = $jobfairCompanyRepository;
  53. $this->jobfairPutJobRepository = $jobfairPutJobRepository;
  54. $this->categoryService = $categoryService;
  55. $this->jobfairPersonalJopApplyService = $jobfairPersonalJopApplyService;
  56. $this->jobfairService = $jobfairService;
  57. $this->jobfairPersonalJobsApplyRepository = $jobfairPersonalJobsApplyRepository;
  58. $this->resumeRepository = $resumeRepository;
  59. $this->companyDownResumeService = $companyDownResumeService;
  60. $this->resumeService = $resumeService;
  61. $this->jobfairPutJobService = $jobfairPutJobService;
  62. $this->jobfairCompanyService = $jobfairCompanyService;
  63. }
  64. /**招聘会列表
  65. * @param Request $request
  66. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  67. */
  68. public function index()
  69. {
  70. $page = 4;
  71. $allJobfair = $this->jobfairRepository->AioAllJobfair($page);
  72. $res = [
  73. 'allJobfair'=>$allJobfair,
  74. 'week'=>['星期日','星期一','星期二','星期三','星期四','星期五','星期六']
  75. ];
  76. return view('app.hardware.aio.jobfair.index', $res);
  77. }
  78. public function jobfairDetail($id)
  79. {
  80. if (!$id) {
  81. return $this->showMessage('参数错误', route('hardware.aio.jobfair.index'));
  82. }
  83. if (!$jobfair = $this->jobfairRepository->find($id)) {
  84. return $this->showMessage('无此招聘会', route('hardware.aio.jobfair.index'));
  85. }
  86. // 1预定中 0结束预定
  87. $time = time();
  88. if ($jobfair->predetermined_start and $jobfair->predetermined_start < $time && $jobfair->predetermined_status == 1 and $jobfair->predetermined_end >$time) {
  89. $jobfair->predetermined_ok = 1;
  90. } elseif ($jobfair->predetermined_start and $jobfair->predetermined_start > $time && $jobfair->predetermined_status == 1) {
  91. $jobfair->predetermined_ok = 2;
  92. } else {
  93. $jobfair->predetermined_ok = 0;
  94. }
  95. $res = [
  96. 'jobfair'=>$jobfair,
  97. ];
  98. return view('app.hardware.aio.jobfair.jobfair_detail', $res);
  99. }
  100. /**参会企业
  101. * @param $id
  102. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  103. */
  104. public function jobfairCom($id)
  105. {
  106. if (!$id) {
  107. return $this->showMessage('参数错误', route('hardware.aio.jobfair.index'));
  108. }
  109. if (!$this->jobfairRepository->find($id)) {
  110. return $this->showMessage('无此招聘会', route('hardware.aio.jobfair.index'));
  111. }
  112. $where['jobfair_id']=$id;
  113. $where['audit']=1;
  114. $page = 4;
  115. $jobfairComList = $this->jobfairCompanyRepository->aioFindCompany($where, $page);
  116. $res = [
  117. 'jobfairComList'=>$jobfairComList,
  118. ];
  119. return view('app.hardware.aio.jobfair.jobfair_com', $res);
  120. }
  121. /**招聘会企业详情
  122. * @param $uid
  123. * @param $jobfair_id
  124. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  125. */
  126. public function jobfairComDetail($uid, $jobfair_id)
  127. {
  128. if (!$uid || !$jobfair_id) {
  129. return $this->showMessage('参数错误', route('hardware.aio.jobfair.com'));
  130. }
  131. $put_jobs_where = [
  132. 'jobfair_id'=>$jobfair_id,
  133. 'company_id'=>$uid
  134. ];
  135. $jobs_where = [
  136. 'display'=>1,
  137. 'audit'=>1
  138. ];
  139. $jobfair_com = $this->jobfairCompanyRepository->findOneCom($put_jobs_where);
  140. $jobs = $this->jobfairPutJobRepository->getWhere($jobs_where,$put_jobs_where);
  141. $res = [
  142. 'jobfair_com'=>$jobfair_com,
  143. 'jobs'=>$jobs,
  144. ];
  145. return view('app.hardware.aio.jobfair.jobfair_com_detail', $res);
  146. }
  147. public function getUser()
  148. {
  149. $user = array();
  150. if (auth('web-member')->check()) {
  151. $user = auth('web-member')->user();
  152. } elseif (auth('web-company')->check()) {
  153. $user = auth('web-company')->user();
  154. }
  155. return $user;
  156. }
  157. public function jobfairJob(Request $request)
  158. {
  159. $params = array();
  160. $param_array = array('citycategory','wage','trade','education','key');
  161. if ($request->all()) {
  162. foreach ($request->all() as $k => $v) {
  163. if (in_array($k, $param_array) && $v) {
  164. $params[$k] = $v;
  165. }
  166. }
  167. }
  168. //所在地区(默认地区)
  169. $citys = $this->categoryService->getCitys();
  170. $orwhere=[];
  171. $where = $this->setWhere($params);
  172. if (array_key_exists('orwhere', $where)) {
  173. $orwhere = $where['orwhere'];
  174. unset($where['orwhere']);
  175. }
  176. $limit = 10;
  177. $list = $this->jobfairPutJobRepository->aioJobfairJob($where, $orwhere, $limit);
  178. $res = [
  179. 'params'=>$params,
  180. 'list'=>$list,
  181. 'arealist' => $citys,
  182. 'user' => $this->getUser(),
  183. ];
  184. return view('app.hardware.aio.jobfair.job.jobfair_job', $res);
  185. }
  186. /**招聘会职位详情
  187. * @param $id
  188. * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
  189. */
  190. public function jobfairJobDetail($id)
  191. {
  192. if (!$id) {
  193. return $this->showMessage('参数错误', route('hardware.aio.jobfair.com'));
  194. }
  195. $jobfairJobInfo = $this->jobfairPutJobRepository->getOne(['id'=>$id]);
  196. $res = [
  197. 'info'=>$jobfairJobInfo,
  198. 'user'=>$this->getUser(),
  199. ];
  200. return view('app.hardware.aio.jobfair.job.job_detail', $res);
  201. }
  202. /**个人预约招聘会职位
  203. * @param Request $request
  204. * @return \Illuminate\Http\JsonResponse
  205. * @throws \App\Exceptions\ResponseException
  206. * @throws \Throwable
  207. */
  208. public function jobfairJobApply(Request $request)
  209. {
  210. $user = $this->getUser();
  211. $jid = $request->jobsfair_job_id;
  212. $jobfair_id = $request->jobfair_id;
  213. $position_id = $request->position_id;
  214. $company_id = $request->company_id;
  215. $resume_id = $request->resume_id?$request->resume_id:0;
  216. $jobfair = $this->jobfairRepository->find($jobfair_id);
  217. if ($jobfair->isEmpty || $jobfair->holddate_end < time()) {
  218. return response()->json(['status'=>0, 'html'=>"招聘会已停止"]);
  219. }
  220. if ($resume_id) {
  221. $data['resume_id'] = $resume_id;
  222. $this->resumeService->isOwn($resume_id,$user);
  223. $this->jobfairPutJobService->isOwn($jid,$company_id);
  224. //错综复杂的关系
  225. $this->jobfairCompanyService->isPositionOwn($position_id,$jobfair_id,$company_id,$jid);
  226. $data['personal_uid'] = $user->id;
  227. $data['jobs_id'] = $jid;
  228. $data['company_id'] = $company_id;
  229. $data['jobfair_id'] = $jobfair_id;
  230. $data['position_id'] = $position_id;
  231. //简历完整度
  232. $res_complete = $this->resumeRepository->find($resume_id, ['complete_percent']);
  233. if ($res_complete['$res_complete'] < config('aix.personal_set.per_set.per_set.apply_job_min_percent')) {
  234. return response()->json(['status'=>0,'html'=>'请完善简历后再预约职位']);
  235. }
  236. if ($this->jobfairPersonalJobsApplyRepository->findWhere(['resume_id'=>$resume_id, 'jobs_id'=>$jid, 'company_id'=>$company_id, 'jobfair_id'=>$jobfair_id, 'position_id'=>$position_id])->isNotEmpty()) {
  237. return response()->json(['status'=>0, 'html'=>"您已预约该职位,请勿重复预约!"]);
  238. }
  239. DB::beginTransaction();
  240. try {
  241. $this->jobfairPersonalJopApplyService->applyJob($data);
  242. $this->companyDownResumeService->addDownResumes($company_id,$resume_id);
  243. DB::commit();
  244. return response()->json(['status'=>1, 'html'=>"职位预约成功!"]);
  245. } catch (\Exception $e) {
  246. DB::rollback();
  247. return response()->json(['status'=>0,'type'=>0 , 'html'=>"职位预约失败!"]);
  248. }
  249. } else {
  250. $result = $this->jobfairPersonalJopApplyService->ifJobApply($user);
  251. if ($result['status'] == 2) { //返回结果,让用户选择简历投递
  252. $page_data = array('status'=>array_get($result, 'status'),'resumes'=>array_get($result, 'resumes'),'def_resume'=>array_get($result, 'def_resume'),'jobs_id'=>$jid);
  253. $page_data['company_id'] = $company_id;
  254. $page_data['jobfair_id'] = $jobfair_id;
  255. $page_data['position_id'] = $position_id;
  256. $page_data['jobs_id'] = $jid;
  257. $html = view('app.hardware.aio.jobfair.job.ajax_apply', $page_data)->render();
  258. return response()->json(['status'=>2,'html'=>$html]);
  259. } elseif ($result['status'] == 3) { //直接投递
  260. $this->jobfairPutJobService->isOwn($jid,$company_id);
  261. //错综复杂的关系
  262. $this->jobfairCompanyService->isPositionOwn($position_id,$jobfair_id,$company_id,$jid);
  263. $resume = $result['resumes'][0];
  264. $data['resume_id'] = $resume->id;
  265. $data['personal_uid'] = $user->id;
  266. $data['jobs_id'] = $jid;
  267. $data['company_id'] = $company_id;
  268. $data['jobfair_id'] = $jobfair_id;
  269. $data['position_id'] = $position_id;
  270. $res_complete = $this->resumeRepository->find($resume->id, ['complete_percent']);
  271. if ($res_complete['complete_percent'] < config('aix.personal_set.per_set.per_set.apply_job_min_percent')) {
  272. return response()->json(['status'=>0,'html'=>'请完善简历后再预约职位']);
  273. }
  274. if ($this->jobfairPersonalJobsApplyRepository->findWhere(['resume_id'=>$resume->id, 'jobs_id'=>$jid, 'company_id'=>$company_id, 'jobfair_id'=>$jobfair_id, 'position_id'=>$position_id])->isNotEmpty()) {
  275. return response()->json(['status'=>0, 'html'=>"您已预约该职位,请勿重复预约!"]);
  276. }
  277. DB::beginTransaction();
  278. try {
  279. $this->jobfairPersonalJopApplyService->applyJob($data);
  280. $this->companyDownResumeService->addDownResumes($company_id,$resume->id);
  281. DB::commit();
  282. return response()->json(['status'=>1, 'html'=>"职位预约成功!"]);
  283. } catch (\Exception $e) {
  284. DB::rollback();
  285. return response()->json(['status'=>0,'type'=>0 , 'html'=>"职位预约失败!"]);
  286. }
  287. }
  288. }
  289. }
  290. protected function setWhere($params)
  291. {
  292. $where = [
  293. ['audit','=',1],
  294. ['display','=',1]
  295. ];
  296. if ($params) {
  297. foreach ($params as $k => $v) {
  298. if ($k == 'citycategory') {
  299. //地标地段
  300. $district = getDistrict($v);
  301. $where[] = array('district','like',"%$district%");
  302. } elseif ($k =='key') {
  303. $where['orwhere'] = [['jobs_name', 'like', "%$v%"],['company_name', 'like', "%$v%"]];
  304. } else {
  305. $where[] = [$k,'=', $v];
  306. }
  307. }
  308. }
  309. return $where;
  310. }
  311. }