diff --git a/app/Classes/Tools.php b/app/Classes/Tools.php index a21a5f5..e1fa65a 100644 --- a/app/Classes/Tools.php +++ b/app/Classes/Tools.php @@ -51,13 +51,13 @@ class Tools ]; foreach ($workerFields as $fieldName) { - if (!empty($Worker->$fieldName)) { + if (!empty($Worker->$fieldName) && $Worker->$fieldName !== 'Не указано') { $persent += 2.8; } } foreach ($workerUserFields as $fieldName) { - if (!empty($Worker->user->$fieldName)) { + if (!empty($Worker->users->$fieldName)) { $persent += 2.8; } } diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index b8d80f2..3db42d8 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -566,8 +566,10 @@ class EmployerController extends Controller } // Данные - $users = $users->Baseuser()-> - orderByDesc(Worker::select('created_at')->whereColumn('workers.user_id', 'users.id')); + $users = $users + ->Baseuser() + ->orderByDesc(Worker::select('created_at') + ->whereColumn('workers.user_id', 'users.id')); $count_users = $users->count(); $users = $users->paginate(10); diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index c3f244d..67903c8 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -30,6 +30,7 @@ use Illuminate\Auth\Events\Registered; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; @@ -247,15 +248,14 @@ class WorkerController extends Controller $status_work = WorkerStatuses::getWorkerStatuses(); $infoblocks = infobloks::query()->get(); - //dd($Query[0]); - return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); + //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); $pdf = PDF::loadView('layout.pdf', [ 'Query' => $Query, 'status_work' => $status_work, 'infoblocks' => $infoblocks ])->setPaper('a4', 'landscape'); - return $pdf->stream(); + return $pdf->download(); } public function resume_download_all(Request $request) { @@ -276,18 +276,26 @@ class WorkerController extends Controller return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.'); } - $query = User::select($columns) - ->leftJoin('workers', 'users.id', '=', 'workers.user_id') - ->leftJoin('job_titles', 'workers.position_work', '=', 'job_titles.id') - ->where('users.is_bd', '=', 1); + $jobIds = $request->input('job_title_list', []); + + $users = DB::select( + "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` + from users + join workers on `users`.`id` = `workers`.`user_id` + join `job_titles` + where `users`.`is_bd` = 1 + and (`workers`.`position_work` = `job_titles`.`id` + or exists (select 1 + from JSON_TABLE( + workers.positions_work, + '$[*]' COLUMNS (id INT PATH '$')) pw + where pw.id = job_titles.id) + )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') + ); - $job_title_list = $request->input('job_title_list', []); - if (!empty($job_title_list)){ - $query->whereIn('job_titles.id', $job_title_list); - } + $users = collect($users); - $users = $query->get(); - if ($users->count()){ + if ($users->count()) { $i = 2; foreach ($users->toArray() as $user){ $j = 0; @@ -580,40 +588,12 @@ class WorkerController extends Controller return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); } - /*$haystack = $request->get('password'); - - $specsumbol = Array('!','~', '#', '$', '%', '^', '&', '*', '(', ')', '-', '=', ';', ':', '<', '>', '?'); - $alpha = Array('Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', - 'X', 'C', 'V', 'B', 'N', 'M'); - $lenpwd_bool = true; - $spec_bool = false; - $alpha_bool = false; - - if (strlen($haystack) < 8) $lenpwd_bool = false; - - foreach ($specsumbol as $it) { - if (strpos($haystack, $it) !== false) { - $spec_bool = true; - } - } - - foreach ($alpha as $it) { - if (strpos($haystack, $it) !== false) { - $alpha_bool = true; - } - } - - if ((!$spec_bool) || (!$alpha_bool)) { - return json_encode(Array("ERROR" => "Error: Нет спецсимволов в пароле, латинские буквы заглавные, а также один из символов: !~#$%^&*()-=;,:<>?")); - }*/ - if (($request->has('politik')) && ($request->get('politik') == 1)) { $validator = Validator::make($params, $rules, $messages); if ($validator->fails()) { return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); } else { - //dd($params); $user = $this->create($params); event(new Registered($user)); Auth::guard()->login($user); diff --git a/app/Models/User.php b/app/Models/User.php index 358efde..07baaf0 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Foundation\Auth\User as Authenticatable; use Illuminate\Notifications\Notifiable; +use JsonException; use Laravel\Sanctum\HasApiTokens; class User extends Authenticatable @@ -87,7 +88,8 @@ class User extends Authenticatable * users - workers */ public function work() { - return $this->hasMany(Worker::class, 'user_id')->select('telephone', 'email', 'position_work', 'persent_anketa'); + return $this->hasMany(Worker::class, 'user_id') + ->select('telephone', 'email', 'position_work', 'persent_anketa'); } /* @@ -156,4 +158,22 @@ class User extends Authenticatable return $query->where('admin', '=', '0'); } + /** + * @throws JsonException + */ + public function getJobAttribute(): ?string + { + $positions = $this->workers[0]?->positions_work; + if (is_string($positions)) { + $jobIds = json_decode($positions, true, 512, JSON_THROW_ON_ERROR); + } else { + $jobIds = $positions; + } + + if ($jobIds !== null && count($jobIds) > 0) { + return Job_title::whereIn('id', $jobIds)->first()->name; + } + return null; + } + } diff --git a/resources/views/admin/worker/edit.blade.php b/resources/views/admin/worker/edit.blade.php index 49b16b4..32985ba 100644 --- a/resources/views/admin/worker/edit.blade.php +++ b/resources/views/admin/worker/edit.blade.php @@ -15,48 +15,59 @@ use Illuminate\Support\Facades\Storage; -