diff --git a/app/Classes/LikesClass.php b/app/Classes/LikesClass.php index d4f2dbf..d89d8ac 100644 --- a/app/Classes/LikesClass.php +++ b/app/Classes/LikesClass.php @@ -8,34 +8,51 @@ use App\Models\Ad_employer; use App\Models\Like_vacancy; use App\Models\Like_worker; use App\Models\Worker; +use Illuminate\Support\Facades\Auth; class LikesClass { - // Вывод всех избранных вакансий у пользователя public static function ListVacancy(Ad_employer $ad_employer) { - $ListVacancy = Like_vacancy::query()->where('code_record', '=', $ad_employer->id)->get(); + $ListVacancy = Like_vacancy::query() + ->where('code_record', '=', $ad_employer->id) + ->where('user_id', Auth::user()?->id) + ->get(); + return $ListVacancy; } - // Вывод всех избранных работников у пользователя public static function ListWorkers(Worker $worker) { - $ListWorker = Like_worker::query()->where('code_record', '=', $worker->id)->get(); + $ListWorker = Like_worker::query() + ->where('code_record', '=', $worker->id) + ->where('user_id', Auth::user()?->id) + ->get(); + + return $ListWorker; } - // Возвращение кода вакансии public static function get_status_vacancy(Ad_employer $ad_employer) { - if (Like_vacancy::query()->where('code_record', '=', $ad_employer->id)->count() > 0) - $IdVacancy = " active "; - else - $IdVacancy = ""; + $isVacancyLiked = Like_worker::query() + ->where('code_record', $ad_employer->id) + ->where('user_id', Auth::user()?->id) + ->exists(); - return $IdVacancy; + if ($isVacancyLiked) { + return 'active'; + } + + return ''; } public static function get_status_worker(Worker $worker) { - if (Like_worker::query()->where('code_record', '=', $worker->id)->count() > 0) - { $IdWorker = " active"; } else { $IdWorker = "123"; } + $isWorkerLiked = Like_worker::query() + ->where('code_record', $worker->id) + ->where('user_id', Auth::user()?->id) + ->exists(); + + if ($isWorkerLiked) { + return 'active'; + } - return $IdWorker; + return ''; } } diff --git a/app/Classes/Tools.php b/app/Classes/Tools.php index 6624d71..4b10015 100644 --- a/app/Classes/Tools.php +++ b/app/Classes/Tools.php @@ -4,6 +4,8 @@ namespace App\Classes; +use App\Models\Worker; + class Tools { static function generator_id($length = 6) @@ -22,4 +24,33 @@ class Tools } return $word; } + + public static function getWorkerProfilePercent(Worker $Worker): int + { + $persent = 10; + + if ((!empty($Worker->telephone)) && + (!empty($Worker->email)) && (!empty($Worker->experience)) && + (!empty($Worker->city)) && (!empty($Worker->old_year))) { + $persent = $persent + 40; + } + + if ($Worker->sertificate->count() > 0) { + $persent = $persent + 15; + } + + if ($Worker->infobloks->count() > 0) { + $persent = $persent + 20; + } + + if ($Worker->prev_company->count() > 0) { + $persent = $persent + 10; + } + + if (!empty($Worker->photo)) { + $persent = $persent + 5; + } + + return $persent; + } } diff --git a/app/Http/Controllers/AdEmployerController.php b/app/Http/Controllers/AdEmployerController.php index dae08f5..5dbda40 100644 --- a/app/Http/Controllers/AdEmployerController.php +++ b/app/Http/Controllers/AdEmployerController.php @@ -38,4 +38,9 @@ class AdEmployerController extends Controller return view('public.ad.profile', compact('ad_employer', 'stat')); } + + public function getById(Ad_employer $vacancy) + { + return $vacancy; + } } diff --git a/app/Http/Controllers/Admin/JobTitlesController.php b/app/Http/Controllers/Admin/JobTitlesController.php index dbbfe0a..4faace7 100644 --- a/app/Http/Controllers/Admin/JobTitlesController.php +++ b/app/Http/Controllers/Admin/JobTitlesController.php @@ -19,13 +19,16 @@ class JobTitlesController extends Controller public function index(Request $request) { if ($request->has('sort')) { - $Jobs = Job_title::query()->where('is_remove', '=', '0'); - if ($request->get('sort') == 'up') + $Jobs = Job_title::query() + ->where('is_remove', '0'); + + if ($request->get('sort') == 'up') { $Jobs = $Jobs->orderBy('sort')->orderBy('name')->paginate(15); - else + } else { $Jobs = $Jobs->orderByDesc('sort')->orderBy('name')->paginate(15); + } } else { - $Jobs = Job_title::query()->where('is_remove', '=', '0')-> + $Jobs = Job_title::query()->where('is_remove', '0')-> orderByDesc('sort')->orderBy('name')->paginate(15); } diff --git a/app/Http/Controllers/CompanyController.php b/app/Http/Controllers/CompanyController.php index c4c8ce5..397ff69 100644 --- a/app/Http/Controllers/CompanyController.php +++ b/app/Http/Controllers/CompanyController.php @@ -57,6 +57,7 @@ class CompanyController extends Controller $ads = Ad_employer::query()->with('jobs')->with('jobs_code') ->where('employer_id', '=', $company[0]->id) ->where('is_remove', '=', '0') + ->where('active_is', 1) ->OrderByDesc('id') ->paginate(50) ; diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index cfa9106..b88ba5e 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -393,7 +393,6 @@ class EmployerController extends Controller 'password' => ['required', 'string', 'min:6'], ]; - $messages = [ 'required' => 'Укажите обязательное поле', 'min' => [ @@ -430,12 +429,16 @@ class EmployerController extends Controller $validator = Validator::make($params, $rules, $messages); if ($validator->fails()) { - return json_encode(Array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); + return json_encode(Array("ERROR" => "Error: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); } else { $user = $this->create($params); event(new Registered($user)); - Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params)); + try { + Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params)); + } catch (Throwable $e) { + Log::error($e); + } Auth::guard()->login($user); } @@ -538,36 +541,28 @@ class EmployerController extends Controller } //Избранные люди - public function favorites(Request $request) { - $IP_address = RusDate::ip_addr_client(); - $Arr = Like_worker::Query()->select('code_record')->where('ip_address', '=', $IP_address)->get(); - - if ($Arr->count()) { - $A = Array(); - foreach ($Arr as $it) { - $A[] = $it->code_record; - } + public function favorites(Request $request) + { + $likedWorkersIds = Like_worker::query() + ->where('user_id', Auth::user()->id) + ->get() + ->pluck('code_record') + ->toArray(); - $Workers = Worker::query()->whereIn('id', $A); - } else { - $Workers = Worker::query()->where('id', '=', '0'); - } + $workerBuilder = Worker::query() + ->whereIn('id', $likedWorkersIds); if (($request->has('search')) && (!empty($request->get('search')))) { $search = $request->get('search'); - $Workers = $Workers->WhereHas('users', - function (Builder $query) use ($search) { - $query->Where('surname', 'LIKE', "%$search%") - ->orWhere('name_man', 'LIKE', "%$search%") - ->orWhere('surname2', 'LIKE', "%$search%"); - }); - } else { - $Workers = $Workers->with('users'); + $workerBuilder->whereHas('users', function (Builder $query) use ($search) { + $query->where('surname', 'LIKE', "%$search%") + ->oWhere('name_man', 'LIKE', "%$search%") + ->orWhere('surname2', 'LIKE', "%$search%"); + }); } - $Workers = $Workers->get(); - + $Workers = $workerBuilder->get(); return view('employers.favorite', compact('Workers')); } @@ -714,7 +709,7 @@ class EmployerController extends Controller $job_titles = Job_title::query() ->where('is_remove', '=', 0) - //->where('is_bd', '=', 1) + ->where('is_bd', '=', 1) ->orderByDesc('sort') ->get(); @@ -757,7 +752,8 @@ class EmployerController extends Controller ////////////////////////////////////////////////////////////////// // Отправил сообщение ////////////////////////////////////////////////////////////////// - public function new_message(Request $request) { + public function new_message(Request $request) + { $params = $request->all(); $id = $params['_user_id']; @@ -768,6 +764,8 @@ class EmployerController extends Controller 'flag_new' => 1 ]; + dd($params); + Message::add_message( $request, $params['_user_id'], diff --git a/app/Http/Controllers/MainController.php b/app/Http/Controllers/MainController.php index a32d96a..6e97038 100644 --- a/app/Http/Controllers/MainController.php +++ b/app/Http/Controllers/MainController.php @@ -89,41 +89,46 @@ class MainController extends Controller } // Лайк вакансии - public function like_vacancy(Request $request) { - $IP_address = RusDate::ip_addr_client(); + public function like_vacancy(Request $request) + { + if(Auth::user() === null) { + return;//todo unauthenticated behavior + } - if ($request->has('code_record')) { - if ($request->has('delete')) { - $code = $request->get('code_record'); - $atomic_era = Like_vacancy::select('id')-> - where('code_record', '=', $code)->toSql(); - DB::table('like_vacancy')->where('code_record', $request->get('code_record'))->delete(); + if ($request->has('code_record')) { + if ($request->has('delete')) { + DB::table('like_vacancy') + ->where('code_record', $request->get('code_record')) + ->where('user_id', Auth::user()->id) + ->delete(); - } else { - $params = $request->all(); - $params['ip_address'] = $IP_address; - Like_vacancy::create($params); - } + } else { + $params = $request->all(); + $params['user_id'] = Auth::user()->id; + Like_vacancy::create($params); } + } } // Лайк соискателю. - public function like_worker(Request $request) { - $IP_address = RusDate::ip_addr_client(); + public function like_worker(Request $request) + { + if(Auth::user() === null) { + return;//todo unauthenticated behavior + } - if ($request->has('code_record')) { + if ($request->has('code_record')) {//fixme make non-absurd validation if ($request->has('delete')) { - $atomic_era = Like_worker::select('id')-> - where('code_record', '=', $request-> - get('code_record'))->first(); - - DB::table('like_worker')->where('code_record', $request->get('code_record'))->delete(); + DB::table('like_worker') + ->where('code_record', $request->get('code_record')) + ->where('user_id', Auth::user()->id) + ->delete(); return "Вот и результат удаления!"; } else { $params = $request->all(); - $params['ip_address'] = $IP_address; + $params['user_id'] = Auth::user()->id; Like_worker::create($params); } } diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 052e61e..59ed51a 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers; use App\Classes\RusDate; +use App\Classes\Tools; use App\Http\Requests\DocumentsRequest; use App\Http\Requests\PrevCompanyRequest; use App\Http\Requests\SertificationRequest; @@ -72,64 +73,64 @@ class WorkerController extends Controller // лист база резюме public function bd_resume(Request $request) { - $look = false; - $idiot = 0; if (isset(Auth()->user()->id)) { - $idiot = Auth()->user()->id; - if ((!Auth()->user()->is_worker) && (Auth()->user()->is_lookin)) - $look = true; + if ((Auth()->user()->is_worker) || (!Auth()->user()->is_lookin)) + return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); } - if ($look) { - $status_work = WorkerStatuses::getWorkerStatuses(); - $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at');; - $resumes = $resumes->whereHas('users', function (Builder $query) { - $query->Where('is_worker', '=', '1') - ->Where('is_bd', '=', '0'); - }); + $status_work = WorkerStatuses::getWorkerStatuses(); - //dd($request->get('job')); - if (($request->has('job')) && ($request->get('job') > 0)) { - $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { - $query->Where('job_titles.id', $request->get('job')); - }); - } + $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at'); + $resumes = $resumes->whereHas('users', function (Builder $query) { + $query->Where('is_worker', '=', '1') + ->Where('is_bd', '=', '0'); + }); - $Job_title = Job_title::query() - ->where('is_remove', '=', '0') - ->where('is_bd', '=' , '1') - ->orderByDesc('sort') - ->get() - ; + if (($request->has('job')) && ($request->get('job') > 0)) { + $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { + $query->Where('job_titles.id', $request->get('job')); + }); + } - if ($request->get('sort')) { - $sort = $request->get('sort'); - switch ($sort) { - case 'looking_for_work': - $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); - break; - case 'considering_offers': - $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); - break; - case 'not_looking_for_work': - $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); - break; - } + $Job_title = Job_title::query() + ->where('is_remove', '=', '0') + ->where('is_bd', '=' , '1') + ->orderByDesc('sort') + ->get(); + + if ($request->get('sort')) { + $sort = $request->get('sort'); + switch ($sort) { + case 'looking_for_work': + $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); + break; + case 'considering_offers': + $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); + break; + case 'not_looking_for_work': + $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); + break; } + } - $res_count = $resumes->count(); - //$resumes = $resumes->get(); - $resumes = $resumes->paginate(4); - if ($request->ajax()) { - // Условия обставлены - if ($request->has('block') && ($request->get('block') == 1)) { - return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count', 'idiot')); - } - } else { - return view('resume', compact('resumes', 'status_work', 'res_count', 'idiot', 'Job_title')); + $resumes->where(function (Builder $query) { + $query->whereNotNull('telephone') + ->whereNotNull('email') + ->whereNotNull('city') + ->whereNotNull('experience') + ->whereNotNull('old_year'); + //fixme костыль, переделать + }); + + $res_count = $resumes->count(); + $resumes = $resumes->paginate(4); + if ($request->ajax()) { + // Условия обставлены + if ($request->has('block') && ($request->get('block') == 1)) { + return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count')); } } else { - return redirect()->route('index')->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); + return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title')); } } @@ -323,7 +324,7 @@ class WorkerController extends Controller ->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker']) ->WhereHas('users', function (Builder $query) use ($id) { $query->Where('id', $id); - })->get(); + })->first(); $Job_titles = Job_title::query()->where('is_remove', '=', '0') ->where('is_bd', '=' , '1') @@ -334,49 +335,7 @@ class WorkerController extends Controller ->where('user_id', '=', $id) ->get(); - - // 10% - - $persent = 10; - $persent1 = 0; - $persent2 = 0; - $persent3 = 0; - $persent4 = 0; - $persent5 = 0; - - if ((!empty($Worker[0]->telephone)) && - (!empty($Worker[0]->email)) && (!empty($Worker[0]->experience)) && - (!empty($Worker[0]->city)) && (!empty($Worker[0]->old_year))) { - // 40% - $persent = $persent + 40; - $persent1 = 40; - } - - //dd($Worker[0]->status_work, $Worker[0]->telephone, $Worker[0]->email, $Worker[0]->experience, $Worker[0]->city, $Worker[0]->old_year); - - if ($Worker[0]->sertificate->count() > 0) { - // 15% - $persent = $persent + 15; - $persent2 = 15; - } - - if ($Worker[0]->infobloks->count() > 0) { - // 20% - $persent = $persent + 20; - $persent3 = 20; - } - - if ($Worker[0]->prev_company->count() > 0) { - // 10% - $persent = $persent + 10; - $persent4 = 10; - } - - if (!empty($Worker[0]->photo)) { - // 5% - $persent = $persent + 5; - $persent5 = 5; - } + $persent = Tools::getWorkerProfilePercent($Worker); $status_work = WorkerStatuses::getWorkerStatuses(); $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; diff --git a/app/Models/Like_vacancy.php b/app/Models/Like_vacancy.php index 853ae06..d55f88e 100644 --- a/app/Models/Like_vacancy.php +++ b/app/Models/Like_vacancy.php @@ -2,17 +2,25 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Like_vacancy extends Model { - use HasFactory; - public $table = 'like_vacancy'; public $fillable = [ 'code_record', - 'ip_address' + 'user_id' ]; + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + + public function vacancy(): BelongsTo + { + return $this->belongsTo(Ad_employer::class); + } } diff --git a/app/Models/Like_worker.php b/app/Models/Like_worker.php index b2e3d6a..6cbfc77 100644 --- a/app/Models/Like_worker.php +++ b/app/Models/Like_worker.php @@ -2,24 +2,25 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Like_worker extends Model { - use HasFactory; - public $table = 'like_worker'; public $fillable = [ 'code_record', - 'ip_address' + 'user_id' ]; - /* - один-ко-многим - */ public function worker() { return $this->hasMany(Worker::class); } + + public function user(): BelongsTo + { + return $this->belongsTo(User::class); + } + } diff --git a/app/Models/Message.php b/app/Models/Message.php index 26ff776..e6e4886 100644 --- a/app/Models/Message.php +++ b/app/Models/Message.php @@ -55,6 +55,7 @@ class Message extends Model string $file_store_path = '/', bool $is_admin_chat = false ) { + dd($request->all()); $message_params['user_id'] = $user_id; $message_params['to_user_id'] = $to_user_id; if ($request && $request->has('file')) { diff --git a/app/Models/Worker.php b/app/Models/Worker.php index 03892e5..d501722 100644 --- a/app/Models/Worker.php +++ b/app/Models/Worker.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; @@ -129,5 +130,4 @@ class Worker extends Model $job_titles_ids = json_decode($this->attributes['positions_work'], true); return Job_title::whereIn('id', $job_titles_ids)->get(); } - } diff --git a/database/migrations/2024_09_18_104034_change_ip_to_id_in_likes_tables.php b/database/migrations/2024_09_18_104034_change_ip_to_id_in_likes_tables.php new file mode 100644 index 0000000..e42ff2a --- /dev/null +++ b/database/migrations/2024_09_18_104034_change_ip_to_id_in_likes_tables.php @@ -0,0 +1,35 @@ +renameColumn('ip_address', 'user_id'); + }); + Schema::table('like_vacancy', function (Blueprint $table) { + $table->renameColumn('ip_address', 'user_id'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { +// Schema::table('id_in_likes_tables', function (Blueprint $table) { +// // +// }); + } +}; diff --git a/resources/views/admin/worker/index.blade.php b/resources/views/admin/worker/index.blade.php index 0c950dc..85b008f 100644 --- a/resources/views/admin/worker/index.blade.php +++ b/resources/views/admin/worker/index.blade.php @@ -143,7 +143,7 @@ @else - {{$user->workers[0]->persent_anketa}}% + {{ \App\Classes\Tools::getWorkerProfilePercent($user->workers[0]) }}% @endif @else diff --git a/resources/views/ajax/list_vacancies.blade.php b/resources/views/ajax/list_vacancies.blade.php index 61ab295..782d96f 100644 --- a/resources/views/ajax/list_vacancies.blade.php +++ b/resources/views/ajax/list_vacancies.blade.php @@ -25,9 +25,7 @@ - - Вернуться к списку вакансий - + Вернуться к списку вакансий
@@ -43,16 +41,6 @@

@if (!empty($Q->name)) {{ $Q->name }}@else Не указано @endif

- -
@@ -61,25 +49,6 @@ {!! $Q->text !!}
-
@if (!empty($Q->jobs_code[0]->position_ship)) @@ -121,4 +90,4 @@ @endforeach
{{ $Query->appends($_GET)->links('paginate') }} -
+
diff --git a/resources/views/companies.blade.php b/resources/views/companies.blade.php index 56b4c35..5db8895 100644 --- a/resources/views/companies.blade.php +++ b/resources/views/companies.blade.php @@ -71,11 +71,18 @@ @csrf -

Работодатели

-

С другой стороны, социально-экономическое развитие не оставляет шанса для - существующих финансовых и административных условий.

+

Судоходные компании

+

+ В данном разделе представлены компании объявления от которых Вы можете увидеть на сайте + + Галочка "Компания одобрена сервисом rekamore.su" выдается компании в чьей репутации мы уверены, компания работает не первый год и у нее нет задержек по заработной плате + + Компании без галочки не стоит игнорировать, возможно она находится на проверке и в скором времени галочка будет выдана + + Мы очень дорожим нашей репутацией и стараемся оградить моряков от недобросовестных работодателей +