| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459 | 
							- <?php
 
- namespace App\Services\Crm;
 
- use App\Exceptions\ResponseException;
 
- use Exception;
 
- use Illuminate\Support\Facades\DB;
 
- use Illuminate\Support\Facades\Cache;
 
- use App\Repositories\Jobfair\JobfairRepository;
 
- use App\Repositories\Jobfair\JobfairFloorplanStandRepository;
 
- use App\Repositories\Jobfair\JobfairCompanyRepository;
 
- use App\Repositories\Jobfair\JobfairPutJobRepository;
 
- use App\Repositories\Jobfair\JobfairJobRepository;
 
- use App\Models\Jobfair\JobfairCompany;
 
- use App\Services\Common\SmsService;
 
- use App\Services\Common\EmailService;
 
- use Aix\Sms\Contracts\Smser;
 
- use Encore\Admin\Facades\Admin;
 
- use App\Models\Pms;
 
- use App\Models\MembersHandsel;
 
- use App\Models\MembersPoint;
 
- use App\Models\MembersSetmeal;
 
- use App\Models\Jobfair\JobfairJob;
 
- use App\Models\Jobfair\JobfairPutJob;
 
- use App\Models\AuditReason;
 
- class JobfairService
 
- {
 
-     protected $jobfairRepository;
 
-     protected $jobfairFloorplanStandRepository;
 
-     protected $jobfairCompanyRepository;
 
-     protected $jobfairPutJobRepository;
 
-     protected $jobfairJobRepository;
 
-     protected $smsService;
 
-     protected $emailService;
 
-     /**
 
-      * JobfairService constructor.
 
-      */
 
-     public function __construct(
 
-         JobfairRepository $jobfairRepository,
 
-         JobfairFloorplanStandRepository $jobfairFloorplanStandRepository,
 
-         JobfairCompanyRepository $jobfairCompanyRepository,
 
-         JobfairPutJobRepository $jobfairPutJobRepository,
 
-         JobfairJobRepository $jobfairJobRepository,
 
-         SmsService $smsService,
 
-         EmailService $emailService
 
-     )
 
-     {
 
-         $this->jobfairRepository               = $jobfairRepository;
 
-         $this->jobfairFloorplanStandRepository = $jobfairFloorplanStandRepository;
 
-         $this->jobfairCompanyRepository        = $jobfairCompanyRepository;
 
-         $this->jobfairPutJobRepository         = $jobfairPutJobRepository;
 
-         $this->jobfairJobRepository            = $jobfairJobRepository;
 
-         $this->smsService                      = $smsService;
 
-         $this->emailService                    = $emailService;
 
-     }
 
-     public function getJobfairExhibitors($com_ids, $data)
 
-     {
 
-         $whereIn = [];
 
-         if ($com_ids) {
 
-             $ids = explode(',',$com_ids);
 
-             $whereIn['company_id'] = $ids;
 
-         }
 
-         $order_by = 'FIELD(audit, 2,1,3), updated_at desc';
 
-         $limit = array_has($data, 'limit')?$data['limit']:'';
 
-         $offset = array_has($data, 'offset')?$data['offset']:'';
 
-         $rst = $this->jobfairCompanyRepository->getCrmJobfairExhibitors([], $whereIn, $order_by, $offset, $limit);
 
-         $list = [];
 
-         if ($rst->isNotEmpty()) {
 
-             foreach ($rst->toArray() as $k => $v) {
 
-                 $v['jobfair_title'] = '';
 
-                 $v['eaddtime']      = strtotime($v['created_at']);
 
-                 if ($v['jobfair']) {
 
-                     $v['jobfair_title'] = $v['jobfair']['title'];
 
-                 }
 
-                 $v['companyname'] = '';
 
-                 $v['company_audit'] = '';
 
-                 if ($v['companys']) {
 
-                     $v['companyname'] = $v['companys']['companyname'];
 
-                     $v['company_audit'] = $v['companys']['audit'];
 
-                 }
 
-                 $list[$k] = $v;
 
-             }
 
-         }
 
-         return $list;
 
-     }
 
-     public function getJobfairExhibitorNums($data)
 
-     {
 
-         $com_ids = array_has($data, 'com_id')?$data['com_id']:0;
 
-         $whereIn = [];
 
-         if ($com_ids) {
 
-             $ids = explode(',',$com_ids);
 
-             $whereIn['company_id'] = $ids;
 
-         }
 
-         $rst = $this->jobfairCompanyRepository->getCrmExhibitorNum([], $whereIn);
 
-         if ($rst === false) {
 
-             return ['status'=>0,'msg'=>'查询失败!'];
 
-         } else {
 
-             return ['status'=>1,'msg'=>['total'=>$rst]];
 
-         }
 
-     }
 
-     //审核招聘会参会企业
 
-     public function auditExhibitors($data)
 
-     {
 
-         $id = array_has($data, 'id')?$data['id']:'';
 
-         $audit = array_has($data, 'audit')?$data['audit']:'';
 
-         $auditusername = array_has($data, 'auditusername')?$data['auditusername']:'CRM系统用户';
 
-         $note = array_has($data, 'note')?$data['note']:'';
 
-         if($audit==3){
 
-             $note = ' ';
 
-         }
 
-         $arr = array_filter(explode(',', $id));
 
-         if (empty($arr)) {
 
-             return ['status'=>0, 'msg'=>'请选择参会企业'];
 
-         }
 
-         $arr_id = [];
 
-         $JobfairCompany = JobfairCompany::whereHas('jobfair',function ($query){
 
-             $query->where('holddate_end', '>', time());
 
-         })->whereIn('id', $arr)->get();
 
-         if($JobfairCompany->isEmpty()){
 
-             return ['status'=>0, 'msg'=>'招聘会已过期'];
 
-         }
 
-         \DB::beginTransaction();
 
-         try {
 
-             foreach ($JobfairCompany as $key => $val) {
 
-                 if ($audit==1) { //预订成功
 
-                     if ($val->audit==2) {
 
-                         $arr_id[] = $val->id;
 
-                         if($val->companys->mobile && $val->companys->mobile_audit == 1){
 
-                             $this->smsService->sendSms(
 
-                                 $val->companys->mobile,
 
-                                 Smser::TEMPLATE_JOBFAIR_APPLY_OK,
 
-                                 [
 
-                                     'jobfair_name'=>$val->jobfair->title,
 
-                                     'jobfair_time'=>date('Y-m-d H:i',$val->jobfair->holddate_start),
 
-                                     'jobfair_addr'=>$val->jobfair->address,
 
-                                     'position'=>$val->jobfairFloorPlanStands->name,
 
-                                 ]);
 
-                         }
 
-                         if($val->companys->email && $val->companys->email_audit == 1){
 
-                             $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_OK,
 
-                                 ['title'=>'招聘会预订成功'],
 
-                                 [
 
-                                     'jobfair_name'=>$val->jobfair->title,
 
-                                     'jobfair_time'=>date('Y-m-d H:i',$val->jobfair->holddate_start),
 
-                                     'jobfair_addr'=>$val->jobfair->address,
 
-                                     'position'=>$val->jobfairFloorPlanStands->name,
 
-                                 ]
 
-                             );
 
-                         }
 
-                     }
 
-                 } else { //审核未通过。
 
-                     if ($val->audit==2 || $val->audit==1) {
 
-                         $arr_id[] = $val->id;
 
-                         if($val->companys->mobile && $val->companys->mobile_audit == 1){
 
-                             $this->smsService->sendSms($val->companys->mobile, Smser::TEMPLATE_JOBFAIR_APPLY_ERROR, ['jobfair_name'=>$val->jobfair->title]);
 
-                         }
 
-                         if($val->companys->email && $val->companys->email_audit == 1){
 
-                             $this->emailService->sendMail($val->companys->email, EmailService::TEMPLATE_JOBFAIR_APPLY_ERROR, ['title'=>'招聘会预订失败'], ['jobfair_name'=>$val->jobfair->title]);
 
-                         }
 
-                     }
 
-                     if ($val->jobfair) {
 
-                         if ($val->pay_type==1) {//场次
 
-                             MembersSetmeal::where('uid', $val->company_id)->where('utype', 1)->increment('jobfair_num', $val->jobfair->jobsfair_num);
 
-                         } elseif ($val->pay_type==2) { //积分
 
-                             MembersPoint::where('uid', $val->company_id)->where('utype', 1)->increment('points', $val->jobfair->predetermined_point);
 
-                             MembersHandsel::create([
 
-                                 'uid'=>$val->company_id,
 
-                                 'utype'=>1,
 
-                                 'htype_cn'=>'返还预定招聘会的积分',
 
-                                 'operate'=>1,
 
-                                 'points'=>$val->jobfair->predetermined_point
 
-                             ]);
 
-                         }
 
-                     }
 
-                 }
 
-             }
 
-             if ($arr_id) {
 
-                 $newReult = JobfairCompany::with(['jobfair','companys'])->whereHas('jobfair')->whereHas('companys')->whereIn('id', $arr_id)->get();
 
-                 foreach ($newReult as $key => $val) {
 
-                     if ($val->jobfair && $val->companys) {
 
-                         $newDate[$key]['utype']      = $val->companys->utype;
 
-                         $newDate[$key]['msgtype']    = 2;
 
-                         $newDate[$key]['msgfromuid'] = 0;
 
-                         $newDate[$key]['msgfrom']    = $auditusername;
 
-                         $newDate[$key]['msgtoname']  = $val->companys->username;
 
-                         $newDate[$key]['msgtouid']   = $val->companys->id;
 
-                         $title = strstr($val->jobfair->title, '招聘会') ? $val->jobfair->title : $val->jobfair->title.'招聘会';
 
-                         if ($audit==1) {
 
-                             $newDate[$key]['message'] = '您申请的<a href="'.route('jobfair.show',$val->jobfair->id).'">'.$title.'</a>'.$val->position.'展位已审核通过,请尽快提交招聘会职位。';
 
-                         } else {
 
-                             $newDate[$key]['message'] = '您申请的<a href="'.route('jobfair.show',$val->jobfair->id).'">'.$title.'</a>'.$val->position.'展位已审核失败,请尽快查收。';
 
-                         }
 
-                         $newDate[$key]['created_at'] = date('Y-m-d H:i:s');
 
-                         $newDate[$key]['updated_at'] = date('Y-m-d H:i:s');
 
-                     }
 
-                 }
 
-                 if ($newDate) {
 
-                     Pms::insert($newDate);
 
-                 }
 
-                 JobfairCompany::whereIn('id', $arr_id)->update(['audit'=>$audit,'note'=>$note]);
 
-             }else{
 
-                 return ['status'=>0, 'msg'=>'不能审核审核未通过的预定信息'];
 
-             }
 
-             \DB::commit();
 
-             return ['status'=>1, 'msg'=>'审核成功'];
 
-         } catch (\Exception $e) {
 
-             \DB::rollback();
 
-             return ['status'=>0, 'msg'=>'审核失败'];
 
-         }
 
-     }
 
