Commit e2907a5767314335bf4860c2cf3a968b37831e8c

Authored by Hayk Nazaryan
1 parent e262a331f3
Exists in master

workers fixes

Showing 5 changed files with 166 additions and 16 deletions Side-by-side Diff

app/Console/Commands/ResetData.php
... ... @@ -0,0 +1,131 @@
  1 +<?php
  2 +
  3 +namespace App\Console\Commands;
  4 +
  5 +use App\Models\Ad_employer;
  6 +use App\Models\Ad_jobs;
  7 +use App\Models\ad_response;
  8 +use App\Models\Answer;
  9 +use App\Models\Chat;
  10 +use App\Models\Contacts;
  11 +use App\Models\Dop_info;
  12 +use App\Models\Employer;
  13 +use App\Models\EmployerAutoliftOption;
  14 +use App\Models\employers_main;
  15 +use App\Models\Flot;
  16 +use App\Models\Group_user;
  17 +use App\Models\Group_works;
  18 +use App\Models\Like_vacancy;
  19 +use App\Models\Like_worker;
  20 +use App\Models\Media;
  21 +use App\Models\Message;
  22 +use App\Models\MessagesRequests;
  23 +use App\Models\PrevCompany;
  24 +use App\Models\ResponseWork;
  25 +use App\Models\Static_ad;
  26 +use App\Models\Static_worker;
  27 +use App\Models\Title_worker;
  28 +use App\Models\User;
  29 +use App\Models\WorkerAutoliftOption;
  30 +use Illuminate\Console\Command;
  31 +use Illuminate\Support\Facades\Hash;
  32 +
  33 +class ResetData extends Command
  34 +{
  35 + /**
  36 + * The name and signature of the console command.
  37 + *
  38 + * @var string
  39 + */
  40 + protected $signature = 'reset:data';
  41 +
  42 + /**
  43 + * The console command description.
  44 + *
  45 + * @var string
  46 + */
  47 + protected $description = 'Command description';
  48 +
  49 + /**
  50 + * Execute the console command.
  51 + *
  52 + * @return int
  53 + */
  54 + public function handle()
  55 + {
  56 + $users = User::query()
  57 + ->whereHas('workers')
  58 + ->where('is_bd', 0)
  59 + ->where('created_at', '<', '2024-11-30 00:00:00')
  60 + ->whereNotIn('email', [
  61 + 'vkontakte@rekamore.su',
  62 + '2anketa@rekamore.su'
  63 + ])
  64 + ->get();
  65 +
  66 + foreach ($users as $user) {
  67 + Answer::query()->where(['user_id' => $user->id])->delete();
  68 +
  69 + Chat::query()->where(['user_id' => $user->id])->delete();
  70 + Chat::query()->where(['to_user_id' => $user->id])->delete();
  71 + Message::query()->where(['user_id' => $user->id])->delete();
  72 + Message::query()->where(['to_user_id' => $user->id])->delete();
  73 + MessagesRequests::query()->where(['user_id' => $user->id])->delete();
  74 +
  75 + Group_user::query()->where(['user_id' => $user->id])->get()->map(function ($groupUser) {
  76 + Group_works::query()->where(['group_user_id' => $groupUser->id])->delete();
  77 + $groupUser->delete();
  78 + });
  79 +
  80 + Like_vacancy::query()->where(['user_id' => (string)$user->id])->delete();
  81 + Like_worker::query()->where(['user_id' => (string)$user->id])->delete();
  82 + Media::query()->where(['user_id' => $user->id])->delete();
  83 + Static_worker::query()->where(['user_id' => $user->id])->delete();
  84 +
  85 +// $user->employers()->get()->map(function ($employer) {
  86 +// Answer::query()->where(['employer_id' => $employer->id])->delete();
  87 +//
  88 +// Ad_employer::query()->where(['employer_id' => $employer->id])->get()->map(function ($adEmployer) {
  89 +// Ad_jobs::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  90 +// ad_response::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  91 +// Static_ad::query()->where(['ad_employer_id' => $adEmployer->id])->delete();
  92 +// Like_vacancy::query()->where(['code_record' => $adEmployer->id])->delete();
  93 +//
  94 +// $adEmployer->delete();
  95 +// });
  96 +//
  97 +// Contacts::query()->where(['employer_id' => $employer->id])->delete();
  98 +// employers_main::query()->where(['employer_id' => $employer->id])->delete();
  99 +// EmployerAutoliftOption::query()->where(['employer_id' => $employer->id])->delete();
  100 +//
  101 +// Flot::query()->where(['employer_id' => $employer->id])->delete();
  102 +//
  103 +// $employer->delete();
  104 +// });
  105 +
  106 + $user->workers()->get()->map(function ($worker) {
  107 + Dop_info::query()->where(['worker_id' => $worker->id])->delete();
  108 + PrevCompany::query()->where(['worker_id' => $worker->id])->delete();
  109 + ResponseWork::query()->where(['worker_id' => $worker->id])->delete();
  110 + Like_worker::query()->where(['code_record' => $worker->id])->delete();
  111 + Title_worker::query()->where(['worker_id' => $worker->id])->delete();
  112 + WorkerAutoliftOption::query()->where(['worker_id' => $worker->id])->delete();
  113 + $worker->delete();
  114 + });
  115 +
  116 + $user->delete();
  117 +
  118 + }
  119 +
  120 + User::query()->where('password', 1234567890)->get()->map(function ($userBd) {
  121 + $password = $userBd->password;
  122 +
  123 + $userBd->update([
  124 + 'password' => Hash::make($password),
  125 + 'pubpassword' => base64_encode($password),
  126 + ]);
  127 + });
  128 +
  129 + return Command::SUCCESS;
  130 + }
  131 +}
