JobfairService.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. namespace App\Services\Crm;
  3. use App\Exceptions\ResponseException;
  4. use Exception;
  5. use Illuminate\Support\Facades\DB;
  6. use Illuminate\Support\Facades\Cache;
  7. use App\Repositories\Jobfair\JobfairRepository;
  8. use App\Repositories\Jobfair\JobfairFloorplanStandRepository;
  9. use App\Repositories\Jobfair\JobfairCompanyRepository;
  10. use App\Repositories\Jobfair\JobfairPutJobRepository;
  11. use App\Repositories\Jobfair\JobfairJobRepository;
  12. use App\Models\Jobfair\JobfairCompany;
  13. use App\Services\Common\SmsService;
  14. use App\Services\Common\EmailService;
  15. use Aix\Sms\Contracts\Smser;
  16. use Encore\Admin\Facades\Admin;
  17. use App\Models\Pms;
  18. use App\Models\MembersHandsel;
  19. use App\Models\MembersPoint;
  20. use App\Models\MembersSetmeal;
  21. use App\Models\Jobfair\JobfairJob;
  22. use App\Models\Jobfair\JobfairPutJob;
  23. use App\Models\AuditReason;
  24. class JobfairService
  25. {
  26. protected $jobfairRepository;
  27. protected $jobfairFloorplanStandRepository;
  28. protected $jobfairCompanyRepository;
  29. protected $jobfairPutJobRepository;
  30. protected $jobfairJobRepository;
  31. protected $smsService;
  32. protected $emailService;
  33. /**
  34. * JobfairService constructor.
  35. */
  36. public function __construct(
  37. JobfairRepository $jobfairRepository,
  38. JobfairFloorplanStandRepository $jobfairFloorplanStandRepository,
  39. JobfairCompanyRepository $jobfairCompanyRepository,
  40. JobfairPutJobRepository $jobfairPutJobRepository,
  41. JobfairJobRepository $jobfairJobRepository,
  42. SmsService $smsService,
  43. EmailService $emailService
  44. )
  45. {
  46. $this->jobfairRepository = $jobfairRepository;
  47. $this->jobfairFloorplanStandRepository = $jobfairFloorplanStandRepository;
  48. $this->jobfairCompanyRepository = $jobfairCompanyRepository;
  49. $this->jobfairPutJobRepository = $jobfairPutJobRepository;
  50. $this->jobfairJobRepository = $jobfairJobRepository;
  51. $this->smsService = $smsService;
  52. $this->emailService = $emailService;
  53. }
  54. public function getJobfairExhibitors($com_ids, $data)
  55. {
  56. $whereIn = [];
  57. if ($com_ids) {
  58. $ids = explode(',',$com_ids);
  59. $whereIn['company_id'] = $ids;
  60. }
  61. $order_by = 'FIELD(audit, 2,1,3), updated_at desc';
  62. $limit = array_has($data, 'limit')?$data['limit']:'';
  63. $offset = array_has($data, 'offset')?$data['offset']:'';
  64. $rst = $this->jobfairCompanyRepository->getCrmJobfairExhibitors([], $whereIn, $order_by, $offset, $limit);
  65. $list = [];
  66. if ($rst->isNotEmpty()) {
  67. foreach ($rst->toArray() as $k => $v) {
  68. $v['jobfair_title'] = '';
  69. $v['eaddtime'] = strtotime($v['created_at']);
  70. if ($v['jobfair']) {
  71. $v['jobfair_title'] = $v['jobfair']['title'];
  72. }
  73. $v['companyname'] = '';
  74. $v['company_audit'] = '';
  75. if ($v['companys']) {
  76. $v['companyname'] = $v['companys']['companyname'];
  77. $v['company_audit'] = $v['companys']['audit'];
  78. }
  79. $list[$k] = $v;
  80. }
  81. }
  82. return $list;
  83. }
  84. public function getJobfairExhibitorNums($data)
  85. {
  86. $com_ids = array_has($data, 'com_id')?$data['com_id']:0;
  87. $whereIn = [];
  88. if ($com_ids) {
  89. $ids = explode(',',$com_ids);
  90. $whereIn['company_id'] = $ids;
  91. }
  92. $rst = $this->jobfairCompanyRepository->getCrmExhibitorNum([], $whereIn);
  93. if ($rst === false) {
  94. return ['status'=>0,'msg'=>'查询失败!'];
  95. } else {
  96. return ['status'=>1,'msg'=>['total'=>$rst]];
  97. }
  98. }
  99. //审核招聘会参会企业
  100. public function auditExhibitors($data)
  101. {
  102. $id = array_has($data, 'id')?$data['id']:'';
  103. $audit = array_has($data, 'audit')?$data['audit']:'';
  104. $auditusername = array_has($data, 'auditusername')?$data['auditusername']:'CRM系统用户';
  105. $note = array_has($data, 'note')?$data['note']:'';
  106. if($audit==3){
  107. $note = ' ';
  108. }
  109. $arr = array_filter(explode(',', $id));
  110. if (empty($arr)) {
  111. return ['status'=>0, 'msg'=>'请选择参会企业'];
  112. }
  113. $arr_id = [];
  114. $JobfairCompany = JobfairCompany::whereHas('jobfair',function ($query){
  115. $query->where('holddate_end', '>', time());
  116. })->whereIn('id', $arr)->get();
  117. if($JobfairCompany->isEmpty()){
  118. return ['status'=>0, 'msg'=>'招聘会已过期'];
  119. }
  120. \DB::beginTransaction();
  121. try {
  122. foreach ($JobfairCompany as $key => $val) {
  123. if ($audit==1) { //预订成功
  124. if ($val->audit==2) {
  125. $arr_id[] = $val->id;
  126. if($val->companys->mobile && $val->companys->mobile_audit == 1){
  127. $this->smsService->sendSms(
  128. $val->companys->mobile,
  129. Smser::TEMPLATE_JOBFAIR_APPLY_OK,
  130. [
  131. 'jobfair_name'=>$val->jobfair->title,
  132. 'jobfair_time'=>date('Y-m-d H:i',$val->jobfair->holddate_start),
  133. 'jobfair_addr'=>$val->jobfair->address,
  134. 'position'=>$val->jobfairFloorPlanStands->name,
  135. ]);
  136. }
  137. if($val->companys->email && $val->companys->email_audit == 1){
  138. $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_OK,
  139. ['title'=>'招聘会预订成功'],
  140. [
  141. 'jobfair_name'=>$val->jobfair->title,
  142. 'jobfair_time'=>date('Y-m-d H:i',$val->jobfair->holddate_start),
  143. 'jobfair_addr'=>$val->jobfair->address,
  144. 'position'=>$val->jobfairFloorPlanStands->name,
  145. ]
  146. );
  147. }
  148. }
  149. } else { //审核未通过。
  150. if ($val->audit==2 || $val->audit==1) {
  151. $arr_id[] = $val->id;
  152. if($val->companys->mobile && $val->companys->mobile_audit == 1){
  153. $this->smsService->sendSms($val->companys->mobile, Smser::TEMPLATE_JOBFAIR_APPLY_ERROR, ['jobfair_name'=>$val->jobfair->title]);
  154. }
  155. if($val->companys->email && $val->companys->email_audit == 1){
  156. $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_ERROR, ['title'=>'招聘会预订失败'], ['jobfair_name'=>$val->jobfair->title]);
  157. }
  158. }
  159. if ($val->jobfair) {
  160. if ($val->pay_type==1) {//场次
  161. MembersSetmeal::where('uid', $val->company_id)->where('utype', 1)->increment('jobfair_num', $val->jobfair->jobsfair_num);
  162. } elseif ($val->pay_type==2) { //积分
  163. MembersPoint::where('uid', $val->company_id)->where('utype', 1)->increment('points', $val->jobfair->predetermined_point);
  164. MembersHandsel::create([
  165. 'uid'=>$val->company_id,
  166. 'utype'=>1,
  167. 'htype_cn'=>'返还预定招聘会的积分',
  168. 'operate'=>1,
  169. 'points'=>$val->jobfair->predetermined_point
  170. ]);
  171. }
  172. }
  173. }
  174. }
  175. if ($arr_id) {
  176. $newReult = JobfairCompany::with(['jobfair','companys'])->whereHas('jobfair')->whereHas('companys')->whereIn('id', $arr_id)->get();
  177. foreach ($newReult as $key => $val) {
  178. if ($val->jobfair && $val->companys) {
  179. $newDate[$key]['utype'] = $val->companys->utype;
  180. $newDate[$key]['msgtype'] = 2;
  181. $newDate[$key]['msgfromuid'] = 0;
  182. $newDate[$key]['msgfrom'] = $auditusername;
  183. $newDate[$key]['msgtoname'] = $val->companys->username;
  184. $newDate[$key]['msgtouid'] = $val->companys->id;
  185. $title = strstr($val->jobfair->title, '招聘会') ? $val->jobfair->title : $val->jobfair->title.'招聘会';
  186. if ($audit==1) {
  187. $newDate[$key]['message'] = '您申请的<a href="'.route('jobfair.show',$val->jobfair->id).'">'.$title.'</a>'.$val->position.'展位已审核通过,请尽快提交招聘会职位。';
  188. } else {
  189. $newDate[$key]['message'] = '您申请的<a href="'.route('jobfair.show',$val->jobfair->id).'">'.$title.'</a>'.$val->position.'展位已审核失败,请尽快查收。';
  190. }
  191. $newDate[$key]['created_at'] = date('Y-m-d H:i:s');
  192. $newDate[$key]['updated_at'] = date('Y-m-d H:i:s');
  193. }
  194. }
  195. if ($newDate) {
  196. Pms::insert($newDate);
  197. }
  198. JobfairCompany::whereIn('id', $arr_id)->update(['audit'=>$audit,'note'=>$note]);
  199. }else{
  200. return ['status'=>0, 'msg'=>'不能审核审核未通过的预定信息'];
  201. }
  202. \DB::commit();
  203. return ['status'=>1, 'msg'=>'审核成功'];
  204. } catch (\Exception $e) {
  205. \DB::rollback();
  206. return ['status'=>0, 'msg'=>'审核失败'];
  207. }
  208. }
  209. //获取招聘会职位
  210. public function getJobs($data)
  211. {
  212. $map = [];
  213. $whereIn =[];
  214. $company_id = array_has($data, 'com_uid')?$data['com_uid']:0;
  215. $audit = array_has($data, 'audit')?$data['audit']:0;
  216. if ($company_id) {
  217. $company_ids = array_filter(explode(',', $company_id));
  218. $whereIn['company_id'] = $company_ids;
  219. }
  220. if ($audit) {
  221. $map[] = ['audit', '=', $audit];
  222. }
  223. $map[] = ['type', '=', 1];
  224. $limit = array_has($data, 'limit')?$data['limit']:'';
  225. $offset = array_has($data, 'offset')?$data['offset']:'';
  226. $order_by = 'FIELD(audit, 2,1,3), updated_at desc';
  227. $rst = $this->jobfairJobRepository->getCrmJobs($map, $whereIn, $order_by, $offset, $limit);
  228. if ($rst->isNotempty()) {
  229. foreach ($rst as $k => $v) {
  230. $rst[$k]->company_audit = $v->company->audit;
  231. $rst[$k]->minwage = $v->wage_min;
  232. $rst[$k]->addtime = strtotime($v->created_at);
  233. $rst[$k]->companyname = $v->company_name;
  234. }
  235. }
  236. return $rst;
  237. }
  238. //获取招聘会职位数量
  239. public function getJobNums($map, $whereIn)
  240. {
  241. $where[] = ['type', '=', 1];
  242. $rst = $this->jobfairJobRepository->getCrmJobCount($where, $whereIn);
  243. return $rst;
  244. }
  245. //获取招聘会详细信息
  246. public function getJobfairInfo($where)
  247. {
  248. $rst = $this->jobfairRepository->getOneOpenJobfair($where);
  249. if ($rst) {
  250. $rst->c_name = '';
  251. if ($rst->jobfair_type == 1) {
  252. $rst->c_name = '现场招聘会';
  253. } elseif ($rst->jobfair_type == 2) {
  254. $rst->c_name = '赴外招聘';
  255. } elseif ($rst->jobfair_type == 3) {
  256. $rst->c_name = '高校专场';
  257. }
  258. if ($rst->is_commonweal == 3) {
  259. $rst->predetermined_point = '';
  260. $rst->jobsfair_num = '';
  261. }
  262. }
  263. return $rst;
  264. }
  265. //获取招聘会职位详细信息
  266. public function getJobInfo($id)
  267. {
  268. $info = $this->jobfairJobRepository->getCrmInfo(['id'=>$id]);
  269. if (!$info) {
  270. return ['status'=>0, 'msg'=>'没有找到对应的职位!'];
  271. }
  272. $info->companyname = $info->company_name;
  273. if ($info->company) {
  274. $info->companyname = $info->company->companyname;
  275. }
  276. $info->user = $info->company;
  277. $info->contents = $info->jobs_content;
  278. $info->addtime = strtotime($info->created_at);
  279. $info->refreshtime = strtotime($info->updated_at);
  280. if ($info->wage == -1) {
  281. $info->negotiable = 1;
  282. }
  283. $info->minwage = $info->wage_min;
  284. $info->maxwage = $info->wage_max;
  285. //职位类别
  286. $category_cn = '';
  287. if ($info->subclass) {
  288. $category_cn = get_job_category($info->subclass);
  289. } elseif ($info->category) {
  290. $category_cn = get_job_category($info->category);
  291. }
  292. $info->category_cn = $category_cn;
  293. $info->education_cn = $info->education_cn?$info->education_cn:'不限'; //学历要求
  294. $info->experience_cn = $info->experience_cn?$info->experience_cn:'不限'; //工作经验
  295. //年龄要求
  296. $info->minage = 0;
  297. $info->maxage = 0;
  298. $age = explode('-', $info->age);
  299. if ($age[0]) {
  300. $info->minage = $age[0];
  301. }
  302. if (count($age)>1 && $age[1]) {
  303. $info->maxage = $age[1];
  304. }
  305. //处理固定电话
  306. $tels =[];
  307. if ($info->contact) {
  308. $info->contact->telephone = $info->contact->mobile;
  309. $tel_arr = explode('-', $info->contact->landline_tel);
  310. if ($tel_arr) {
  311. if (implode('', $tel_arr)) {
  312. foreach ($tel_arr as $k => $v) {
  313. if ($v == '') {
  314. unset($tel_arr[$k]);
  315. }
  316. }
  317. }
  318. $tels = $tel_arr;
  319. }
  320. }
  321. $info->telarray = $tels;
  322. return ['status'=>1, 'msg'=>$info];
  323. }
  324. public function auditJobs($data)
  325. {
  326. $ids = '';
  327. if (array_has($data, 'id')) {
  328. $ids = $data['id'];
  329. }
  330. if (!$ids) {
  331. return ['status'=>0,'msg'=>'请选择要审核的职位'];
  332. }
  333. $audit = array_has($data, 'audit')?$data['audit']:2;
  334. $remark = '';
  335. $auditusername = array_has($data, 'auditusername')?$data['auditusername']:'CRM业务员';
  336. $arr = array_filter(explode(',', $ids));
  337. $result = JobfairJob::whereIn('id', $arr)->update(['audit'=>$audit]);
  338. //审核成功后同步参展职位
  339. if($audit == 1){
  340. $put_jobs = JobfairPutJob::whereHas('jobfairs',function ($query){
  341. $query->where('holddate_end','>=',time());
  342. })->whereIn('job_id',$arr)->get();
  343. if($put_jobs->isNotEmpty()){
  344. foreach ($put_jobs as $val){
  345. $jobfairJob = JobfairJob::find($val->job_id);
  346. $val['jobs_name'] = $jobfairJob['jobs_name'];
  347. $val['company_id'] = $jobfairJob['company_id'];
  348. $val['company_name'] = $jobfairJob['company_name'];
  349. $val['company_audit'] = $jobfairJob['company_audit'];
  350. $val['stick'] = $jobfairJob['stick'];
  351. $val['nature'] = $jobfairJob['nature'];
  352. $val['nature_cn'] = $jobfairJob['nature_cn'];
  353. $val['sex'] = $jobfairJob['sex'];
  354. $val['sex_cn'] = $jobfairJob['sex_cn'];
  355. $val['age'] = $jobfairJob['age'];
  356. $val['amount'] = $jobfairJob['amount'];
  357. $val['topclass'] = $jobfairJob['topclass'];
  358. $val['category'] = $jobfairJob['category'];
  359. $val['subclass'] = $jobfairJob['subclass'];
  360. $val['category_cn'] = $jobfairJob['category_cn'];
  361. $val['trade'] = $jobfairJob['trade'];
  362. $val['trade_cn'] = $jobfairJob['trade_cn'];
  363. $val['scale'] = $jobfairJob['scale'];
  364. $val['scale_cn'] = $jobfairJob['scale_cn'];
  365. $val['district'] = $jobfairJob['district'];
  366. $val['district_cn'] = $jobfairJob['district_cn'];
  367. $val['tag'] = $jobfairJob['tag'];
  368. $val['tag_cn'] = $jobfairJob['tag_cn'];
  369. $val['education'] = $jobfairJob['education'];
  370. $val['education_cn'] = $jobfairJob['education_cn'];
  371. $val['experience'] = $jobfairJob['experience'];
  372. $val['experience_cn'] = $jobfairJob['experience_cn'];
  373. $val['wage'] = $jobfairJob['wage'];
  374. $val['wage_min'] = $jobfairJob['wage_min'];
  375. $val['wage_max'] = $jobfairJob['wage_max'];
  376. $val['wage_cn'] = $jobfairJob['wage_cn'];
  377. $val['negotiable'] = $jobfairJob['negotiable'];
  378. $val['audit'] = $jobfairJob['audit'];
  379. $val['display'] = $jobfairJob['display'];
  380. $val['click'] = $jobfairJob['click'];
  381. $val['robot'] = $jobfairJob['robot'];
  382. $val['map_x'] = $jobfairJob['map_x'];
  383. $val['map_y'] = $jobfairJob['map_y'];
  384. $val['map_zoom'] = $jobfairJob['map_zoom'];
  385. $val['add_mode'] = $jobfairJob['add_mode'];
  386. $val['is_entrust'] = $jobfairJob['is_entrust'];
  387. $val['department'] = $jobfairJob['department'];
  388. $val['major'] = $jobfairJob['major'];
  389. $val['major_cn'] = $jobfairJob['major_cn'];
  390. $val['zcid'] = $jobfairJob['zcid'];
  391. $val['zc_cn'] = $jobfairJob['zc_cn'];
  392. $val['zc_name'] = $jobfairJob['zc_name'];
  393. $val->save();
  394. }
  395. }
  396. $cache_jobs = JobfairPutJob::whereIn('job_id', $arr)->whereHas('jobfairs',function ($query){
  397. $query->where([['holddate_start', '<', strtotime("+60 minute")], ['holddate_end', '>', time()]]);
  398. })->get();
  399. foreach ($cache_jobs as $v){
  400. Cache::put($v->jobfair_id.'-'.$v->company_id, time(),72000);
  401. }
  402. }
  403. $data=[];
  404. foreach ($arr as $k => $v) {
  405. $data[$k]['type'] = 11;
  406. $data[$k]['type_id'] = $v;
  407. $data[$k]['status'] = $audit;
  408. $data[$k]['reason'] = $remark;
  409. $data[$k]['audit_man'] = $auditusername;
  410. $data[$k]['created_at'] = date('Y-m-d H:i:s', time());
  411. $data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  412. }
  413. AuditReason::insert($data);
  414. if ($audit==3) {
  415. $stat='审核不通过';
  416. } elseif ($audit==1) {
  417. $stat = '审核通过';
  418. } else {
  419. $stat='待审核';
  420. }
  421. $reus=JobfairJob::whereIn('id', $arr)->get();
  422. $ds = [];
  423. foreach ($reus as $k => $v) {
  424. $ds[$k]['utype'] = 1;
  425. $ds[$k]['msgtype'] = 1;
  426. $ds[$k]['msgfromuid'] = 0;
  427. $ds[$k]['msgfrom'] = $auditusername;
  428. $ds[$k]['msgtoname'] = $v->company_name ? $v->company_name : 'admin';
  429. $ds[$k]['msgtouid'] = $v->company_id ? $v->company_id : 0;
  430. $ds[$k]['message'] = $remark ? '招聘会职位(id:'.array_values($arr)[$k].')'.$stat.'<备注:'.$remark.'>' : '招聘会职位(id:'.array_values($arr)[$k].')'.$stat;
  431. $ds[$k]['created_at'] = date('Y-m-d H:i:s', time());
  432. $ds[$k]['updated_at'] = date('Y-m-d H:i:s', time());
  433. }
  434. Pms::insert($ds);
  435. //TODO 邮件通知、短信通知、管理员操作日志
  436. if ($result) {
  437. return ['status'=>1,'msg'=>'审核成功'];
  438. } else {
  439. return ['status'=>0,'msg'=>'审核失败'];
  440. }
  441. }
  442. }