-     //获取招聘会职位
 
-     public function getJobs($data)
 
-     {
 
-         $map = [];
 
-         $whereIn =[];
 
-         $company_id = array_has($data, 'com_uid')?$data['com_uid']:0;
 
-         $audit = array_has($data, 'audit')?$data['audit']:0;
 
-         if ($company_id) {
 
-             $company_ids = array_filter(explode(',', $company_id));
 
-             $whereIn['company_id'] = $company_ids;
 
-         }
 
-         if ($audit) {
 
-             $map[] = ['audit', '=', $audit];
 
-         }
 
-         $map[] = ['type', '=', 1];
 
-         $limit = array_has($data, 'limit')?$data['limit']:'';
 
-         $offset = array_has($data, 'offset')?$data['offset']:'';
 
-         $order_by = 'FIELD(audit, 2,1,3), updated_at desc';
 
-         $rst = $this->jobfairJobRepository->getCrmJobs($map, $whereIn, $order_by, $offset, $limit);
 
-         if ($rst->isNotempty()) {
 
-             foreach ($rst as $k => $v) {
 
-                 $rst[$k]->company_audit = $v->company->audit;
 
-                 $rst[$k]->minwage       = $v->wage_min;
 
-                 $rst[$k]->addtime       = strtotime($v->created_at);
 
-                 $rst[$k]->companyname  = $v->company_name;
 
-             }
 
-         }
 
-         return $rst;
 
-     }
 
