JobfairoutPersonalJopApplyService.php 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wuzhenke
  5. * Date: 2019/1/27
  6. * Time: 10:42
  7. */
  8. namespace App\Services\Jobfairout;
  9. use App\Exceptions\ResponseException;
  10. use App\Models\Jobfair\JobfairPersonalJobsApply;
  11. use App\Models\Jobfairout\JobfairoutPersonalJobsApply;
  12. use App\Repositories\Jobfairout\JobfairoutPersonalJobsApplyRepository;
  13. use App\Repositories\ResumeRepository;
  14. class JobfairoutPersonalJopApplyService
  15. {
  16. protected $jobfairPersonalJobsApplyRepository;
  17. protected $resumeRepository;
  18. /**
  19. * JobfairPersonalJopApplyService constructor.
  20. * @param $resumeRepository
  21. */
  22. public function __construct(JobfairoutPersonalJobsApplyRepository $jobfairoutPersonalJobsApplyRepository, ResumeRepository $resumeRepository)
  23. {
  24. $this->jobfairoutPersonalJobsApplyRepository = $jobfairoutPersonalJobsApplyRepository;
  25. $this->resumeRepository = $resumeRepository;
  26. }
  27. public function downResumeDel($request,$user)
  28. {
  29. $id = $request->y_id;
  30. if (!$id) {
  31. return response()->json(['status'=>0, 'msg'=>'请选择操作的项目!']);
  32. }
  33. if (!is_array($id)) {
  34. $ids = explode(',', $id);
  35. } else {
  36. $ids = $id;
  37. }
  38. $this->isComOwn($ids,$user);
  39. if ($this->jobfairoutPersonalJobsApplyRepository->downResumeDel($ids)) {
  40. return response()->json(['status'=>1,'msg'=>'简历删除成功!']);
  41. }
  42. return response()->json(['status'=>0,'msg'=>'简历删除失败!']);
  43. }
  44. public function personJobfair()
  45. {
  46. $data[] = ['personal_uid','=',auth('web-member')->user()->id];
  47. if (request()->resume_id) {
  48. $data[] = ['resume_id','=',request()->resume_id];
  49. }
  50. $interview = $this->jobfairoutPersonalJobsApplyRepository->personJobfair($data, getJobsStatus(), getResumeStatus());
  51. return ['interview'=>$interview];
  52. }
  53. public function personDelect($id, $user)
  54. {
  55. if (empty($id)) {
  56. throw new ResponseException('请选择预约职位!');
  57. }
  58. $res = JobfairoutPersonalJobsApply::where(['personal_uid'=>$user->id])->get()->toArray();
  59. $array_id = array_column($res,'id');
  60. $arr_id = string_to_array(',', $id);
  61. foreach ($arr_id as $key=>$val){
  62. if(!in_array($val,$array_id)){
  63. throw new ResponseException('预约职位不存在!');
  64. }
  65. }
  66. return $this->jobfairoutPersonalJobsApplyRepository->downResumeDel(string_to_array(',', $id));
  67. }
  68. public function ifJobApply($user)
  69. {
  70. //判断是否有可以投递的简历
  71. $resume_audit = config('aix.personal_set.per_set.show_set.resume_display');
  72. $resume_where = array(array('uid', '=', $user->id));
  73. if (config('aix.personal_set.per_set.show_set.resume_display') == '1') {
  74. $resume_where[] = array('audit', '=', '2');
  75. } else {
  76. $resume_where[] = array('audit', '<>', '0');
  77. }
  78. $resumes = $this->resumeRepository->getResumes($resume_where);
  79. if (count($resumes) == 0) {
  80. //判断是否有简历
  81. $user_resumes = $this->resumeRepository->getResumes(array('uid' => $user->id));
  82. if ($user_resumes->toArray()) {
  83. throw new ResponseException("您没有审核通过的简历!");
  84. } else {
  85. throw new ResponseException("请您先填写一份简历!");
  86. }
  87. } else if (count($resumes) == 1) {
  88. //直接进入投递环节
  89. return ['status'=>3, 'resumes'=>$resumes];
  90. } else {
  91. //获取默认简历信息
  92. $def_resume = array();
  93. foreach ($resumes as $k => $v) {
  94. if ($v->def == '1') {
  95. $def_resume = $v;
  96. }
  97. }
  98. if (!$def_resume) {
  99. $def_resume = $resumes[0];
  100. }
  101. //提示用户选择需要投递的简历
  102. return array('status' => 2, 'resumes' => $resumes, 'def_resume' => $def_resume);
  103. }
  104. }
  105. public function applyJob($data)
  106. {
  107. return $this->jobfairoutPersonalJobsApplyRepository->create($data);
  108. }
  109. //发送面试邀请
  110. public function interview($request,$user){
  111. $type = $request->input('type');
  112. if($type == 2){
  113. //直接修改状态
  114. if(empty($request->input('apply_id'))){
  115. return response()->json(array('status'=>0,'msg'=>'邀请失败'));
  116. }
  117. $ret = $this->jobfairoutPersonalJobsApplyRepository->interviewEdit($request->input('apply_id'));
  118. $msg2 = '邀请成功';
  119. $msg3 = '邀请失败,请稍后重试';
  120. }else{
  121. if($type == 3 || $type == 5){
  122. $data['jobs_id'] = $request->input('job_id');
  123. $data['personal_uid'] = $request->input('personal_uid');
  124. $data['company_id'] = $user->id;
  125. $data['position_id'] = session('floorplan_stands.id');
  126. $data['jobfair_id'] = session('floorplan_stands.jobfair_id');
  127. }
  128. $res = $this->jobfairoutPersonalJobsApplyRepository->applyFind($data);
  129. if ($type == 3){
  130. $data['is_apply'] = 2;
  131. $msg = '您已对该简历进行过面试邀请,不能重复邀请';
  132. $msg2 = '邀请成功';
  133. $msg3 = '邀请失败,请稍后重试';
  134. }elseif ($type == 5){
  135. $data['is_apply'] = 1;
  136. $msg = '恭喜您已被面试邀请';
  137. $msg1 = '您已投递该职位,不能重复投递';
  138. $msg2 = '投递成功';
  139. $msg3 = '投递失败,请稍后重试';
  140. }
  141. if(!$res){
  142. $data['resume_id'] = $request->input('resume_id');
  143. $ret = $this->jobfairoutPersonalJobsApplyRepository->interviewAdd($data);
  144. }else{
  145. if($res->is_apply == 2 || ($res->is_apply == 1 && $res->is_interview == 1)){
  146. return response()->json(array('status'=>0,'msg'=>$msg));
  147. }elseif($res->is_apply == 1 && $res->is_interview == 2){
  148. if($type == 5){
  149. return response()->json(array('status'=>0,'msg'=>$msg1));
  150. }else{
  151. $ret = $this->jobfairoutPersonalJobsApplyRepository->interviewEdit($res->id);
  152. }
  153. }
  154. }
  155. }
  156. if ($ret) {
  157. return response()->json(array('status'=>1,'msg'=>$msg2));
  158. } else {
  159. return response()->json(array('status'=>0,'msg'=>$msg3));
  160. }
  161. }
  162. public function getApplyJobs($where, $field = 'jobs_id')
  163. {
  164. $rst = $this->jobfairoutPersonalJobsApplyRepository->getJobsApply($where);
  165. $list = array();
  166. if ($rst->toArray()) {
  167. foreach ($rst as $key => $val) {
  168. $list[$val->$field] = $val;
  169. }
  170. }
  171. return $list;
  172. }
  173. public function isOwn($id,$user)
  174. {
  175. $apply = $this->jobfairoutPersonalJobsApplyRepository->applyFind(['id'=>$id]);
  176. if(!$apply)
  177. {
  178. throw new ResponseException('参数错误!');
  179. }
  180. if($apply->personal_uid != $user->id)
  181. {
  182. throw new ResponseException('抱歉,您只能操作自己的招聘会!');
  183. }
  184. }
  185. //企业判断
  186. public function isComOwn($idsArr,$user)
  187. {
  188. $allIdsArr = $this->jobfairoutPersonalJobsApplyRepository->getPluck(['company_id'=>$user->id],'id')->toArray();
  189. if(array_diff($idsArr,$allIdsArr))
  190. {
  191. throw new ResponseException('抱歉,您只能操作自己的招聘会数据!');
  192. }
  193. }
  194. }