app/Http/Controllers/Admin/UsersController.php
... ... @@ -10,6 +10,7 @@ use App\Models\User;
10 10 use App\Models\Worker;
11 11 use Illuminate\Http\Request;
12 12 use Illuminate\Support\Facades\Auth;
  13 +use Illuminate\Support\Facades\Hash;
13 14 use Illuminate\Support\Facades\Storage;
14 15 use PhpOffice\PhpSpreadsheet\Spreadsheet;
15 16 use PhpOffice\PhpSpreadsheet\Style\Alignment;
... ... @@ -104,6 +105,10 @@ class UsersController extends Controller
104 105 $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2;
105 106 }
106 107  
  108 + $password = $params['password'];
  109 + $params['password'] = Hash::make($password);
  110 + $params['pubpassword'] = base64_encode($password);
  111 +
107 112 $user = User::create($params);
108 113 $worker = new Worker();
109 114 $worker->positions_work = isset($params['positions_work']) ? json_encode($params['positions_work']) : [];
app/Http/Controllers/Admin/WorkersController.php
... ... @@ -34,25 +34,25 @@ class WorkersController extends Controller
34 34 $find_status_work = $request->status_work;
35 35  
36 36 if ($request->status_work > 0) {
37   - $users = $users->with('workers')->
  37 + $users = $users->
38 38 whereHas('workers',
39 39 function (Builder $query) use ($find_status_work) {
40 40 $query->where('position_work', $find_status_work);
41 41 }
42 42 );
43 43 } else {
44   - $users = $users->with('workers');
  44 + $users = $users->whereHas('workers');
45 45 }
46 46  
47 47 } else {
48   - $users = $users->with('workers');
  48 + $users = $users->whereHas('workers');
49 49 }
50 50  
51 51 $find_key = "";
52 52 if (isset($request->find)) {
53 53 $find_key = $request->find;
54 54 $users = $users->where(function($query) use($find_key) {
55   - $query->Where('name_man', 'LIKE', "%$find_key%")
  55 + $query->where('name_man', 'LIKE', "%$find_key%")
56 56 ->orWhere('email', 'LIKE', "%$find_key%")
57 57 ->orWhere('telephone', 'LIKE', "%$find_key%")
58 58 ->orWhere('surname', 'LIKE', "%$find_key%")
... ... @@ -60,7 +60,9 @@ class WorkersController extends Controller
60 60 });
61 61 }
62 62  
63   - $users = $users->orderByDesc('id')->Realuser()->paginate(15);
  63 + $all_worker = $users->count();
  64 +
  65 + $users = $users->orderByDesc('id')->paginate(15);