-     //获取招聘会职位数量
 
-     public function getJobNums($map, $whereIn)
 
-     {
 
-         $where[] = ['type', '=', 1];
 
-         $rst = $this->jobfairJobRepository->getCrmJobCount($where, $whereIn);
 
-         return $rst;
 
-     }
 
-     //获取招聘会详细信息
 
-     public function getJobfairInfo($where)
 
-     {
 
-         $rst = $this->jobfairRepository->getOneOpenJobfair($where);
 
-         if ($rst) {
 
-             $rst->c_name = '';
 
-             if ($rst->jobfair_type == 1) {
 
-                 $rst->c_name = '现场招聘会';
 
-             } elseif ($rst->jobfair_type == 2) {
 
-                 $rst->c_name = '赴外招聘';
 
-             } elseif ($rst->jobfair_type == 3) {
 
-                 $rst->c_name = '高校专场';
 
-             }
 
-             if ($rst->is_commonweal == 3) {
 
-                 $rst->predetermined_point = '';
 
-                 $rst->jobsfair_num        = '';
 
-             }
 
-         }
 
-         return $rst;
 
-     }
 
-     //获取招聘会职位详细信息
 
-     public function getJobInfo($id)
 
-     {
 
-         $info = $this->jobfairJobRepository->getCrmInfo(['id'=>$id]);
 
-         if (!$info) {
 
-             return ['status'=>0, 'msg'=>'没有找到对应的职位!'];
 
-         }
 
-         $info->companyname = $info->company_name;
 
-         if ($info->company) {
 
-             $info->companyname = $info->company->companyname;
 
-         }
 
-         $info->user        = $info->company;
 
-         $info->contents    = $info->jobs_content;
 
-         $info->addtime     = strtotime($info->created_at);
 
-         $info->refreshtime = strtotime($info->updated_at);
 
-         if ($info->wage == -1) {
 
-             $info->negotiable = 1;
 
-         }
 
-         $info->minwage = $info->wage_min;
 
-         $info->maxwage = $info->wage_max;
 
-         //职位类别
 
-         $category_cn = '';
 
-         if ($info->subclass) {
 
-             $category_cn = get_job_category($info->subclass);
 
-         } elseif ($info->category) {
 
-             $category_cn = get_job_category($info->category);
 
-         }
 
-         $info->category_cn = $category_cn;
 
-         $info->education_cn = $info->education_cn?$info->education_cn:'不限';  //学历要求
 
-         $info->experience_cn = $info->experience_cn?$info->experience_cn:'不限';  //工作经验
 
-         //年龄要求
 
-         $info->minage = 0;
 
-         $info->maxage = 0;
 
-         $age = explode('-', $info->age);
 
-         if ($age[0]) {
 
-             $info->minage = $age[0];
 
-         }
 
-         if (count($age)>1 && $age[1]) {
 
-             $info->maxage = $age[1];
 
-         }
 
-         //处理固定电话
 
-         $tels =[];
 
-         if ($info->contact) {
 
-             $info->contact->telephone = $info->contact->mobile;
 
-             $tel_arr = explode('-', $info->contact->landline_tel);
 
-             if ($tel_arr) {
 
-                 if (implode('', $tel_arr)) {
 
-                     foreach ($tel_arr as $k => $v) {
 
-                         if ($v == '') {
 
-                             unset($tel_arr[$k]);
 
-                         }
 
-                     }
 
-                 }
 
-                 $tels = $tel_arr;
 
-             }
 
-         }
 
-         $info->telarray = $tels;
 
-         return ['status'=>1, 'msg'=>$info];
 
-     }
 
