<?php
namespace App\Http\Controllers\Mobile\Content;
use App\Http\Controllers\Mobile\MobileBaseController;
use App\Models\Ad;
use App\Models\Jobs;
use App\Repositories\CompanyRepository;
use App\Services\Common\CategoryService;
use App\Services\Company\JobsService;
use App\Services\Person\ResumeService;
use App\Services\Content\FeedbackService;
use Illuminate\Http\Request;
use App\Exceptions\ResponseException;
use App\Services\Content\ReportService;
use App\Services\Content\TaskService;
use App\Services\Company\PersonalJobsApplyService;
use App\Services\Company\CompanyService;
use App\Services\Person\PersonFavoriteService;
use App\Services\Content\AdService;
use App\Services\Common\SearchService;
use App\Services\Common\HotWordService;
use App\Validators\Content\ReportValidatorRequest;
use App\Validators\Content\MsgValidatorRequest;
use Illuminate\Support\Facades\Cache;
class JobsController extends MobileBaseController
{
protected $jobsService;
protected $resumeService;
protected $categoryService;
protected $feedbackService;
protected $reportService;
protected $taskService;
protected $personalJobsApplyService;
protected $companyService;
protected $personFavoriteService;
protected $adService;
protected $searchService;
protected $hotWordService;
/**
* JobsController constructor.
* @param $JobsService
* @param $resumeService
* @param $categoryService
* @param $feedbackService
* @param $reportService
* @param $taskService
* @param $personalJobsApplyService
* @param $companyService
* @param $personFavoriteService
* @param $adService
* @param $searchService
* @param $hotWordService
*/
public function __construct(JobsService $jobsService, ResumeService $resumeService, CategoryService $categoryService, FeedbackService $feedbackService, ReportService $reportService, TaskService $taskService, PersonalJobsApplyService $personalJobsApplyService, CompanyService $companyService, PersonFavoriteService $personFavoriteService, AdService $adService, SearchService $searchService, HotWordService $hotWordService)
{
$this->jobsService = $jobsService;
$this->resumeService = $resumeService;
$this->categoryService = $categoryService;
$this->feedbackService = $feedbackService;
$this->reportService = $reportService;
$this->taskService = $taskService;
$this->personalJobsApplyService = $personalJobsApplyService;
$this->companyService = $companyService;
$this->personFavoriteService = $personFavoriteService;
$this->adService = $adService;
$this->searchService = $searchService;
$this->hotWordService = $hotWordService;
}
public function index(Request $request)
{
if ($request->input('range-lng')!='' &&$request->input('range-lat')!='') {
$request->session()->put('range-lng', $request->input('range-lng'));
$request->session()->put('range-lat', $request->input('range-lat'));
$request->session()->put('range-laction', 1);
};
//查询条件
$citycategory = $request->input('citycategory');
$search_type = $request->input('search_type', 'jobs');
if ($search_type == 'company') {
return redirect(route('jobs.companyList', array('list_type'=>'AIX_companylist')));
} else {
session(['hotword_show_type' => 1]);
//职位搜索
$job_category = $this->categoryService->getJobsCategoryInfo(); //获取职位分类信息
$filter_where = array(
'AIX_wage' => 100,
'AIX_jobtag' => 100,
'AIX_trade' => 100,
'AIX_scale' => 100,
'AIX_jobs_nature' => 100,
'AIX_education' => 100,
'AIX_experience' => 100
);
$categories = $this->categoryService->getCategories($filter_where); //过滤条件信息
//广告位
$subsite_id = Cache::has('subsite_id')?Cache::get('subsite_id'):0;
$ad_where = array(
'theme' => 'default',
'org' => 'Home',
'alias' => 'AIX_jobs_list_right',
'num' => '1'
);
$ad_infos = $this->adService->getAds($ad_where);
$hotWords = $this->hotWordService->getHotWords(array('type'=>1), 'list_order desc,w_hot desc', '21'); //热门关键词
$job_hotwords = array_slice($hotWords->toArray(), 0, 10);
$company_hotwords = $this->hotWordService->getHotWords(array('type'=>2), 'list_order desc,w_hot desc', '10');
$param_array = array('citycategory','wage','jobtag','trade','scale','nature','education','experience','settr','jobcategory','key','sort', 'search_cont','license','deliver','search_type','lng','lat','range','wa','range-lng','range-lat');
$params= array();
if ($request->all()) {
foreach ($request->all() as $k => $v) {
if (in_array($k, $param_array) && $v) {
$params[$k] = $v;
}
}
}
$map_data = array();
if (array_has($params, 'lng') && array_has($params, 'lat') && (array_has($params, 'range') || array_has($params, 'wa'))) {
if (array_has($params, 'range')) {
$map_data = array('lng'=>$params['lng'],'lat'=>$params['lat'],'range'=>$params['range']);
} elseif (array_has($params, 'wa')) {
$map_data = array('lng'=>$params['lng'],'lat'=>$params['lat'],'range'=>round($params['wa']/1000, 2));
} else {
$map_data = array('lng'=>$params['lng'],'lat'=>$params['lat'],'range'=>config('aix.system.map.map.map_range'));
}
} elseif (array_has($params, 'range') && !array_has($params, 'citycategory') && session("range-laction")) {
$map_data = array('lng'=>session("range-lng"),'lat'=>session("range-lat"),'range'=>$params['range']);
}
$show_range = false;
if ($map_data) {
$show_range = true;
}
$hidden_all_result = 0;
$show_login_notice = 0;
$list_limit = '';
$order_by = array('stime'=>'desc', 'refresh_time'=>'desc');
$search_key = '';
$where = array();
if ($params) {
$search_key = array_has($params, 'key')?$params['key']:'';
if (array_has($params, 'sort')) {
if ($params['sort'] == 'rtime') {
$order_by = 'refresh_time';
} else {
$order_by = $params['sort'];
}
} else {
$order_by = array('stime'=>'desc', 'refresh_time'=>'desc');
}
}
$is_subsite = 0;
$subsites = Cache::get('subsites_list');
if ($subsites) {
if (!array_has($params, 'citycategory')) {
if (get_subsite_id() > 0) {
$citycategory = $subsites[get_subsite_id()]['district'];
}
}
$is_subsite = 1;
}
$citys = $this->categoryService->getCitys($citycategory); //获取地标地段
$district_info = $this->categoryService->getDefaultDistrictInfo(); //获取默认地区信息
$where = $this->setWhere($params, $citys, $job_category); //组合where条件
if (config('aix.companyset.search_com.search_basic.jobs_search_login')==1 && !auth('web-company')->check() && !auth('web-member')->check()) {
$need_login_params = $param_array;
if ($is_subsite ==1) {
unset($need_login_params[array_search('citycategory', $need_login_params)]);
};
foreach ($params as $k => $v) {
if (in_array($k, $need_login_params) && $v) {
$hidden_all_result = 1;
$where[] = array('id','=',0); //设置该条件使查询结果为空
break;
}
}
$show_login_notice = 1;
$list_limit = config('aix.companyset.search_com.search_basic.jobs_search_num_login');
}
$size = 20;
$list = $this->searchService->search('Job', $where, $order_by, $search_key, $size);
if ($list->total()>0) {
$list_items = $this->jobsService->dealjobFilelds($list->items(), $map_data);
} else {
$list_items = array();
}
$mobile_dropload = false;
if ($list->total() > $size) {
$mobile_dropload = true;
}
if ($request->ajax()) {
if ($list->lastPage() < $list->currentPage()) {
return response()->json(['status'=>0]);
}
return response()->json(['status'=>1,'data'=>view('mobile.app.content.jobs.ajax_job_list', ['params'=> $params,'list_items'=> $list_items])->render()]);
}
$return_data = array(
'search_type' => $search_type,
'city' => $citys,
'categories' => $categories,
'params' => $params,
'district_info' => $district_info,
'job_category' => $job_category,
'ad_info' => $ad_infos,
'hotWords' => $hotWords,
'job_hotwords' => $job_hotwords,
'company_hotwords' => $company_hotwords,
'list' => $list,
'list_items' => $list_items,
'show_login_notice' => $show_login_notice,
'hidden_all_result' => $hidden_all_result,
'limit' => $list_limit,
'mobile_dropload' => $mobile_dropload,
'show_range' => $show_range,
'current_url' => \Illuminate\Support\Facades\Request::getRequestUri(),
'wap_title' => '找工作',
'user' => $this->getUser()
);
return view('mobile.app.content.jobs.index', $return_data);
}
}
public function setWhere($params, $citys, $job_category)
{
$where = array();
//审核状态过滤
if (config('aix.companyset.comset.show_set.jobs_display')==1) {
$where[] = array('audit','=',1);
} else {
$where[] = array('audit','<>',3);
}
$where[] = array('valid','=',1);
$where[] = array('display','=',1);
if ($params) {
foreach ($params as $k => $v) {
if ($k == 'citycategory') {
//地标地段
$where[] = array('district','=',$citys['select']['id']);
} elseif ($k == 'jobcategory') {
//职位分类
if ($job_category && $v && array_get($job_category['spell'], $v)) {
if ($job_category && $v && array_get($job_category['spell'], $v)) {
$where[] = array('intention_jobs_id','=',$job_category['spell'][$v]['id']);
}
}
} elseif ($k=='jobtag') {
//职位亮点
$where[] = array('tag', '=',$v);
} elseif ($k=='search_cont') {
if ($v=='setmeal') {
//名企招聘
$where[] = array('setmeal_id', '>',1);
}
} elseif ($k=='license') {
//营业执照
$where[] = array('company.certificate_img_audit', '=',1);
} elseif ($k =='settr') {
//更新时间
$update_time = date('Y-m-d H:i:s', strtotime(date('Y-m-d', strtotime('-'.$v.' day'))));
$where[] = array('updated_at', '>=',$update_time);
} elseif ($k == 'deliver') {
$where['apply'] = $v;
} elseif ($k =='wa') {
$where[] = array('range', '=',round($params['wa']/1000, 2));
if (!(array_has($params, 'lng')&& array_has($params, 'lat'))) {
$where[] = array('lng', '=', subsite_config('aix.system.map.map.map_x'));
$where[] = array('lat', '=', subsite_config('aix.system.map.map.map_y'));
}
} elseif ($k =='wage') {
//获取薪资最大值和最小值
$filter_where = array( 'AIX_wage'=> 100);
$categories = $this->categoryService->getCategories($filter_where);
if ($categories) {
$wage = $categories['AIX_wage'][$params['wage']]['origin_demand'];
if ($wage) {
$wage = format_wage($wage);
}
$wage_arr = explode_wage($wage);
$where[] = $wage_arr[0];
$where[] = $wage_arr[1];
}
} elseif ($k =='range') {
if (!array_has($params, 'citycategory')) {
if (!(array_has($params, 'lng')&& array_has($params, 'lat'))) {
if (session('range-laction')) {
$where[] = array('range', '=',$params['range']);
$where[] = array('lng', '=', session('range-lng'));
$where[] = array('lat', '=', session('range-lat'));
}
}
}
} elseif ($k !='sort' && $k !='key' && $k !='search_type' && $k !='m_zoom'&& $k !='range-lng'&& $k !='range-lat') {
$where[] = array($k, '=', $v);
}
}
}
$where[] = ['subsite_ids','=', get_subsite_id()];
return $where;
}
public function category()
{
session(['hotword_show_type' => 1]);
$serch_type = null;
$district_info = $this->categoryService->getDefaultDistrictInfo();
//获取职位分类信息
$job_cates = $this->categoryService->getJobsCategories();
$citys = $this->categoryService->getCitys();
$job_hotwords = $this->hotWordService->getHotWords(array('type'=>1), 'list_order desc,w_hot desc', '10');
$company_hotwords = $this->hotWordService->getHotWords(array('type'=>2), 'list_order desc,w_hot desc', '10');
$return_data = array(
'search_type' => $serch_type,
'city' => $citys,
'district_info' => $district_info,
'job_hotwords' => $job_hotwords,
'company_hotwords' => $company_hotwords,
'job_cates' => $job_cates
);
return view('app.content.jobs.category', $return_data);
}
public function hotWord(Request $request)
{
$key = $request->input('query', '');
$key = trim($key);
if (!$key) {
return response()->json(array('status'=>0,'msg'=>'请输入关健字!'));
}
}
public function getUser()
{
$user = array();
if (auth('web-member')->check()) {
$user = auth('web-member')->user();
} elseif (auth('web-company')->check()) {
$user = auth('web-company')->user();
}
return $user;
}
/*public function getCateJobs($job, $limit = '')
{
$cate_jobs = array();
$cate_job_where[] = array('intention_jobs_id','=',$job->jobcategory_id);
$cate_job_where[] = array('id','<>',$job->id);
if (config('aix.companyset.comset.show_set.jobs_display')==1) {
$cate_job_where[] = array('audit','=',1);
} else {
$cate_job_where[] = array('audit','<>',3);
}
$cate_job_where[] = array('display','=',1);
$cate_job_where[] = array('valid','=',1);
$cate_job_where[] = array('subsite_ids','=',get_subsite_id());
$cate_job_list = $this->searchService->search('Job', $cate_job_where, 'stime', '');
if ($cate_job_list->total()>0) {
$cate_jobs = $this->jobsService->dealjobList($cate_job_list->items(), 6);
}
return $cate_jobs;
}*/
public function show(Request $request)
{
$job_id = $request->input('id');
$job_rst = $this->jobsService->getJobInfo(array('id'=>$job_id), $this->getUser()); //获取job信息
if ($job_rst['status'] == 0) {
$back_url = \Illuminate\Support\Facades\URL::previous();
return $this->showMessage($job_rst['error'], $back_url, true, '上一页', '3');
}
$job_info = $job_rst['job'];
$cate_jobs = $this->searchService->searchCateJobs($job_info, 6); //看了此职位的人还会看(同类别6条其它职位)
$this->putSeoData('job', $job_info);
//当前公司的其它职位
$other_where = array(
array('company_id','=',$job_info->company_id),
array('valid','=',1),
array('display','=',1),
array('id','<>',$job_id)
);
if (config('aix.companyset.comset.show_set.jobs_display')==1) {
$other_where[] = array('audit','=',1);
} else {
$other_where[] = array('audit','<>',3);
}
$other_jobs = $this->jobsService->getOtherJobs($other_where, 6);
$return_data = array(
'info' => $job_info,
'other_jobs' => $other_jobs,
'user' => $this->getUser(),
'wap_title' => $job_info->jobs_name,
'cate_jobs' => $cate_jobs
);
return view('mobile.app.content.jobs.job_show', $return_data);
}
public function click(Request $request)
{
$id = $request->input('id');
$rst = $this->jobsService->incrementData(array('id'=>$id), 1, 'click');
$data = array('status'=>0);
if ($rst) {
$data = array('status'=>1);
}
return response()->json($data);
}
/*//留言
public function sendMsg(MsgValidatorRequest $request)
{
$form_data = array(
'parent_id' => $request->input('parent_id', '0'),
'touid' => $request->input('touid'),
'message' => $request->input('message'),
'ip' => ip2long($request->getClientIp()),
'ip_address' => '本机地址'
);
$rst = $this->feedbackService->sendMsg($form_data, 3);
$data = array('status'=>0);
if ($rst) {
$data = array('status'=>1,'msg'=>'反馈成功,感谢您对本站的关注!','insert_id'=>$rst['data']['id']);
} else {
$data = array('msg'=>'数据保存失败!');
}
return response()->json($data);
}*/
//收藏职位
public function favor(Request $request)
{
$jid = $request->jid;
$reg = $this->jobsService->jobFavor($jid);
$return_data = array('status'=>0,'msg' => '收藏失败!');
if ($reg) {
if ($reg == 1) {
$return_data = array( 'status'=>1, 'msg' => '取消收藏成功!', 'data'=>'cancel');
} else {
$return_data = array( 'status'=>1, 'msg' => '收藏成功!', 'data'=>'');
}
}
return response()->json($return_data);
}
public function loginDig(Request $request)
{
$html = '';
if ($request->input('type')=='per') {
$html = view('app.common.ajax.per_login')->render();
} elseif ($request->input('type')=='com') {
$html = view('app.common.ajax.com_login')->render();
}
$return_data = array( 'status'=>1, 'html' => $html);
return response()->json($return_data);
}
//职位举报
public function report(Request $request)
{
$jobs_id = $request->input('jobs_id');
if (!$jobs_id) {
throw new ResponseException('请选择要举报的职位!');
}
$report_types = $this->reportService->getReportTypes('1');
$taskInfo = $this->taskService->getTask('2', 'report_jobs'); //举报积分信息
$page_data = array('type_arr'=>$report_types,'jobs_id'=>$jobs_id,'taskInfo'=>$taskInfo);
$html = view('app.common.ajax.report_job', $page_data)->render();
$return_data = array( 'status'=>1, 'html' => $html);
return response()->json($return_data);
}
public function reportJobs(ReportValidatorRequest $request)
{
$report_type = $request->input('report_type');
$jobs_id = $request->input('jobs_id');
$telephone = trim($request->input('telephone'));
$content = trim($request->input('content'));
if (!$content) {
throw new ResponseException('请填写备注说明!');
}
if (!$telephone) {
throw new ResponseException('请填写联系电话!');
}
//添加举报信息
$report_data = array(
'utype' => 1,
'utype_id' => $jobs_id,
'type_id' => $report_type,
'phone' => $telephone,
'content' => $content,
'audit' => 1
);
$rst = $this->reportService->addReport($report_data);
if ($rst) {
//添加会员日志
$user_info = array(
'uid' => auth('web-member')->user()->id,
'utype' =>2,
'username' => auth('web-member')->user()->username,
'ip' => ip2long($request->getClientIp()),
'log_address'=>'本机地址'
);
$this->feedbackService->addMembersLog($user_info, '2042', '投诉职位(职位id:'.$jobs_id.')');
$return_data = array( 'status'=>1, 'msg' => '投诉成功!请等待管理员核实!');
return response()->json($return_data);
} else {
throw new ResponseException('举报失败!');
}
}
//职位申请
public function apply(Request $request)
{
//判断个人资料是否完善
$jobs_id = $request->input('jobs_id');
$resume_id = $request->input('resume_id');
if (!$jobs_id) {
throw new ResponseException('请选择要投递的职位!');
}
if (!is_array($jobs_id)) {
$jobs_id = explode(',', $jobs_id);
}
if ($resume_id) {
$apply_rst = $this->personalJobsApplyService->mobileApplyJobs($jobs_id, $resume_id, $this->getUser());
return response()->json($apply_rst);
} else {
//未选择投递简历前
$rst = $this->personalJobsApplyService->ifMobileJobApply($jobs_id, $this->getUser());
if (array_get($rst, 'status') == 2) {
$page_data = array('status'=>array_get($rst, 'status'),'resumes'=>array_get($rst, 'resumes'),'def_resume'=>array_get($rst, 'def_resume'));
$html = view('mobile.app.common.ajax.apply_resume', $page_data)->render();
$return_data = array( 'status'=>2, 'html' => $html);
return response()->json($return_data);
} else {
return response()->json($rst);
}
}
}
public function jobMap(Request $request)
{
$params = $request->all();
$param_array = array('key','wage','trade','scale','nature','education','experience','settr','lng','lat','range','wa','m_zoom','search_type','sort','license',"apply",'search_cont');
$params= array();
if ($request->all()) {
foreach ($request->all() as $k => $v) {
if (in_array($k, $param_array) && $v) {
$params[$k] = $v;
}
}
}
$position_search = false;
if ($request->input('search_type')=='position') {
$position_search = true;
}
$filter_array = array('sort', 'search_cont','license','apply','search_type','key','wa','lng','lat','m_zoom');
$show_filter = $this->showFilter($params, $filter_array);
$filter_where = array(
'AIX_wage' => 100,
'AIX_jobtag' => 100,
'AIX_trade' => 100,
'AIX_scale' => 100,
'AIX_jobs_nature' => 100,
'AIX_education' => 100,
'AIX_experience' => 100
);
$categories = $this->categoryService->getCategories($filter_where);
$where = $this->setWhere($params, array(), array()); //组合where条件
$order_by = 'stime';
$search_key = '';
if ($params) {
if (array_has($params, 'sort')) {
if ($params['sort'] == 'rtime') {
$order_by = 'refresh_time';
} else {
$order_by = $params['sort'];
}
}
if (array_has($params, 'key')) {
$search_key = $params['key']?$params['key']:'';
}
}
$map_data = array();
if (array_has($params, 'lng') && array_has($params, 'lat') && array_has($params, 'wa')) {
$map_data = array('lng'=>$params['lng'],'lat'=>$params['lat'],'map'=>1);
}
$list = $this->searchService->search('Job', $where, $order_by, $search_key);
$list_items = array();
$job_companys = array();
if ($list->total()>0) {
$list_items = $this->jobsService->dealjobFilelds($list->items(), $map_data);
$job_companys = $this->jobsService->dealJobCompanies($list_items);
}
$emergency_jobs = $this->searchService->searchEmergencyJobs(4); //紧急招聘
$recommend_jobs = $this->searchService->searchRecommendJobs(5, $this->getUser()); //推荐职位
$map_info = $this->getMapInfo();
$return_data = array(
'params' => $params,
'categories' => $categories,
'show_filter' => $show_filter,
'list' => $list,
'list_items' => $list_items,
'job_companys' => $job_companys,
'emergency_jobs' => $emergency_jobs,
'position_search'=> $position_search,
'recommend_jobs' => $recommend_jobs,
'map_info' => $map_info
);
return view('app.content.jobs.map', $return_data);
}
public function getMapInfo()
{
$m_zoom = subsite_config('aix.system.map.map.max_level');
$map_center_x = subsite_config('aix.system.map.map.map_x');
$map_center_y = subsite_config('aix.system.map.map.map_y');
return ['m_zoom'=>$m_zoom,'map_center_x'=>$map_center_x,'map_center_y'=>$map_center_y];
}
public function showFilter($params, $filter_array)
{
$show_filter = false;
if ($params && (count($params) <= count($filter_array))) {
foreach ($params as $k => $v) {
if (!in_array($k, $filter_array)) {
$show_filter = true;
break;
}
}
} elseif (count($params) > count($filter_array)) {
$show_filter = true;
}
return $show_filter;
}
public function msg(Request $request)
{
$company_id = $request->input('id', '');
if (!$company_id) {
$back_url = \Illuminate\Support\Facades\URL::previous();
return $this->showMessage('请选择需要咨询的企业', $back_url, true, '上一页', '3');
}
//获取企业信息
$company_info = $this->companyService->getCompany(['id'=>$company_id]);
if ($company_info->logo) {
$company_info->logo = upload_asset($company_info->logo);
} else {
$company_info->logo = public_data_path('data/upload/no_logo.png');
}
//获取个人用户信息
$member_avator = $this->resumeService->getPersonAvator($this->getUser());
$return_data = array(
'company' => $company_info,
'wap_title' => '留言咨询',
'msg' => null,
'perosn_images' => $member_avator
);
return view('mobile.app.content.jobs.msg', $return_data);
}
}