jobsService = $jobsService;
$this->categoryService = $categoryService;
$this->companyService = $companyService;
$this->memberSetmealRepository = $memberSetmealRepository;
$this->setmealIncrementsService = $setmealIncrementsService;
$this->refreshLogRepository = $refreshLogRepository;
$this->memberPointRepository = $memberPointRepository;
$this->setmealRepository = $setmealRepository;
$this->queueAutoRefreshRepository = $queueAutoRefreshRepository;
$this->serviceService = $serviceService;
$this->subsiteService = $subsiteService;
$this->jobsRepository = $jobsRepository;
$this->companyContactsRepository = $companyContactsRepository;
$this->membersSetmealService = $membersSetmealService;
}
/**
* 管理职位
* @param null $type
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*/
public function jobsList(Request $request, $type = null)
{
$user = auth('web-company')->user();
$type = isset($request->type) ? $request->type : 0;
$jobs_list = $this->jobsService->list($type, $user);
$jobs_total = $this->jobsService->jobsTotal($user->id);
$company_setmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);//会员套餐
$stick = $this->setmealIncrementsService->getCat('stick');
$emergency = $this->setmealIncrementsService->getCat('emergency');
$this->serviceService->freeSetmealIsOver($user);
return view('app.jobs.jobs_list', ['jobsList' => $jobs_list, 'type' => $type, 'jobsCount' => $jobs_total, 'company_setmeal' => $company_setmeal, 'stick' => $stick, 'emergency' => $emergency]);
}
/**
* 职位添加
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \App\Exceptions\ResponseException
*/
public function jobsAdd($id = null)
{
$user = auth('web-company')->user();
$jobsExist = $this->jobsRepository->jobsTotal(['company_id' => $user->id, 'id' => $id]);
if (empty($jobsExist) && !empty($id)) {
return $this->showMessage('没有这个职位!', route('jobs.list'), true);
}
//企业联系人数据
$companyContact = $this->companyContactsRepository->getContacts(['company_id' => $user->id]);
//查询该套餐可发布多少职位数及已发布多少职位
$jobs_total = $this->jobsService->jobsTotal($user->id);
$company_setmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);//会员套餐
//查询企业信息
$companyInfo = $this->companyService->getInfoById($user);
//分站信息
$subsite = $this->subsiteService->getSubsite($user);
$result = [
'info' => $companyInfo,
'jobsCount' => $jobs_total,
'company_setmeal' => $company_setmeal,
'subsite' => $subsite,
'companyContact' => $companyContact,
];
if (isset($id) && $id) {
if (!$result['jobsInfo'] = $this->jobsService->jobsInfo($id)) {
return $this->showMessage('请确认职位是否存在!', route('jobs.list'), true);
}
if ($result['jobsInfo']->subsites->isNotEmpty()) {
$subsiteArr = $result['jobsInfo']->subsites->toArray();
if ($subsiteArr) {
foreach ($subsiteArr as $key => $val) {
$result['sites'][] = $val['subsite_id'];
}
} else {
$result['sites'][] = [];
}
}
}
return view('app.jobs.jobs_add', $result);
}
/**异步获取企业联系人
* @param $id
* @return \Illuminate\Http\JsonResponse
*/
public function ajaxGetComContact(Request $request)
{
$id = $request->id;
if (!$id) {
return response()->json(['status' => 0, 'msg' => '无此联系人ID', 'data' => '']);
}
$contact = $this->companyContactsRepository->find($id);
return response()->json(['status' => 1, 'msg' => '成功', 'data' => $contact]);
}
public function ajaxGetDistrict(Request $request)
{
$id = $request->id;
$district_cn = get_district_cn($id);
return response()->json(['status' => 1, 'msg' => '成功', 'data' => $district_cn]);
}
/**
* 职位保存
* @param JobsValidatorRequest $request
* @return \Illuminate\Http\JsonResponse
* @throws \Prettus\Validator\Exceptions\ValidatorException
*/
public function jobsSave(JobsValidatorRequest $request)
{
$user = auth('web-company')->user();
$data = $request->except('_token', '_method');
$data['wage_min'] = empty($data['wage_min']) ? 0 : $data['wage_min'];
$data['wage_max'] = empty($data['wage_max']) ? 0 : $data['wage_max'];
$data['map_x'] = empty($data['map_x']) ? '' : $data['map_x'];
$data['map_y'] = empty($data['map_y']) ? '' : $data['map_y'];
return $this->jobsService->jobsSave($data, $user);
}
/**
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \Throwable
*/
public function jobsAddToJobfair(Request $request)
{
if ($request->method() == 'POST') {
$user = $this->getLoginUser();
return $this->jobsService->jobsAddToJobfair($request, $user);
}
$tip = '您确定要将该职位加入招聘会职位库吗?';
return response()->json(['status' => 1, 'msg' => '', 'data' => ['html' => view('app.company.ajax.ajax_warning', ['tip' => $tip])->render()]]);
}
/**职位刷新
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \App\Exceptions\ResponseException
* @throws \Throwable
*/
public function jobsRefresh(Request $request)
{
$cat = $request->input('service_type', 'auto_refresh_jobs');
$project_id = $request->input('project_id');
$id = $request->id;
if (!$id) {
return response()->json(['status' => 0, 'msg' => "请选择刷新职位!"]);
}
$res = [];
$yid = is_array($id) ? $id : explode(",", $id);
$jobsCount = count($yid);
$user = auth('web-company')->user();
//有无开通刷新服务
$mySetmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);
if (!$mySetmeal) {
return response()->json(['status' => 0, 'msg' => '您还没有开通服务,请开通!', 'data' => ['show_footer' => 0]]);
}
//服务是否到期
if ($mySetmeal->expire == 1 && $mySetmeal->setmeal_id > 1) {
return response()->json(['status' => 0, 'msg' => '您的服务已经到期,请重新开通!', 'data' => ['show_footer' => 0]]);
}
$where = [
'uid' => $user->id,
'utype' => 1,
'type' => 1006,
'mode' => 2,
];
//刷新间隔时间
// $refrestime = $this->refreshLogRepository->getLastRefreshDate($where);
// $duringtime = time() - strtotime($refrestime?$refrestime->created_at:0);
$space = config('aix.companyset.comset.other_set.refresh_jobs_space') * 60;
// if ($space > 0 && $duringtime <= $space) {
// return response()->json(['status' => 0, 'msg' => $space . "秒内不能重复刷新职位", 'data' => ['show_footer' => 0]]);
// }
foreach ($yid as $value) {
if (Cache::has('refresh_jobid_' . $value)) {
// $jobs_intersect = array_intersect(Cache::get('refresh_jobid_'.$value), $yid);
// if ($jobs_intersect) {
$refreshJobName = $this->jobsRepository->findWhereIn('id', [$value], ['jobs_name'])->toArray();
return response()->json(['status' => 0, 'msg' => "【" . implode(',', array_column($refreshJobName, 'jobs_name')) . "】" . $space . "秒内不能重复刷新,请重新选择", 'data' => ['show_footer' => 0]]);
// }
}
}
if ($request->method() == 'POST') {
if (isExpire($mySetmeal)) {
return response()->json(['status' => 0, 'msg' => "提醒:您的套餐已到期,请及时到我的套餐处升级套餐!"]);
}
$payment_name = $request->payment_name ? $request->payment_name : '';
if ($payment_name) {
$is_deductible = $request->input('is_deductible', 0);
if ($is_deductible == 0) {
$deductible = 0;
} else {
$deductible = $request->input('deductible', '');
}
$myPoints = $this->memberPointRepository->getComPointsById($user->id, $user->utype);
$increment_info['name'] = '职位刷新';
$params['jobs_id'] = $yid[0];
$params['type'] = 'jobs_refresh';
//修改吴正科的微信支付的DB写法
$my_setmeal = $this->membersSetmealService->getUserSetmeal($user, '1'); //会员套餐信息
$my_discount = $this->setmealIncrementsService->getIncrementDiscountByArray($cat, $my_setmeal); //套餐折扣
if (empty($project_id)) { //就是单次刷新的支付
$service_need_cash = config('aix.companyset.comsume.comsume_set.refresh_jobs_price');
$increment_info['name'] = "单次刷新职位";
} else {
$increment_info = $this->setmealIncrementsService->getIncrement($project_id);
$service_need_cash = $my_discount > 0 ? round($increment_info->price * $my_discount / 10, 2) : $increment_info->price; //智能刷新所需积分
}
return $this->jobsService->callCashPay($user, $increment_info, $myPoints, 13, $payment_name, $service_need_cash, $is_deductible, $deductible, '', $params);
} else {
//如果是积分兑换刷新或者直接免费刷新
$r = $this->jobsService->jobsRefreshSave($yid, $user, $mySetmeal);
if (!$r['status']) {
return response()->json(['status' => 0, 'msg' => $r['msg']]);
} else {
return response()->json(['status' => 1, 'msg' => '刷新成功!']);
}
}
}
//计算免费刷新次数
$todayCount = $this->refreshLogRepository->getTodayRefreshTimes($where);
if ($jobsCount > 1 && $todayCount >= $mySetmeal->refresh_jobs_free) {
return response()->json(['status' => 2, 'msg' => "您共选中了 " . $jobsCount . " 条职位,今天免费刷新次数已用完。
请单条刷新。", 'data' => ['show_footer' => 0]]);
} elseif ($jobsCount > 1 && ($todayCount + $jobsCount) > $mySetmeal->refresh_jobs_free) {
$surplus = $mySetmeal->refresh_jobs_free - $todayCount;
return response()->json(['status' => 2, 'msg' => "您共选中了 " . $jobsCount . " 条职位,今天免费刷新次数剩余 " . $surplus . " 次。
请单条刷新。", 'data' => ['show_footer' => 0]]);
}
$myPoints = $this->memberPointRepository->getPointsOne(auth('web-company')->user()->id, 1);
if ($todayCount >= $mySetmeal->refresh_jobs_free) {//免费刷新次数已到
$mode = 'points';
if ($myPoints->points < config('aix.companyset.comsume.comsume_set.refresh_jobs_price') * config('aix.companyset.points.points_set.payment_rate') * $jobsCount) {
$mode = 'mix';
}
} else {
$mode = 'setmeal';
}
if ($mode == 'points' && config('aix.companyset.comsume.comsume_set.refresh_jobs_by_points') == 0) {
$mode = 'mix';
}
if ($mode == 'setmeal') {
$show_footer = 1;
$res['freeTime'] = $mySetmeal->refresh_jobs_free - $todayCount;
} elseif ($mode == 'points') {
$show_footer = 0;
} else {
$show_footer = 0;
$res['max_discount'] = $this->setmealRepository->getMaxDiscount('auto_refresh_jobs');
$res['needCash'] = config('aix.companyset.comsume.comsume_set.refresh_jobs_price') * $jobsCount;
}
$res['open_points_convert'] = config('aix.companyset.comsume.comsume_set.refresh_jobs_by_points');
if ($jobsCount == 1) {
$jobid = $yid[0];
$condition['pid'] = $jobid;
$condition['type'] = 1;
$auto_refresh_log = $this->queueAutoRefreshRepository->findData($condition);
$auto_refresh_log = $auto_refresh_log ? 1 : 0;
$res['id'] = $jobid;
} else {
$auto_refresh_log = 0;
$res['id'] = implode(',', $yid);
}
$res['cat'] = 'auto_refresh_jobs';
$res['increment_arr'] = $this->serviceService->incrementAdd('auto_refresh_jobs', $request->all());
$res['auto_refresh_log'] = $auto_refresh_log;
$res['mySetmeal'] = $mySetmeal;
$res['mode'] = $mode;
$res['jobsCount'] = $jobsCount;
$res['more_times'] = $mySetmeal->refresh_jobs_free + config('aix.companyset.comsume.comsume_set.refresh_jobs_more') - $todayCount; //此中refresh_jobs_more 代表触屏版的额外次数
$res['increment'] = $request->increment ? 1 : 0;
$res['refresh_points'] = config('aix.companyset.comsume.comsume_set.refresh_jobs_price') * config('aix.companyset.points.points_set.payment_rate') * $jobsCount;
$res['myPoints'] = $myPoints->points;
// dd($res);
return response()->json(['status' => 1, 'msg' => view('app.jobs.ajax.ajax_job_refresh', $res)->render(), 'data' => ['show_footer' => $show_footer]]);
}
/**
* 付费刷新
*/
public function jobsPayRefresh(Request $request)
{
$jobs_id = $request->jobs_id;
$is_deductible = $request->is_deductible;
$deductible = $request->deductible;
$user = auth('web-company')->user();
$mySetmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);
return $this->jobsService->jobRefreshPay($jobs_id, $user, $is_deductible, $deductible, $mySetmeal);
}
/**
* 职位关闭
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
*/
public function jobsClose(Request $request)
{
if ($request->type && $request->type == 1) {
$user = auth('web-company')->user();
return $this->jobsService->jobsClose($request->id, $user);
}
$tip = "职位关闭后将会暂停招聘,您确定要关闭选中的职位吗?";
return view('app.company.ajax.ajax_warning', ['tip' => $tip]);
}
public function closeAll(Request $request)
{
if ($request->type && $request->type == 1) {
$user = auth('web-company')->user();
return $this->jobsService->jobsClose($request->id, $user);
}
$tip = "职位关闭后将会暂停招聘,您确定要关闭选中的职位吗?";
return view('app.company.ajax.ajax_warning', ['tip' => $tip]);
}
/**
* 恢复职位
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
*/
public function jobsShow(Request $request)
{
$user = auth('web-company')->user();
if ($request->type && $request->type == 1) {
return $this->jobsService->jobsShow($request->id, $user);
}
$tip = "职位恢复后将会对外公开招聘,您确定要恢复选中的职位吗?";
return view('app.company.ajax.ajax_warning', ['tip' => $tip]);
}
/**职位删除
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
*/
public function jobsDel(Request $request)
{
if ($request->type && $request->type == 1) {
$id = $request->id;
$user = auth('web-company')->user();
return $this->jobsService->jobsDel($id, $user);
}
$tip = "被删除后将无法恢复,您确定要删除选中的职位吗?";
return view('app.company.ajax.ajax_warning', ['tip' => $tip]);
}
/**
* 删除所有职位
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View
*/
public function delAll(Request $request)
{
if ($request->type && $request->type == 1) {
$id = $request->id;
$user = auth('web-company')->user();
return $this->jobsService->jobsDel($id, $user);
}
$tip = "被删除后将无法恢复,您确定要删除选中的职位吗?";
return view('app.company.ajax.ajax_warning', ['tip' => $tip]);
}
/**紧急招聘
*
*/
public function jobsEmergency(Request $request)
{
if (!$request->jobs_id) {
return response()->json(['status' => 0, 'msg' => '参数错误!']);
}
$user = auth('web-company')->user();
$jobsExist = $this->jobsRepository->jobsHas($user, $request->jobs_id);
if (empty($jobsExist)) {
return response()->json(['status' => 0, 'msg' => "没有这个职位"]);
}
$res = $this->serviceService->incrementAdd('emergency', $request->all());
$res['jobs_id'] = $request->jobs_id;
$html = view('app.jobs.ajax.ajax_jobs_stick_emergency', $res)->render();
return response()->json(['status' => 1, 'msg' => $html]);
}
/**职位置顶
* @param Request $request
* @return \Illuminate\Http\JsonResponse
* @throws \Throwable
*/
public function jobsStick(Request $request)
{
if (!$request->jobs_id) {
return response()->json(['status' => 0, 'msg' => '参数错误!']);
}
$user = auth('web-company')->user();
$jobsExist = $this->jobsRepository->jobsHas($user, $request->jobs_id);
if (empty($jobsExist)) {
return response()->json(['status' => 0, 'msg' => "没有这个职位"]);
}
$res = $this->serviceService->incrementAdd('stick', $request->all());
$res['jobs_id'] = $request->jobs_id;
$html = view('app.jobs.ajax.ajax_jobs_stick_emergency', $res)->render();
return response()->json(['status' => 1, 'msg' => $html]);
}
/**招聘效果统计===访客统计
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
* @throws \Throwable
*/
public function statisticsVisitor(Request $request)
{
$user = auth('web-company')->user();
if ($request->ajax()) {
return $this->jobsService->statisticsVisitor($request, $user);
}
$company_setmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);//会员套餐
$res = $this->jobsService->statisticsVisitor($request, $user);
$res['company_setmeal'] = $company_setmeal;
$jobs_total = $this->jobsService->jobsTotal($user->id);
$res['jobsCount'] = $jobs_total;
// dd($res['view_time']);
return view('app.jobs.jobs_statistics_visitor', $res);
}
/**招聘效果统计===职位浏览
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
* @throws \Throwable
*/
public function statisticsViewjobs(Request $request)
{
$user = auth('web-company')->user();
if ($request->ajax()) {
return $this->jobsService->statisticsViewjobs($request, $user);
}
$res = $this->jobsService->statisticsViewjobs($request, $user);
$company_setmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);//会员套餐
$res['company_setmeal'] = $company_setmeal;
$jobs_total = $this->jobsService->jobsTotal($user->id);
$res['jobsCount'] = $jobs_total;
return view('app.jobs.jobs_statistics_viewjobs', $res);
}
/**招聘效果统计===应聘统计
* @param Request $request
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View|mixed
* @throws \Throwable
*/
public function statisticsApply(Request $request)
{
$user = auth('web-company')->user();
if ($request->ajax()) {
return $this->jobsService->statisticsApply($request, $user);
}
$res = $this->jobsService->statisticsApply($request, $user);
$company_setmeal = $this->memberSetmealRepository->getSetmealByUid($user->id, $user->utype);//会员套餐
$res['company_setmeal'] = $company_setmeal;
$jobs_total = $this->jobsService->jobsTotal($user->id);
$res['jobsCount'] = $jobs_total;
return view('app.jobs.jobs_statistics_apply', $res);
}
}