-     public function auditJobs($data)
 
-     {
 
-         $ids = '';
 
-         if (array_has($data, 'id')) {
 
-             $ids = $data['id'];
 
-         }
 
-         if (!$ids) {
 
-             return ['status'=>0,'msg'=>'请选择要审核的职位'];
 
-         }
 
-         $audit = array_has($data, 'audit')?$data['audit']:2;
 
-         $remark = '';
 
-         $auditusername = array_has($data, 'auditusername')?$data['auditusername']:'CRM业务员';
 
-         $arr = array_filter(explode(',', $ids));
 
-         $result = JobfairJob::whereIn('id', $arr)->update(['audit'=>$audit]);
 
-         //审核成功后同步参展职位
 
-         if($audit == 1){
 
-             $put_jobs = JobfairPutJob::whereHas('jobfairs',function ($query){
 
-                 $query->where('holddate_end','>=',time());
 
-             })->whereIn('job_id',$arr)->get();
 
-             if($put_jobs->isNotEmpty()){
 
-                 foreach ($put_jobs as $val){
 
-                     $jobfairJob = JobfairJob::find($val->job_id);
 
-                     $val['jobs_name'] = $jobfairJob['jobs_name'];
 
-                     $val['company_id'] = $jobfairJob['company_id'];
 
-                     $val['company_name'] = $jobfairJob['company_name'];
 
-                     $val['company_audit'] = $jobfairJob['company_audit'];
 
-                     $val['stick'] = $jobfairJob['stick'];
 
-                     $val['nature'] = $jobfairJob['nature'];
 
-                     $val['nature_cn'] = $jobfairJob['nature_cn'];
 
-                     $val['sex'] = $jobfairJob['sex'];
 
-                     $val['sex_cn'] = $jobfairJob['sex_cn'];
 
-                     $val['age'] = $jobfairJob['age'];
 
-                     $val['amount'] = $jobfairJob['amount'];
 
-                     $val['topclass'] = $jobfairJob['topclass'];
 
-                     $val['category'] = $jobfairJob['category'];
 
-                     $val['subclass'] = $jobfairJob['subclass'];
 
-                     $val['category_cn'] = $jobfairJob['category_cn'];
 
-                     $val['trade'] = $jobfairJob['trade'];
 
-                     $val['trade_cn'] = $jobfairJob['trade_cn'];
 
-                     $val['scale'] = $jobfairJob['scale'];
 
-                     $val['scale_cn'] = $jobfairJob['scale_cn'];
 
-                     $val['district'] = $jobfairJob['district'];
 
-                     $val['district_cn'] = $jobfairJob['district_cn'];
 
-                     $val['tag'] = $jobfairJob['tag'];
 
-                     $val['tag_cn'] = $jobfairJob['tag_cn'];
 
-                     $val['education'] = $jobfairJob['education'];
 
-                     $val['education_cn'] = $jobfairJob['education_cn'];
 
-                     $val['experience'] = $jobfairJob['experience'];
 
-                     $val['experience_cn'] = $jobfairJob['experience_cn'];
 
-                     $val['wage'] = $jobfairJob['wage'];
 
-                     $val['wage_min'] = $jobfairJob['wage_min'];
 
-                     $val['wage_max'] = $jobfairJob['wage_max'];
 
-                     $val['wage_cn'] = $jobfairJob['wage_cn'];
 
-                     $val['negotiable'] = $jobfairJob['negotiable'];
 
-                     $val['audit'] = $jobfairJob['audit'];
 
-                     $val['display'] = $jobfairJob['display'];
 
-                     $val['click'] = $jobfairJob['click'];
 
-                     $val['robot'] = $jobfairJob['robot'];
 
-                     $val['map_x'] = $jobfairJob['map_x'];
 
-                     $val['map_y'] = $jobfairJob['map_y'];
 
-                     $val['map_zoom'] = $jobfairJob['map_zoom'];
 
-                     $val['add_mode'] = $jobfairJob['add_mode'];
 
-                     $val['is_entrust'] = $jobfairJob['is_entrust'];
 
-                     $val['department'] = $jobfairJob['department'];
 
-                     $val['major'] = $jobfairJob['major'];
 
-                     $val['major_cn'] = $jobfairJob['major_cn'];
 
-                     $val['zcid'] = $jobfairJob['zcid'];
 
-                     $val['zc_cn'] = $jobfairJob['zc_cn'];
 
-                     $val['zc_name'] = $jobfairJob['zc_name'];
 
-                     $val->save();
 
-                 }
 
-             }
 
-             $cache_jobs = JobfairPutJob::whereIn('job_id', $arr)->whereHas('jobfairs',function ($query){
 
-                 $query->where([['holddate_start', '<', strtotime("+60 minute")], ['holddate_end', '>', time()]]);
 
-             })->get();
 
-             foreach ($cache_jobs as $v){
 
-                 Cache::put($v->jobfair_id.'-'.$v->company_id, time(),72000);
 
-             }
 
-         }
 
-         $data=[];
 
-         foreach ($arr as $k => $v) {
 
-             $data[$k]['type'] = 11;
 
-             $data[$k]['type_id'] = $v;
 
-             $data[$k]['status'] = $audit;
 
-             $data[$k]['reason'] = $remark;
 
-             $data[$k]['audit_man'] = $auditusername;
 
-             $data[$k]['created_at'] = date('Y-m-d H:i:s', time());
 
-             $data[$k]['updated_at'] = date('Y-m-d H:i:s', time());
 
-         }
 
-         AuditReason::insert($data);
 
-         if ($audit==3) {
 
-             $stat='审核不通过';
 
-         } elseif ($audit==1) {
 
-             $stat = '审核通过';
 
-         } else {
 
-             $stat='待审核';
 
-         }
 
-         $reus=JobfairJob::whereIn('id', $arr)->get();
 
-         $ds = [];
 
-         foreach ($reus as $k => $v) {
 
-             $ds[$k]['utype'] = 1;
 
-             $ds[$k]['msgtype'] = 1;
 
-             $ds[$k]['msgfromuid'] = 0;
 
-             $ds[$k]['msgfrom'] = $auditusername;
 
-             $ds[$k]['msgtoname'] = $v->company_name ? $v->company_name : 'admin';
 
-             $ds[$k]['msgtouid'] = $v->company_id ? $v->company_id : 0;
 
-             $ds[$k]['message'] =  $remark ? '招聘会职位(id:'.array_values($arr)[$k].')'.$stat.'<备注:'.$remark.'>' : '招聘会职位(id:'.array_values($arr)[$k].')'.$stat;
 
-             $ds[$k]['created_at'] = date('Y-m-d H:i:s', time());
 
-             $ds[$k]['updated_at'] = date('Y-m-d H:i:s', time());
 
-         }
 
-         Pms::insert($ds);
 
-         //TODO 邮件通知、短信通知、管理员操作日志
 
-         if ($result) {
 
-             return ['status'=>1,'msg'=>'审核成功'];
 
-         } else {
 
-             return ['status'=>0,'msg'=>'审核失败'];
 
-         }
 
-     }
 
- }
 
 
  |