64 66  
65 67 $status_wor = WorkerStatuses::getWorkerStatuses();
66 68  
resources/views/admin/worker/index.blade.php
... ... @@ -72,7 +72,7 @@
72 72 >
73 73 <th class="px-4 py-3">№</th>
74 74 <th class="px-4 py-3">Лого</th>
75   - <th class="px-4 py-3">ФИО/Email/Телефон</th>
  75 + <th class="px-4 py-3">ФИО/Email/Телефон/Пароль</th>
76 76 <th class="px-4 py-3">Статус</th>
77 77 <th class="px-4 py-3">% анкеты</th>
78 78 <th class="px-4 py-3">Должность</th>
... ... @@ -116,16 +116,23 @@
116 116 <div class="flex items-center text-sm">
117 117 <div>
118 118 <p class="font-semibold">
119   - @if (isset($user->id))
120   - <a style="text-decoration: underline;" href="{{ route('admin.user-profile', ['user' => $user->id]) }}}">{{ $user->surname }} {{ !empty($user->name_man) ? $user->name_man : $user->name }} {{ $user->surname2 }}</a>
121   - @else
122   - {{ $user->surname }} {{ !empty($user->name_man) ? $user->name_man : $user->name }} {{ $user->surname2 }}
123   - @endif
  119 + @if (isset($user->id))
  120 + <a style="text-decoration: underline;"
  121 + href="{{ route('admin.user-profile', ['user' => $user->id]) }}}">{{ $user->surname }} {{ !empty($user->name_man) ? $user->name_man : $user->name }} {{ $user->surname2 }}</a>
  122 + @else
  123 + {{ $user->surname }} {{ !empty($user->name_man) ? $user->name_man : $user->name }} {{ $user->surname2 }}
  124 + @endif
  125 + </p>
  126 +{{-- <p class="font-semibold">{{ empty($user->workers->email) ? $user->email : $user->workers->email }}</p>--}}
  127 + <p class="font-semibold">{{ $user->email }}</p>
  128 + <p class="text-xs text-gray-600 dark:text-gray-400">
  129 + {{ empty($user->workers->telephone) ? $user->telephone : $user->workers->telephone }}
  130 + </p>
  131 + <p class="text-xs text-gray-600 dark:text-gray-400">
  132 + @if (!empty($user->pubpassword))
  133 + {{ base64_decode($user->pubpassword) }}
  134 + @endif
124 135 </p>
125   - <p class="font-semibold">{{ empty($user->workers->email) ? $user->email : $user->workers->email }}</p>
126   - <p class="text-xs text-gray-600 dark:text-gray-400">
127   - {{ empty($user->workers->telephone) ? $user->telephone : $user->workers->telephone }}
128   - </p>
129 136 </div>
130 137 </div>
131 138 </td>
resources/views/admin/worker/index_ajax.blade.php
... ... @@ -7,7 +7,7 @@
7 7 >
8 8 <th class="px-4 py-3">№</th>
9 9 <th class="px-4 py-3">Лого</th>
10   - <th class="px-4 py-3">ФИО/Email/Телефон</th>
  10 + <th class="px-4 py-3">ФИО/Email/Телефон/Пароль</th>
11 11 <th class="px-4 py-3">Статус</th>
12 12 <th class="px-4 py-3">% анкеты</th>
13 13 <th class="px-4 py-3">Должность</th>
... ... @@ -58,6 +58,11 @@
58 58 <p class="text-xs text-gray-600 dark:text-gray-400">
59 59 {{ empty($user->workers->telephone) ? $user->telephone : $user->workers->telephone }}
60 60 </p>
  61 + <p class="text-xs text-gray-600 dark:text-gray-400">
  62 + @if (!empty($user->pubpassword))
  63 + {{ base64_decode($user->pubpassword) }}
  64 + @endif
  65 + </p>
61 66 </div>
62 67 </div>
63 68 </td>