<?php
namespace App\Http\Middleware;
use App\Models\Resume;
use App\Models\Thirdlogin;
use App\Repositories\ResumeRepository;
use App\Services\Common\TaskService;
use App\Services\Person\ResumeService;
use Closure;
use App\Models\MemberInfo;
use View;
class MobilePersonAuth
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
private $resumeService;
private $resumeRepository;
private $taskService;
public function __construct(ResumeService $resumeService, ResumeRepository $resumeRepository, TaskService $taskService)
{
$this->resumeService = $resumeService;
$this->resumeRepository = $resumeRepository;
$this->taskService = $taskService;
}
public function handle($request, Closure $next)
{
$resume = Resume::where(['uid'=>auth('web-member')->user()->id,'def'=>1])->first();
if (!$resume) {
return redirect('mobile/person/resumeAdd');
}
$memberInfo = MemberInfo::where(['uid'=>auth('web-member')->user()->id])->first();
if (!$memberInfo) {
return redirect('mobile/person/memberInfo');
}
$resume_id = [];
$resume = $this->resumeRepository->getSuccessResume(auth('web-member')->user()->id, getResumeStatus());
if (!$resume->isEmpty()) {
$resume_id = array_column($resume->toArray(), 'id');
}
$Third_bind = Thirdlogin::where(['uid'=>auth('web-member')->user()->id, 'utype'=>2])->get();
if (!$Third_bind->isEmpty()) {
foreach ($Third_bind as $key=>$val) {
if (in_array($val->type, [1])) {
$this->taskService->doTask(9);
}
if (in_array($val->type, [2,3,4])) {
$this->taskService->doTask(15);
}
}
}
View::share('memberInfo', $this->resumeService->getUserInfo(auth('web-member')->user(), $resume_id));
return $next($request);
}
}