From be3039cb9484bf92de7fd4e416d09f86e363b9d3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=20=D0=9B=D0=B0=D1=80?= =?UTF-8?q?=D0=B8=D0=BE=D0=BD=D0=BE=D0=B2?= Date: Thu, 5 Oct 2023 19:16:09 +0700 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8=20=D0=BF=D0=BE?= =?UTF-8?q?=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=BE=D0=B4=D0=B0=D1=82=D0=B5=D0?= =?UTF-8?q?=BB=D1=8F=D0=BC,=20=D1=81=D0=BE=D0=B8=D1=81=D0=BA=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D1=8F=D0=BC=20=D0=B8=20=D0=B2=D0=B0=D0=BA=D0=B0=D0=BD=D1=81?= =?UTF-8?q?=D0=B8=D1=8F=D0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Admin/Ad_EmployersController.php | 36 +++++++- app/Http/Controllers/Admin/EmployersController.php | 24 ++--- app/Http/Controllers/Admin/WorkersController.php | 76 +++++++++++++++- app/Models/Ad_employer.php | 3 + app/Models/User.php | 17 ++++ resources/views/admin/ad_employers/edit.blade.php | 93 ++++++++++++++++++++ resources/views/admin/ad_employers/index.blade.php | 72 ++++++++------- resources/views/admin/employer/index.blade.php | 2 +- resources/views/admin/find_employer.blade.php | 41 +++++++++ resources/views/admin/find_worker.blade.php | 41 +++++++++ resources/views/admin/worker/index.blade.php | 22 +++-- resources/views/admin/worker/index_ajax.blade.php | 23 +++-- routes/web.php | 4 +- 13 files changed, 390 insertions(+), 64 deletions(-) create mode 100644 resources/views/admin/ad_employers/edit.blade.php create mode 100644 resources/views/admin/find_employer.blade.php create mode 100644 resources/views/admin/find_worker.blade.php diff --git a/app/Http/Controllers/Admin/Ad_EmployersController.php b/app/Http/Controllers/Admin/Ad_EmployersController.php index efefbbb..1675f31 100644 --- a/app/Http/Controllers/Admin/Ad_EmployersController.php +++ b/app/Http/Controllers/Admin/Ad_EmployersController.php @@ -4,9 +4,11 @@ namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Ad_employer; +use App\Models\Job_title; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Validator; class Ad_EmployersController extends Controller { @@ -18,7 +20,8 @@ class Ad_EmployersController extends Controller public function index(Request $request) { $title = 'Админка - Вакансии работодателей'; - $ad_employers = Ad_employer::with('employer')->with('jobs')->where('is_remove', '0')->paginate(15); + $ad_employers = Ad_employer::with('employer')->with('jobs') + ->where('is_remove', '0')->paginate(15); return view('admin.ad_employers.index', compact('ad_employers', 'title')); @@ -64,7 +67,14 @@ class Ad_EmployersController extends Controller */ public function edit(Ad_employer $ad_employer) { - // + $sel = Array(); + $job_titles = Job_title::active()->get(); + + foreach ($ad_employer->jobs as $j) { + $sel[] = $j->id; + } + + return view('admin.ad_employers.edit', compact('ad_employer', 'job_titles', 'sel')); } /** @@ -76,7 +86,27 @@ class Ad_EmployersController extends Controller */ public function update(Request $request, Ad_employer $ad_employer) { - // + $params = $request->all(); + unset($params->position_work); + $rules = [ + 'name' => 'required|min:3', + ]; + $messages = [ + 'required' => 'Укажите обязательное поле', + ]; + $validator = Validator::make($params, $rules, $messages); + + if ($validator->fails()) { + return redirect()->route('admin.edit-ad-employers', ['ad_employer' => $ad_employer->id]) + ->withErrors($validator); + } else { + $ad_employer->update($params); + $ad_employer->jobs()->sync($request->position_work); + + return redirect()->route('admin.ad-employers') + ->with('success', 'Данные были успешно сохранены'); + } + return redirect()->route('admin.ad-employers'); } /** diff --git a/app/Http/Controllers/Admin/EmployersController.php b/app/Http/Controllers/Admin/EmployersController.php index 0574469..3e652f8 100644 --- a/app/Http/Controllers/Admin/EmployersController.php +++ b/app/Http/Controllers/Admin/EmployersController.php @@ -25,21 +25,19 @@ class EmployersController extends Controller $user->update($request->all()); } - /*$users = User::with('employers')->where('is_worker', '0'); - $find_key = ""; - if (isset($request->find)) { - $find_key = $request->find; - $users = $users->where(function($query) use($find_key) { - $query->Where('name', 'LIKE', "%$find_key%") - ->orWhere('email', 'LIKE', "%$find_key%") - ->orWhere('telephone', 'LIKE', "%$find_key%"); - }); - }*/ - $users = User::with('employers')->select(['users.*','users.id as usr_id', 'emp.id as emp_id', 'emp.*'])->join('employers as emp','emp.user_id','users.id') ->where('users.is_worker', '0'); $all_employer = $users->count(); + + $find_cat = ""; + if (isset($request->category)) { + if ($request->category != 'Все категории') { + $users = $users->where('category', '=', $request->category); + $find_cat = $request->category; + } + } $find_key = ""; + if (isset($request->find)) { $find_key = $request->find; $users = $users->where(function($query) use($find_key) { @@ -53,10 +51,12 @@ class EmployersController extends Controller $users = $users->paginate(15); //dd(DB::getQueryLog()); + $select_category = CategoryEmp::query()->active()->get(); + if ($request->ajax()) { return view('admin.employer.index_ajax', compact('users')); } else { - return view('admin.employer.index', compact('users', 'find_key', 'all_employer')); + return view('admin.employer.index', compact('users', 'find_key', 'find_cat', 'all_employer', 'select_category')); } } diff --git a/app/Http/Controllers/Admin/WorkersController.php b/app/Http/Controllers/Admin/WorkersController.php index 6a57bdd..c027b7b 100644 --- a/app/Http/Controllers/Admin/WorkersController.php +++ b/app/Http/Controllers/Admin/WorkersController.php @@ -8,7 +8,9 @@ use App\Models\Job_title; use App\Models\Static_worker; use App\Models\User; use App\Models\Worker; +use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; @@ -21,7 +23,41 @@ class WorkersController extends Controller $user->update($request->all()); } - $users = User::with('workers')->where('is_worker', '1'); + $status_work = Job_title::query()->active()->orderBy('name')->get(); + $users = User::with('jobtitles')->where('is_worker', '1'); + + $find_status_work = ""; + if (isset($request->status_work)) { + $find_status_work = $request->status_work; + //$users = $users->where('position_work', '=', $find_status_work); + + /*if ($request->status_work > 0) + $users = $users->with(['workers' => function($query) use ($find_status_work){ + $query->where('position_work', $find_status_work); + }]); + else + $users = $users->with('workers');*/ + + /*$users = $users->where(function($query) use($find_status_work) { + $query->with(['workers' => function($query1) use ($find_status_work){ + $query1->where('position_work', $find_status_work); + }]); + });*/ + if ($request->status_work > 0) { + $users = $users->with('workers')-> + whereHas('workers', + function (Builder $query) use ($find_status_work) { + $query->where('position_work', $find_status_work); + } + ); + } else { + $users = $users->with('workers'); + } + + } else { + $users = $users->with('workers'); + } + $find_key = ""; if (isset($request->find)) { $find_key = $request->find; @@ -34,10 +70,46 @@ class WorkersController extends Controller $users = $users->paginate(15); + /* + $Arr = array(); + $where = ''; + $find_status_work = ""; + if (isset($request->status_work)) { + $find_status_work = $request->status_work; + //$users = $users->where('position_work', '=', $find_status_work); + $where.= ' and (w.position_work = :uid1)'; + $Arr['uid1'] = $find_status_work; + } + + $find_key = ""; + if (isset($request->find)) { + $find_key = $request->find; + /*$users = $users->where(function($query) use($find_key) { + $query->Where('name_man', 'LIKE', "%$find_key%") + ->orWhere('email', 'LIKE', "%$find_key%") + ->orWhere('telephone', 'LIKE', "%$find_key%"); + });*/ + /*$where.= " and ((u.name_man LIKE %:uid2%) or (w.email LIKE %:uid2%) or (w.telephone LIKE %:uid2%))"; + $Arr['uid2'] = $find_key; + } + + //$users = $users->paginate(15); + + //DB::enableQueryLog(); + $users = DB::select('SELECT u.*, w.*, j.* + FROM workers w + JOIN users u ON u.id = w.user_id + JOIN job_titles j ON j.id = w.position_work + Where (u.is_worker = 1) + '.$where, $Arr); + //dump(DB::getQueryLog()); + dd($users); + */ + if ($request->ajax()) { return view('admin.worker.index_ajax', compact('users')); } else { - return view('admin.worker.index', compact('users', 'find_key')); + return view('admin.worker.index', compact('users', 'find_key', 'find_status_work', 'status_work')); } } diff --git a/app/Models/Ad_employer.php b/app/Models/Ad_employer.php index 2bd9d4d..b25d0a8 100644 --- a/app/Models/Ad_employer.php +++ b/app/Models/Ad_employer.php @@ -21,6 +21,9 @@ class Ad_employer extends Model 'sort', 'is_remove', 'active_is', + 'status', + 'sroch_vacancy', + 'favorite_vacancy' ]; /* * Связь таблицы employers с таблицей ad_employers diff --git a/app/Models/User.php b/app/Models/User.php index da0b697..6a040ee 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -74,6 +74,14 @@ class User extends Authenticatable } /* + * Связь Пользователей системы с работниками + * users - workers + */ + public function work() { + return $this->hasMany(Worker::class, 'user_id')->select('telephone', 'email', 'position_work', 'persent_anketa'); + } + + /* * Связь Модели Пользователей(Users) с Группами (Group_users) * users - group_users многие-ко-многим @@ -106,6 +114,15 @@ class User extends Authenticatable return $this->hasMany(Group_works::class); } + /* + * Связь Модели Пользователей(Users) с Группами (Group_users) + * users - group_users + многие-ко-многим + */ + public function jobtitles() { + return $this->belongsToMany(Job_title::class, 'Workers', 'user_id', 'position_work'); + } + public function scopeActive($query) { return $query->where('is_remove', '=', '0'); } diff --git a/resources/views/admin/ad_employers/edit.blade.php b/resources/views/admin/ad_employers/edit.blade.php new file mode 100644 index 0000000..c496a79 --- /dev/null +++ b/resources/views/admin/ad_employers/edit.blade.php @@ -0,0 +1,93 @@ +@extends('layout.admin', ['title' => 'Админка - Редактирование вакансии']) + +@section('script') + +@endsection + +@section('content') +

+ Редактирование вакансии +

+
+ @csrf +
+ + + + +
+ + + +
+
+ + Назад +
+
+
+
+@endsection diff --git a/resources/views/admin/ad_employers/index.blade.php b/resources/views/admin/ad_employers/index.blade.php index fd8d1fe..154bc01 100644 --- a/resources/views/admin/ad_employers/index.blade.php +++ b/resources/views/admin/ad_employers/index.blade.php @@ -4,32 +4,7 @@ @endsection @section('search') - + @endsection @section('content') @@ -43,10 +18,13 @@ № Название объявления Название компании - Вакансии - Город - З/п - Дата + Должности + Избранные + Срочные + Статус + Дата создан. + Дата изменен. + Изменить @@ -80,15 +58,45 @@ + + + @if ($ad->favorite_vacancy==1) + + Да + + @else + + Нет + + @endif + + - {{ $ad->city }} + @if ($ad->sroch_vacancy==1) + + Да + + @else + + Нет + + @endif + - {{ $ad->salary }} + {{ $ad->status }} {{ $ad->created_at }} + + {{ $ad->updated_at }} + + + + Изменить + + @endforeach diff --git a/resources/views/admin/employer/index.blade.php b/resources/views/admin/employer/index.blade.php index b624501..2b65a7d 100644 --- a/resources/views/admin/employer/index.blade.php +++ b/resources/views/admin/employer/index.blade.php @@ -39,7 +39,7 @@ @endsection @section('search') - @include('admin.find') + @include('admin.find_employer', ['select_category' => $select_category]) @endsection @section('content') diff --git a/resources/views/admin/find_employer.blade.php b/resources/views/admin/find_employer.blade.php new file mode 100644 index 0000000..a8c5cb8 --- /dev/null +++ b/resources/views/admin/find_employer.blade.php @@ -0,0 +1,41 @@ +
+ +
+
+
+
+
+ +
+
+ +
+
diff --git a/resources/views/admin/find_worker.blade.php b/resources/views/admin/find_worker.blade.php new file mode 100644 index 0000000..cb6bb77 --- /dev/null +++ b/resources/views/admin/find_worker.blade.php @@ -0,0 +1,41 @@ +
+ +
+
+
+
+
+ +
+
+ +
+
diff --git a/resources/views/admin/worker/index.blade.php b/resources/views/admin/worker/index.blade.php index 3f623d1..e197005 100644 --- a/resources/views/admin/worker/index.blade.php +++ b/resources/views/admin/worker/index.blade.php @@ -39,7 +39,7 @@ @endsection @section('search') - @include('admin.find') + @include('admin.find_worker', ['find_status_work' => $find_status_work]) @endsection @section('content') @@ -54,9 +54,10 @@ Имя Email/Телефон % заполнения анкеты + Должность Дата регистрации Изменить - Бан + @@ -79,23 +80,30 @@ - @if (!empty($user->workers->persent_anketa)) - @if ($user->workers->persent_anketa > 40) + @if (isset($user->workers[0]->persent_anketa)) + @if ($user->workers[0]->persent_anketa > 40) - {{$user->workers->persent_anketa}}% + {{$user->workers[0]->persent_anketa}}% @else - {{$user->workers->persent_anketa}}% + {{$user->workers[0]->persent_anketa}}% @endif @else - 10% + 0% @endif + @if (isset($user->jobtitles[0]->name)) + {{ $user->jobtitles[0]->name }} + @else + Не задана + @endif + + {{ $user->created_at }} diff --git a/resources/views/admin/worker/index_ajax.blade.php b/resources/views/admin/worker/index_ajax.blade.php index 0e5e9a7..b000ff5 100644 --- a/resources/views/admin/worker/index_ajax.blade.php +++ b/resources/views/admin/worker/index_ajax.blade.php @@ -8,6 +8,7 @@ Имя Email/Телефон % заполнения анкеты + Должность Дата регистрации Изменить Бан @@ -33,28 +34,38 @@ - @if (!empty($user->workers->persent_anketa)) - @if ($user->workers->persent_anketa > 40) + @if (isset($user->workers[0]->persent_anketa)) + @if ($user->workers[0]->persent_anketa > 40) - {{$user->workers->persent_anketa}}% + {{$user->workers[0]->persent_anketa}}% @else - {{$user->workers->persent_anketa}}% + {{$user->workers[0]->persent_anketa}}% @endif @else - 10% + 0% @endif + @if (isset($user->jobtitles[0]->name)) + {{ $user->jobtitles[0]->name }} + @else + Не задана + @endif + + {{ $user->created_at }} @if ($user->id > 1) - Изменить + @if (isset($user->workers[0]->id)) + Изменить + + @endif @endif diff --git a/routes/web.php b/routes/web.php index b5aa8cf..c24354a 100644 --- a/routes/web.php +++ b/routes/web.php @@ -138,7 +138,7 @@ Route::group([ // кабинет профиль админа - форма Route::get('profile', [AdminController::class, 'profile'])->name('profile'); - // кабинет профиль админа - сохранение формы + // кабинет профиль админа - сохранение формы Route::post('profile', [AdminController::class, 'store_profile'])->name('store_profile'); //кабинет сообщения админа @@ -188,6 +188,8 @@ Route::group([ // кабинет - вакансии Route::get('ad-employers', [Ad_EmployersController::class, 'index'])->name('ad-employers'); + Route::get('ad-employers/edit/{ad_employer}', [Ad_EmployersController::class, 'edit'])->name('edit-ad-employers'); + Route::post('ad-employers/edit/{ad_employer}', [Ad_EmployersController::class, 'update'])->name('update-ad-employers'); // кабинет - категории //Route::get('categories', [AdminController::class, 'index'])->name('categories'); -- 1.7.10.4