Commit bc71e803a9dbd22d5e930328ce91cc33a9dbd485
1 parent
40290093cd
Exists in
master
fix worker register error
Showing 1 changed file with 1 additions and 1 deletions Inline Diff
app/Http/Controllers/WorkerController.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Http\Controllers; | 3 | namespace App\Http\Controllers; |
4 | 4 | ||
5 | use App\Classes\RusDate; | 5 | use App\Classes\RusDate; |
6 | use App\Classes\Tools; | 6 | use App\Classes\Tools; |
7 | use App\Http\Requests\DocumentsRequest; | 7 | use App\Http\Requests\DocumentsRequest; |
8 | use App\Http\Requests\PrevCompanyRequest; | 8 | use App\Http\Requests\PrevCompanyRequest; |
9 | use App\Http\Requests\SertificationRequest; | 9 | use App\Http\Requests\SertificationRequest; |
10 | use App\Models\Ad_employer; | 10 | use App\Models\Ad_employer; |
11 | use App\Models\ad_response; | 11 | use App\Models\ad_response; |
12 | use App\Models\Chat; | 12 | use App\Models\Chat; |
13 | use App\Models\Dop_info; | 13 | use App\Models\Dop_info; |
14 | use App\Models\Employer; | 14 | use App\Models\Employer; |
15 | use App\Models\EmployerAutoliftOption; | 15 | use App\Models\EmployerAutoliftOption; |
16 | use App\Models\infobloks; | 16 | use App\Models\infobloks; |
17 | use App\Models\Job_title; | 17 | use App\Models\Job_title; |
18 | use App\Models\Like_vacancy; | 18 | use App\Models\Like_vacancy; |
19 | use App\Models\Message; | 19 | use App\Models\Message; |
20 | use App\Models\place_works; | 20 | use App\Models\place_works; |
21 | use App\Models\PrevCompany; | 21 | use App\Models\PrevCompany; |
22 | use App\Models\ResponseWork; | 22 | use App\Models\ResponseWork; |
23 | use App\Models\sertification; | 23 | use App\Models\sertification; |
24 | use App\Models\Static_worker; | 24 | use App\Models\Static_worker; |
25 | use App\Models\Title_worker; | 25 | use App\Models\Title_worker; |
26 | use App\Models\User; | 26 | use App\Models\User; |
27 | use App\Models\User as User_Model; | 27 | use App\Models\User as User_Model; |
28 | use App\Models\Worker; | 28 | use App\Models\Worker; |
29 | use App\Models\WorkerAutoliftOption; | 29 | use App\Models\WorkerAutoliftOption; |
30 | use Barryvdh\DomPDF\Facade\Pdf; | 30 | use Barryvdh\DomPDF\Facade\Pdf; |
31 | use Carbon\Carbon; | 31 | use Carbon\Carbon; |
32 | use Illuminate\Auth\Events\Registered; | 32 | use Illuminate\Auth\Events\Registered; |
33 | use Illuminate\Database\Eloquent\Builder; | 33 | use Illuminate\Database\Eloquent\Builder; |
34 | use Illuminate\Http\RedirectResponse; | 34 | use Illuminate\Http\RedirectResponse; |
35 | use Illuminate\Http\Request; | 35 | use Illuminate\Http\Request; |
36 | use Illuminate\Pagination\LengthAwarePaginator; | 36 | use Illuminate\Pagination\LengthAwarePaginator; |
37 | use Illuminate\Support\Facades\Auth; | 37 | use Illuminate\Support\Facades\Auth; |
38 | use Illuminate\Support\Facades\DB; | 38 | use Illuminate\Support\Facades\DB; |
39 | use Illuminate\Support\Facades\Hash; | 39 | use Illuminate\Support\Facades\Hash; |
40 | use Illuminate\Support\Facades\Storage; | 40 | use Illuminate\Support\Facades\Storage; |
41 | use Illuminate\Support\Facades\Validator; | 41 | use Illuminate\Support\Facades\Validator; |
42 | use Illuminate\View\View; | 42 | use Illuminate\View\View; |
43 | use JsonException; | 43 | use JsonException; |
44 | use PhpOffice\PhpSpreadsheet\Spreadsheet; | 44 | use PhpOffice\PhpSpreadsheet\Spreadsheet; |
45 | use PhpOffice\PhpSpreadsheet\Writer\Xlsx; | 45 | use PhpOffice\PhpSpreadsheet\Writer\Xlsx; |
46 | use Symfony\Component\HttpFoundation\StreamedResponse; | 46 | use Symfony\Component\HttpFoundation\StreamedResponse; |
47 | use App\Enums\DbExportColumns; | 47 | use App\Enums\DbExportColumns; |
48 | use App\Enums\WorkerStatuses; | 48 | use App\Enums\WorkerStatuses; |
49 | use DateTime; | 49 | use DateTime; |
50 | 50 | ||
51 | class WorkerController extends Controller | 51 | class WorkerController extends Controller |
52 | { | 52 | { |
53 | //профиль | 53 | //профиль |
54 | public function profile(Worker $worker) | 54 | public function profile(Worker $worker) |
55 | { | 55 | { |
56 | $get_date = date('Y.m'); | 56 | $get_date = date('Y.m'); |
57 | 57 | ||
58 | $c = Static_worker::query()->where('year_month', '=', $get_date) | 58 | $c = Static_worker::query()->where('year_month', '=', $get_date) |
59 | ->where('user_id', '=', $worker->users->id) | 59 | ->where('user_id', '=', $worker->users->id) |
60 | ->get(); | 60 | ->get(); |
61 | 61 | ||
62 | if ($c->count() > 0) { | 62 | if ($c->count() > 0) { |
63 | $upd = Static_worker::find($c[0]->id); | 63 | $upd = Static_worker::find($c[0]->id); |
64 | $upd->lookin = $upd->lookin + 1; | 64 | $upd->lookin = $upd->lookin + 1; |
65 | $upd->save(); | 65 | $upd->save(); |
66 | } else { | 66 | } else { |
67 | $crt = new Static_worker(); | 67 | $crt = new Static_worker(); |
68 | $crt->lookin = 1; | 68 | $crt->lookin = 1; |
69 | $crt->year_month = $get_date; | 69 | $crt->year_month = $get_date; |
70 | $crt->user_id = $worker->user_id; | 70 | $crt->user_id = $worker->user_id; |
71 | $crt->save(); | 71 | $crt->save(); |
72 | } | 72 | } |
73 | 73 | ||
74 | $stat = Static_worker::query()->where('year_month', '=', $get_date) | 74 | $stat = Static_worker::query()->where('year_month', '=', $get_date) |
75 | ->where('user_id', '=', $worker->users->id) | 75 | ->where('user_id', '=', $worker->users->id) |
76 | ->get(); | 76 | ->get(); |
77 | 77 | ||
78 | return view('public.workers.profile', compact('worker', 'stat')); | 78 | return view('public.workers.profile', compact('worker', 'stat')); |
79 | } | 79 | } |
80 | 80 | ||
81 | // лист база резюме | 81 | // лист база резюме |
82 | public function bd_resume(Request $request) | 82 | public function bd_resume(Request $request) |
83 | { | 83 | { |
84 | 84 | ||
85 | if (!Auth::check()) { | 85 | if (!Auth::check()) { |
86 | 86 | ||
87 | return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"])->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); | 87 | return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"])->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); |
88 | 88 | ||
89 | } | 89 | } |
90 | if ((Auth::user()->is_worker) || (!Auth()->user()->is_lookin)) | 90 | if ((Auth::user()->is_worker) || (!Auth()->user()->is_lookin)) |
91 | return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"])->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); | 91 | return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"])->withErrors(['errors' => ['Вы не можете просматривать базу резюме. Подробнее в меню: "Условия размещения"']]); |
92 | 92 | ||
93 | 93 | ||
94 | $status_work = WorkerStatuses::getWorkerStatuses(); | 94 | $status_work = WorkerStatuses::getWorkerStatuses(); |
95 | 95 | ||
96 | $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at'); | 96 | $resumes = Worker::query()->with('users')->with('job_titles')->orderByDesc('updated_at'); |
97 | $resumes = $resumes->whereHas('users', function (Builder $query) { | 97 | $resumes = $resumes->whereHas('users', function (Builder $query) { |
98 | $query->Where('is_worker', '=', '1') | 98 | $query->Where('is_worker', '=', '1') |
99 | ->Where('is_bd', '=', '0'); | 99 | ->Where('is_bd', '=', '0'); |
100 | }); | 100 | }); |
101 | 101 | ||
102 | if (($request->has('job')) && ($request->get('job') > 0)) { | 102 | if (($request->has('job')) && ($request->get('job') > 0)) { |
103 | $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { | 103 | $resumes = $resumes->whereHas('job_titles', function (Builder $query) use ($request) { |
104 | $query->Where('job_titles.id', $request->get('job')); | 104 | $query->Where('job_titles.id', $request->get('job')); |
105 | }); | 105 | }); |
106 | } | 106 | } |
107 | 107 | ||
108 | $Job_title = Job_title::query() | 108 | $Job_title = Job_title::query() |
109 | ->where('is_remove', '=', '0') | 109 | ->where('is_remove', '=', '0') |
110 | ->where('is_bd', '=' , '1') | 110 | ->where('is_bd', '=' , '1') |
111 | ->orderByDesc('sort') | 111 | ->orderByDesc('sort') |
112 | ->get(); | 112 | ->get(); |
113 | 113 | ||
114 | if ($request->get('sort')) { | 114 | if ($request->get('sort')) { |
115 | $sort = $request->get('sort'); | 115 | $sort = $request->get('sort'); |
116 | switch ($sort) { | 116 | switch ($sort) { |
117 | case 'looking_for_work': | 117 | case 'looking_for_work': |
118 | $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); | 118 | $resumes->where('status_work', '=', WorkerStatuses::LookingForWork->value); |
119 | break; | 119 | break; |
120 | case 'considering_offers': | 120 | case 'considering_offers': |
121 | $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); | 121 | $resumes->where('status_work', '=', WorkerStatuses::ConsideringOffers->value); |
122 | break; | 122 | break; |
123 | case 'not_looking_for_work': | 123 | case 'not_looking_for_work': |
124 | $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); | 124 | $resumes->where('status_work', '=', WorkerStatuses::NotLookingForWork->value); |
125 | break; | 125 | break; |
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | $resumes = $resumes->get()->filter(function ($worker) { | 129 | $resumes = $resumes->get()->filter(function ($worker) { |
130 | return Tools::getWorkerProfilePercent($worker) >= 50; | 130 | return Tools::getWorkerProfilePercent($worker) >= 50; |
131 | }); | 131 | }); |
132 | 132 | ||
133 | $res_count = $resumes->count(); | 133 | $res_count = $resumes->count(); |
134 | 134 | ||
135 | $currentPage = $_GET['page'] ?? 1; | 135 | $currentPage = $_GET['page'] ?? 1; |
136 | $resumes = new LengthAwarePaginator( | 136 | $resumes = new LengthAwarePaginator( |
137 | items: $resumes->slice(4 * ($currentPage - 1), 4), | 137 | items: $resumes->slice(4 * ($currentPage - 1), 4), |
138 | total: $res_count, | 138 | total: $res_count, |
139 | perPage: 4, | 139 | perPage: 4, |
140 | ); | 140 | ); |
141 | $resumes->setPath('bd-resume'); | 141 | $resumes->setPath('bd-resume'); |
142 | 142 | ||
143 | if ($request->ajax()) { | 143 | if ($request->ajax()) { |
144 | // Условия обставлены | 144 | // Условия обставлены |
145 | if ($request->has('block') && ($request->get('block') == 1)) { | 145 | if ($request->has('block') && ($request->get('block') == 1)) { |
146 | return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count')); | 146 | return view('ajax.resume_1', compact('resumes', 'status_work', 'res_count')); |
147 | } | 147 | } |
148 | } else { | 148 | } else { |
149 | return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title')); | 149 | return view('resume', compact('resumes', 'status_work', 'res_count', 'Job_title')); |
150 | } | 150 | } |
151 | } | 151 | } |
152 | 152 | ||
153 | public function basic_information(){ | 153 | public function basic_information(){ |
154 | if (!isset(Auth()->user()->id)) { | 154 | if (!isset(Auth()->user()->id)) { |
155 | abort(404); | 155 | abort(404); |
156 | } | 156 | } |
157 | 157 | ||
158 | $user_id = Auth()->user()->id; | 158 | $user_id = Auth()->user()->id; |
159 | 159 | ||
160 | $user = User::query() | 160 | $user = User::query() |
161 | ->with('workers') | 161 | ->with('workers') |
162 | ->with(['jobtitles' => function ($query) { | 162 | ->with(['jobtitles' => function ($query) { |
163 | $query->select('job_titles.id'); | 163 | $query->select('job_titles.id'); |
164 | }]) | 164 | }]) |
165 | ->where('id', '=', $user_id) | 165 | ->where('id', '=', $user_id) |
166 | ->first(); | 166 | ->first(); |
167 | $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray(); | 167 | $user->workers[0]->job_titles = $user->workers[0]->job_titles->pluck('id')->toArray(); |
168 | 168 | ||
169 | $job_titles = Job_title::query() | 169 | $job_titles = Job_title::query() |
170 | ->where('is_remove', '=', 0) | 170 | ->where('is_remove', '=', 0) |
171 | ->where('is_bd', '=', 1) | 171 | ->where('is_bd', '=', 1) |
172 | ->orderByDesc('sort') | 172 | ->orderByDesc('sort') |
173 | ->get() | 173 | ->get() |
174 | ; | 174 | ; |
175 | 175 | ||
176 | return view('workers.form_basic_information', compact('user', 'job_titles')); | 176 | return view('workers.form_basic_information', compact('user', 'job_titles')); |
177 | } | 177 | } |
178 | 178 | ||
179 | public function additional_documents(){ | 179 | public function additional_documents(){ |
180 | if (!isset(Auth()->user()->id)) { | 180 | if (!isset(Auth()->user()->id)) { |
181 | abort(404); | 181 | abort(404); |
182 | } | 182 | } |
183 | 183 | ||
184 | $user_id = Auth()->user()->id; | 184 | $user_id = Auth()->user()->id; |
185 | 185 | ||
186 | $info_blocks = infobloks::query()->OrderBy('name')->get(); | 186 | $info_blocks = infobloks::query()->OrderBy('name')->get(); |
187 | $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; | 187 | $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; |
188 | 188 | ||
189 | $worker = Worker::query() | 189 | $worker = Worker::query() |
190 | ->with('users') | 190 | ->with('users') |
191 | ->with('infobloks') | 191 | ->with('infobloks') |
192 | ->WhereHas('users', function (Builder $query) use ($user_id) { | 192 | ->WhereHas('users', function (Builder $query) use ($user_id) { |
193 | $query->Where('id', $user_id); | 193 | $query->Where('id', $user_id); |
194 | }) | 194 | }) |
195 | ->first(); | 195 | ->first(); |
196 | if ($worker->dop_info->count()){ | 196 | if ($worker->dop_info->count()){ |
197 | $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); | 197 | $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); |
198 | } | 198 | } |
199 | 199 | ||
200 | return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses')); | 200 | return view('workers.form_additional_documents', compact('worker', 'info_blocks', 'additional_document_statuses')); |
201 | } | 201 | } |
202 | 202 | ||
203 | //Лайк резюме | 203 | //Лайк резюме |
204 | public function like_controller() { | 204 | public function like_controller() { |
205 | 205 | ||
206 | } | 206 | } |
207 | 207 | ||
208 | // анкета соискателя | 208 | // анкета соискателя |
209 | public function resume_profile(Worker $worker) | 209 | public function resume_profile(Worker $worker) |
210 | { | 210 | { |
211 | if (isset(Auth()->user()->id)) { | 211 | if (isset(Auth()->user()->id)) { |
212 | $idiot = Auth()->user()->id; | 212 | $idiot = Auth()->user()->id; |
213 | } else { | 213 | } else { |
214 | $idiot = 0; | 214 | $idiot = 0; |
215 | } | 215 | } |
216 | 216 | ||
217 | $status_work = WorkerStatuses::getWorkerStatuses(); | 217 | $status_work = WorkerStatuses::getWorkerStatuses(); |
218 | $Query = Worker::query()->with('users')->with('job_titles') | 218 | $Query = Worker::query()->with('users')->with('job_titles') |
219 | ->with('place_worker')->with('sertificate')->with('prev_company') | 219 | ->with('place_worker')->with('sertificate')->with('prev_company') |
220 | ->with('infobloks')->with('response'); | 220 | ->with('infobloks')->with('response'); |
221 | $Query = $Query->where('id', '=', $worker->id); | 221 | $Query = $Query->where('id', '=', $worker->id); |
222 | $Query = $Query->get(); | 222 | $Query = $Query->get(); |
223 | 223 | ||
224 | $get_date = date('Y.m'); | 224 | $get_date = date('Y.m'); |
225 | 225 | ||
226 | $infoblocks = infobloks::query()->get(); | 226 | $infoblocks = infobloks::query()->get(); |
227 | 227 | ||
228 | $c = Static_worker::query()->where('year_month', '=', $get_date) | 228 | $c = Static_worker::query()->where('year_month', '=', $get_date) |
229 | ->where('user_id', '=', $worker->user_id) | 229 | ->where('user_id', '=', $worker->user_id) |
230 | ->get(); | 230 | ->get(); |
231 | 231 | ||
232 | if ($c->count() > 0) { | 232 | if ($c->count() > 0) { |
233 | $upd = Static_worker::find($c[0]->id); | 233 | $upd = Static_worker::find($c[0]->id); |
234 | $upd->lookin = $upd->lookin + 1; | 234 | $upd->lookin = $upd->lookin + 1; |
235 | $upd->save(); | 235 | $upd->save(); |
236 | } else { | 236 | } else { |
237 | $crt = new Static_worker(); | 237 | $crt = new Static_worker(); |
238 | $crt->lookin = 1; | 238 | $crt->lookin = 1; |
239 | $crt->year_month = $get_date; | 239 | $crt->year_month = $get_date; |
240 | $crt->user_id = $worker->user_id; | 240 | $crt->user_id = $worker->user_id; |
241 | $status = $crt->save(); | 241 | $status = $crt->save(); |
242 | } | 242 | } |
243 | 243 | ||
244 | $stat = Static_worker::query()->where('year_month', '=', $get_date) | 244 | $stat = Static_worker::query()->where('year_month', '=', $get_date) |
245 | ->where('user_id', '=', $worker->user_id) | 245 | ->where('user_id', '=', $worker->user_id) |
246 | ->get(); | 246 | ->get(); |
247 | 247 | ||
248 | return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat')); | 248 | return view('worker', compact('Query', 'infoblocks', 'status_work', 'idiot', 'stat')); |
249 | } | 249 | } |
250 | 250 | ||
251 | // скачать анкету соискателя | 251 | // скачать анкету соискателя |
252 | public function resume_download(Worker $worker) | 252 | public function resume_download(Worker $worker) |
253 | { | 253 | { |
254 | $status_work = WorkerStatuses::getWorkerStatuses(); | 254 | $status_work = WorkerStatuses::getWorkerStatuses(); |
255 | $Query = Worker::query()->with('users')->with('job_titles') | 255 | $Query = Worker::query()->with('users')->with('job_titles') |
256 | ->with('place_worker')->with('sertificate')->with('prev_company') | 256 | ->with('place_worker')->with('sertificate')->with('prev_company') |
257 | ->with('infobloks'); | 257 | ->with('infobloks'); |
258 | $Query = $Query->where('id', '=', $worker->id); | 258 | $Query = $Query->where('id', '=', $worker->id); |
259 | $Query = $Query->get(); | 259 | $Query = $Query->get(); |
260 | 260 | ||
261 | view()->share('Query',$Query); | 261 | view()->share('Query',$Query); |
262 | 262 | ||
263 | $status_work = WorkerStatuses::getWorkerStatuses(); | 263 | $status_work = WorkerStatuses::getWorkerStatuses(); |
264 | $infoblocks = infobloks::query()->get(); | 264 | $infoblocks = infobloks::query()->get(); |
265 | 265 | ||
266 | //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); | 266 | //return view('layout.pdf', compact('Query', 'status_work', 'infoblocks')); |
267 | $pdf = PDF::loadView('layout.pdf', [ | 267 | $pdf = PDF::loadView('layout.pdf', [ |
268 | 'Query' => $Query, | 268 | 'Query' => $Query, |
269 | 'status_work' => $status_work, | 269 | 'status_work' => $status_work, |
270 | 'infoblocks' => $infoblocks | 270 | 'infoblocks' => $infoblocks |
271 | ])->setPaper('a4', 'landscape'); | 271 | ])->setPaper('a4', 'landscape'); |
272 | 272 | ||
273 | return $pdf->download(); | 273 | return $pdf->download(); |
274 | } | 274 | } |
275 | 275 | ||
276 | public function resume_download_all(Request $request) { | 276 | public function resume_download_all(Request $request) { |
277 | $spreadsheet = new Spreadsheet(); | 277 | $spreadsheet = new Spreadsheet(); |
278 | $sheet = $spreadsheet->getActiveSheet(); | 278 | $sheet = $spreadsheet->getActiveSheet(); |
279 | 279 | ||
280 | $columnMap = range('A', 'Z'); | 280 | $columnMap = range('A', 'Z'); |
281 | $columns = []; | 281 | $columns = []; |
282 | 282 | ||
283 | foreach (DbExportColumns::toArray() as $key => $value){ | 283 | foreach (DbExportColumns::toArray() as $key => $value){ |
284 | if ($request->input($key, 0)){ | 284 | if ($request->input($key, 0)){ |
285 | $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value)); | 285 | $sheet->setCellValue("{$columnMap[count($columns)]}1", ucfirst($value)); |
286 | $columns[] = str_replace('__', '.', $key); | 286 | $columns[] = str_replace('__', '.', $key); |
287 | } | 287 | } |
288 | } | 288 | } |
289 | 289 | ||
290 | if (empty($columns)) { | 290 | if (empty($columns)) { |
291 | return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.'); | 291 | return redirect()->back()->with('error', 'Пожалуйста выберите хотя бы 1 колонку для экспорта.'); |
292 | } | 292 | } |
293 | 293 | ||
294 | $jobIds = $request->input('job_title_list', []); | 294 | $jobIds = $request->input('job_title_list', []); |
295 | 295 | ||
296 | /* //query for mysql ver 8.0 or higher | 296 | /* //query for mysql ver 8.0 or higher |
297 | $users = DB::select( | 297 | $users = DB::select( |
298 | "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` | 298 | "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` |
299 | from users | 299 | from users |
300 | join workers on `users`.`id` = `workers`.`user_id` | 300 | join workers on `users`.`id` = `workers`.`user_id` |
301 | join `job_titles` | 301 | join `job_titles` |
302 | where `users`.`is_bd` = 1 | 302 | where `users`.`is_bd` = 1 |
303 | and (`workers`.`position_work` = `job_titles`.`id` | 303 | and (`workers`.`position_work` = `job_titles`.`id` |
304 | or exists (select 1 | 304 | or exists (select 1 |
305 | from JSON_TABLE( | 305 | from JSON_TABLE( |
306 | workers.positions_work, | 306 | workers.positions_work, |
307 | '$[*]' COLUMNS (id INT PATH '$')) pw | 307 | '$[*]' COLUMNS (id INT PATH '$')) pw |
308 | where pw.id = job_titles.id) | 308 | where pw.id = job_titles.id) |
309 | )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') | 309 | )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') |
310 | );*/ | 310 | );*/ |
311 | 311 | ||
312 | $selectFields = implode(',', $columns); | 312 | $selectFields = implode(',', $columns); |
313 | 313 | ||
314 | $users = DB::select("SELECT $selectFields FROM users | 314 | $users = DB::select("SELECT $selectFields FROM users |
315 | JOIN workers ON `users`.`id` = `workers`.`user_id` | 315 | JOIN workers ON `users`.`id` = `workers`.`user_id` |
316 | JOIN job_titles ON (`workers`.`position_work` = `job_titles`.`id` | 316 | JOIN job_titles ON (`workers`.`position_work` = `job_titles`.`id` |
317 | OR JSON_CONTAINS(`workers`.`positions_work`, JSON_QUOTE(CAST(`job_titles`.`id` AS CHAR)), '$')) | 317 | OR JSON_CONTAINS(`workers`.`positions_work`, JSON_QUOTE(CAST(`job_titles`.`id` AS CHAR)), '$')) |
318 | WHERE `users`.`is_bd` = 1 " . ((!empty($jobIds)) ? 'AND job_titles.id IN (' . implode(',', $jobIds) . ')' : '') . ""); | 318 | WHERE `users`.`is_bd` = 1 " . ((!empty($jobIds)) ? 'AND job_titles.id IN (' . implode(',', $jobIds) . ')' : '') . ""); |
319 | 319 | ||
320 | $users = collect($users); | 320 | $users = collect($users); |
321 | 321 | ||
322 | if ($users->count()) { | 322 | if ($users->count()) { |
323 | $i = 2; | 323 | $i = 2; |
324 | foreach ($users->toArray() as $user){ | 324 | foreach ($users->toArray() as $user){ |
325 | $j = 0; | 325 | $j = 0; |
326 | foreach ($user as $field){ | 326 | foreach ($user as $field){ |
327 | $sheet->setCellValue("{$columnMap[$j++]}$i", $field); | 327 | $sheet->setCellValue("{$columnMap[$j++]}$i", $field); |
328 | } | 328 | } |
329 | $i++; | 329 | $i++; |
330 | } | 330 | } |
331 | } | 331 | } |
332 | $writer = new Xlsx($spreadsheet); | 332 | $writer = new Xlsx($spreadsheet); |
333 | $fileName = 'DB.xlsx'; | 333 | $fileName = 'DB.xlsx'; |
334 | 334 | ||
335 | $response = new StreamedResponse(function() use ($writer) { | 335 | $response = new StreamedResponse(function() use ($writer) { |
336 | $writer->save('php://output'); | 336 | $writer->save('php://output'); |
337 | }); | 337 | }); |
338 | 338 | ||
339 | $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); | 339 | $response->headers->set('Content-Type', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); |
340 | $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"'); | 340 | $response->headers->set('Content-Disposition', 'attachment;filename="' . $fileName . '"'); |
341 | $response->headers->set('Cache-Control', 'max-age=0'); | 341 | $response->headers->set('Cache-Control', 'max-age=0'); |
342 | 342 | ||
343 | return $response; | 343 | return $response; |
344 | } | 344 | } |
345 | 345 | ||
346 | // Кабинет работника | 346 | // Кабинет работника |
347 | public function cabinet(Request $request) | 347 | public function cabinet(Request $request) |
348 | { | 348 | { |
349 | // дата год и месяц | 349 | // дата год и месяц |
350 | $get_date = date('Y.m'); | 350 | $get_date = date('Y.m'); |
351 | 351 | ||
352 | $id = Auth()->user()->id; | 352 | $id = Auth()->user()->id; |
353 | 353 | ||
354 | $Infobloks = infobloks::query()->get(); | 354 | $Infobloks = infobloks::query()->get(); |
355 | 355 | ||
356 | $Worker = Worker::query() | 356 | $Worker = Worker::query() |
357 | ->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker']) | 357 | ->with(['users', 'sertificate', 'prev_company', 'infobloks', 'place_worker']) |
358 | ->WhereHas('users', function (Builder $query) use ($id) { | 358 | ->WhereHas('users', function (Builder $query) use ($id) { |
359 | $query->Where('id', $id); | 359 | $query->Where('id', $id); |
360 | })->first(); | 360 | })->first(); |
361 | 361 | ||
362 | $Job_titles = Job_title::query()->where('is_remove', '=', '0') | 362 | $Job_titles = Job_title::query()->where('is_remove', '=', '0') |
363 | ->where('is_bd', '=' , '1') | 363 | ->where('is_bd', '=' , '1') |
364 | ->OrderByDesc('sort')->OrderBy('name') | 364 | ->OrderByDesc('sort')->OrderBy('name') |
365 | ->get(); | 365 | ->get(); |
366 | 366 | ||
367 | $stat = Static_worker::query()->where('year_month', '=', $get_date) | 367 | $stat = Static_worker::query()->where('year_month', '=', $get_date) |
368 | ->where('user_id', '=', $id) | 368 | ->where('user_id', '=', $id) |
369 | ->get(); | 369 | ->get(); |
370 | 370 | ||
371 | $persent = Tools::getWorkerProfilePercent($Worker); | 371 | $persent = Tools::getWorkerProfilePercent($Worker); |
372 | 372 | ||
373 | $status_work = WorkerStatuses::getWorkerStatuses(); | 373 | $status_work = WorkerStatuses::getWorkerStatuses(); |
374 | $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; | 374 | $additional_document_statuses = [0 => 'Не указано', 1 => 'В наличии', 2 => 'Отсутствует']; |
375 | $info_blocks = infobloks::query()->OrderBy('name')->get(); | 375 | $info_blocks = infobloks::query()->OrderBy('name')->get(); |
376 | 376 | ||
377 | $worker = Worker::query() | 377 | $worker = Worker::query() |
378 | ->with('users') | 378 | ->with('users') |
379 | ->with('sertificate') | 379 | ->with('sertificate') |
380 | ->with('prev_company') | 380 | ->with('prev_company') |
381 | ->with('infobloks') | 381 | ->with('infobloks') |
382 | ->with('place_worker') | 382 | ->with('place_worker') |
383 | ->with('job_titles') | 383 | ->with('job_titles') |
384 | ->WhereHas('users', function (Builder $query) use ($id) { | 384 | ->WhereHas('users', function (Builder $query) use ($id) { |
385 | $query->Where('id', $id); | 385 | $query->Where('id', $id); |
386 | }) | 386 | }) |
387 | ->first(); | 387 | ->first(); |
388 | if ($worker->dop_info->count()){ | 388 | if ($worker->dop_info->count()){ |
389 | $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); | 389 | $worker->dop_info = $worker->dop_info->keyBy('infoblok_id')->toArray(); |
390 | } | 390 | } |
391 | 391 | ||
392 | //dd($worker->dop_info); | 392 | //dd($worker->dop_info); |
393 | 393 | ||
394 | if ($request->has('print')) { | 394 | if ($request->has('print')) { |
395 | dd($Worker); | 395 | dd($Worker); |
396 | } else { | 396 | } else { |
397 | return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat', | 397 | return view('workers.cabinet', compact( 'persent', 'Job_titles', 'stat', |
398 | 'worker', 'info_blocks', 'status_work', 'additional_document_statuses' | 398 | 'worker', 'info_blocks', 'status_work', 'additional_document_statuses' |
399 | )); | 399 | )); |
400 | } | 400 | } |
401 | } | 401 | } |
402 | 402 | ||
403 | // Сохранение данных | 403 | // Сохранение данных |
404 | public function cabinet_save(Worker $worker, Request $request) | 404 | public function cabinet_save(Worker $worker, Request $request) |
405 | { | 405 | { |
406 | $id = $worker->id; | 406 | $id = $worker->id; |
407 | $params = $request->all(); | 407 | $params = $request->all(); |
408 | $job_title_id = $request->get('job_title_id'); | 408 | $job_title_id = $request->get('job_title_id'); |
409 | 409 | ||
410 | $rules = [ | 410 | $rules = [ |
411 | 'surname' => ['required', 'string', 'max:255'], | 411 | 'surname' => ['required', 'string', 'max:255'], |
412 | 'name_man' => ['required', 'string', 'max:255'], | 412 | 'name_man' => ['required', 'string', 'max:255'], |
413 | 'email' => ['required', 'string', 'email', 'max:255'], | 413 | 'email' => ['required', 'string', 'email', 'max:255'], |
414 | 414 | ||
415 | ]; | 415 | ]; |
416 | 416 | ||
417 | $messages = [ | 417 | $messages = [ |
418 | 'required' => 'Укажите обязательное поле', | 418 | 'required' => 'Укажите обязательное поле', |
419 | 'min' => [ | 419 | 'min' => [ |
420 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', | 420 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', |
421 | 'integer' => 'Поле «:attribute» должно быть :min или больше', | 421 | 'integer' => 'Поле «:attribute» должно быть :min или больше', |
422 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' | 422 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' |
423 | ], | 423 | ], |
424 | 'max' => [ | 424 | 'max' => [ |
425 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', | 425 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', |
426 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', | 426 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', |
427 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' | 427 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' |
428 | ] | 428 | ] |
429 | ]; | 429 | ]; |
430 | 430 | ||
431 | $validator = Validator::make($params, $rules, $messages); | 431 | $validator = Validator::make($params, $rules, $messages); |
432 | 432 | ||
433 | if ($validator->fails()) { | 433 | if ($validator->fails()) { |
434 | return redirect()->route('worker.cabinet')->withErrors($validator); | 434 | return redirect()->route('worker.cabinet')->withErrors($validator); |
435 | } else { | 435 | } else { |
436 | 436 | ||
437 | if ($request->has('photo')) { | 437 | if ($request->has('photo')) { |
438 | if (!empty($worker->photo)) { | 438 | if (!empty($worker->photo)) { |
439 | Storage::delete($worker->photo); | 439 | Storage::delete($worker->photo); |
440 | } | 440 | } |
441 | $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); | 441 | $params['photo'] = $request->file('photo')->store("worker/$id", 'public'); |
442 | } | 442 | } |
443 | 443 | ||
444 | if ($request->has('file')) { | 444 | if ($request->has('file')) { |
445 | if (!empty($worker->file)) { | 445 | if (!empty($worker->file)) { |
446 | Storage::delete($worker->file); | 446 | Storage::delete($worker->file); |
447 | } | 447 | } |
448 | $params['file'] = $request->file('file')->store("worker/$id", 'public'); | 448 | $params['file'] = $request->file('file')->store("worker/$id", 'public'); |
449 | } | 449 | } |
450 | 450 | ||
451 | $worker->update($params); | 451 | $worker->update($params); |
452 | $use = User::find($worker->user_id); | 452 | $use = User::find($worker->user_id); |
453 | $use->surname = $request->get('surname'); | 453 | $use->surname = $request->get('surname'); |
454 | $use->name_man = $request->get('name_man'); | 454 | $use->name_man = $request->get('name_man'); |
455 | $use->surname2 = $request->get('surname2'); | 455 | $use->surname2 = $request->get('surname2'); |
456 | 456 | ||
457 | $use->save(); | 457 | $use->save(); |
458 | $worker->job_titles()->sync($job_title_id); | 458 | $worker->job_titles()->sync($job_title_id); |
459 | 459 | ||
460 | return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); | 460 | return redirect()->route('worker.cabinet')->with('success', 'Данные были успешно сохранены'); |
461 | } | 461 | } |
462 | } | 462 | } |
463 | 463 | ||
464 | public function cabinet_save_foto(Worker $worker, Request $request){ | 464 | public function cabinet_save_foto(Worker $worker, Request $request){ |
465 | $params = ['photo' => null]; | 465 | $params = ['photo' => null]; |
466 | 466 | ||
467 | if ($request->has('photo')) { | 467 | if ($request->has('photo')) { |
468 | if (!empty($worker->photo)) { | 468 | if (!empty($worker->photo)) { |
469 | Storage::delete($worker->photo); | 469 | Storage::delete($worker->photo); |
470 | } | 470 | } |
471 | $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public'); | 471 | $params['photo'] = $request->file('photo')->store("worker/$worker->id", 'public'); |
472 | } | 472 | } |
473 | 473 | ||
474 | if ($request->has('file')) { | 474 | if ($request->has('file')) { |
475 | if (!empty($worker->file)) { | 475 | if (!empty($worker->file)) { |
476 | Storage::delete($worker->file); | 476 | Storage::delete($worker->file); |
477 | } | 477 | } |
478 | $params['file'] = $request->file('file')->store("worker/$worker->id", 'public'); | 478 | $params['file'] = $request->file('file')->store("worker/$worker->id", 'public'); |
479 | } | 479 | } |
480 | 480 | ||
481 | $worker->update($params); | 481 | $worker->update($params); |
482 | 482 | ||
483 | return redirect()->route('worker.cabinet'); | 483 | return redirect()->route('worker.cabinet'); |
484 | } | 484 | } |
485 | 485 | ||
486 | // Сообщения данные | 486 | // Сообщения данные |
487 | public function messages($type_message) | 487 | public function messages($type_message) |
488 | { | 488 | { |
489 | $user_id = Auth()->user()->id; | 489 | $user_id = Auth()->user()->id; |
490 | 490 | ||
491 | $chats = Chat::get_user_chats($user_id); | 491 | $chats = Chat::get_user_chats($user_id); |
492 | $admin_chat = Chat::get_user_admin_chat($user_id); | 492 | $admin_chat = Chat::get_user_admin_chat($user_id); |
493 | $user_type = 'worker'; | 493 | $user_type = 'worker'; |
494 | 494 | ||
495 | return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type')); | 495 | return view('workers.messages', compact('chats', 'admin_chat','user_id', 'user_type')); |
496 | } | 496 | } |
497 | 497 | ||
498 | // Избранный | 498 | // Избранный |
499 | public function favorite() | 499 | public function favorite() |
500 | { | 500 | { |
501 | return view('workers.favorite'); | 501 | return view('workers.favorite'); |
502 | } | 502 | } |
503 | 503 | ||
504 | // Сменить пароль | 504 | // Сменить пароль |
505 | public function new_password() | 505 | public function new_password() |
506 | { | 506 | { |
507 | $email = Auth()->user()->email; | 507 | $email = Auth()->user()->email; |
508 | return view('workers.new_password', compact('email')); | 508 | return view('workers.new_password', compact('email')); |
509 | } | 509 | } |
510 | 510 | ||
511 | // Обновление пароля | 511 | // Обновление пароля |
512 | public function save_new_password(Request $request) { | 512 | public function save_new_password(Request $request) { |
513 | $use = Auth()->user(); | 513 | $use = Auth()->user(); |
514 | $request->validate([ | 514 | $request->validate([ |
515 | 'password' => 'required|string', | 515 | 'password' => 'required|string', |
516 | 'new_password' => 'required|string', | 516 | 'new_password' => 'required|string', |
517 | 'new_password2' => 'required|string' | 517 | 'new_password2' => 'required|string' |
518 | ]); | 518 | ]); |
519 | 519 | ||
520 | if ($request->get('new_password') == $request->get('new_password2')) | 520 | if ($request->get('new_password') == $request->get('new_password2')) |
521 | if ($request->get('password') !== $request->get('new_password')) { | 521 | if ($request->get('password') !== $request->get('new_password')) { |
522 | $credentials = $request->only('email', 'password'); | 522 | $credentials = $request->only('email', 'password'); |
523 | if (Auth::attempt($credentials, $request->has('save_me'))) { | 523 | if (Auth::attempt($credentials, $request->has('save_me'))) { |
524 | 524 | ||
525 | if (!is_null($use->email_verified_at)){ | 525 | if (!is_null($use->email_verified_at)){ |
526 | 526 | ||
527 | $user_data = User_Model::find($use->id); | 527 | $user_data = User_Model::find($use->id); |
528 | $user_data->update([ | 528 | $user_data->update([ |
529 | 'password' => Hash::make($request->get('new_password')), | 529 | 'password' => Hash::make($request->get('new_password')), |
530 | 'pubpassword' => base64_encode($request->get('new_password')), | 530 | 'pubpassword' => base64_encode($request->get('new_password')), |
531 | ]); | 531 | ]); |
532 | return redirect() | 532 | return redirect() |
533 | ->route('worker.new_password') | 533 | ->route('worker.new_password') |
534 | ->with('success', 'Поздравляю! Вы обновили свой пароль!'); | 534 | ->with('success', 'Поздравляю! Вы обновили свой пароль!'); |
535 | } | 535 | } |
536 | 536 | ||
537 | return redirect() | 537 | return redirect() |
538 | ->route('worker.new_password') | 538 | ->route('worker.new_password') |
539 | ->withError('Данная учетная запись не было верифицированна!'); | 539 | ->withError('Данная учетная запись не было верифицированна!'); |
540 | } | 540 | } |
541 | } | 541 | } |
542 | 542 | ||
543 | return redirect() | 543 | return redirect() |
544 | ->route('worker.new_password') | 544 | ->route('worker.new_password') |
545 | ->withErrors('Не совпадение данных, обновите пароли!'); | 545 | ->withErrors('Не совпадение данных, обновите пароли!'); |
546 | } | 546 | } |
547 | 547 | ||
548 | // Удаление профиля форма | 548 | // Удаление профиля форма |
549 | public function delete_profile() | 549 | public function delete_profile() |
550 | { | 550 | { |
551 | $login = Auth()->user()->email; | 551 | $login = Auth()->user()->email; |
552 | return view('workers.delete_profile', compact('login')); | 552 | return view('workers.delete_profile', compact('login')); |
553 | } | 553 | } |
554 | 554 | ||
555 | // Удаление профиля код | 555 | // Удаление профиля код |
556 | public function delete_profile_result(Request $request) { | 556 | public function delete_profile_result(Request $request) { |
557 | $Answer = $request->all(); | 557 | $Answer = $request->all(); |
558 | $user_id = Auth()->user()->id; | 558 | $user_id = Auth()->user()->id; |
559 | $request->validate([ | 559 | $request->validate([ |
560 | 'password' => 'required|string', | 560 | 'password' => 'required|string', |
561 | ]); | 561 | ]); |
562 | 562 | ||
563 | $credentials = $request->only('email', 'password'); | 563 | $credentials = $request->only('email', 'password'); |
564 | if (Auth::attempt($credentials)) { | 564 | if (Auth::attempt($credentials)) { |
565 | Auth::logout(); | 565 | Auth::logout(); |
566 | $it = User_Model::find($user_id); | 566 | $it = User_Model::find($user_id); |
567 | $it->delete(); | 567 | $it->delete(); |
568 | return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); | 568 | return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); |
569 | } else { | 569 | } else { |
570 | return redirect()->route('worker.delete_profile') | 570 | return redirect()->route('worker.delete_profile') |
571 | ->withErrors( 'Неверный пароль! Нужен корректный пароль'); | 571 | ->withErrors( 'Неверный пароль! Нужен корректный пароль'); |
572 | } | 572 | } |
573 | } | 573 | } |
574 | 574 | ||
575 | // Регистрация соискателя | 575 | // Регистрация соискателя |
576 | public function register_worker(Request $request) | 576 | public function register_worker(Request $request) |
577 | { | 577 | { |
578 | $params = $request->all(); | 578 | $params = $request->all(); |
579 | $params['is_worker'] = 1; | 579 | $params['is_worker'] = 1; |
580 | 580 | ||
581 | $rules = [ | 581 | $rules = [ |
582 | 'surname' => ['required', 'string', 'max:255'], | 582 | 'surname' => ['required', 'string', 'max:255'], |
583 | 'name_man' => ['required', 'string', 'max:255'], | 583 | 'name_man' => ['required', 'string', 'max:255'], |
584 | 'email' => ['required', 'email', 'max:255', 'unique:users'], | 584 | 'email' => ['required', 'email', 'max:255', 'unique:users'], |
585 | 'password' => ['required', 'string', 'min:6'] | 585 | 'password' => ['required', 'string', 'min:6'] |
586 | ]; | 586 | ]; |
587 | 587 | ||
588 | $messages = [ | 588 | $messages = [ |
589 | 'required' => 'Укажите обязательное поле', | 589 | 'required' => 'Укажите обязательное поле', |
590 | 'min' => [ | 590 | 'min' => [ |
591 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', | 591 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', |
592 | 'integer' => 'Поле «:attribute» должно быть :min или больше', | 592 | 'integer' => 'Поле «:attribute» должно быть :min или больше', |
593 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' | 593 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' |
594 | ], | 594 | ], |
595 | 'max' => [ | 595 | 'max' => [ |
596 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', | 596 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', |
597 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', | 597 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', |
598 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' | 598 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' |
599 | ] | 599 | ] |
600 | ]; | 600 | ]; |
601 | 601 | ||
602 | $email = $request->get('email'); | 602 | $email = $request->get('email'); |
603 | if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { | 603 | if (!preg_match("/^[a-zA-Z0-9_\-.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/", $email)) { |
604 | return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); | 604 | return json_encode(Array("ERROR" => "Error: Отсутствует емайл или некорректный емайл")); |
605 | } | 605 | } |
606 | 606 | ||
607 | if ($request->get('password') !== $request->get('confirmed')){ | 607 | if ($request->get('password') !== $request->get('confirmed')){ |
608 | return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); | 608 | return json_encode(Array("ERROR" => "Error: Не совпадают пароль и подтверждение пароля")); |
609 | } | 609 | } |
610 | 610 | ||
611 | if (strlen($request->get('password')) < 6) { | 611 | if (strlen($request->get('password')) < 6) { |
612 | return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); | 612 | return json_encode(Array("ERROR" => "Error: Недостаточная длина пароля! Увеличьте себе длину пароля!")); |
613 | } | 613 | } |
614 | 614 | ||
615 | if (($request->has('politik')) && ($request->get('politik') == 1)) { | 615 | if (($request->has('politik')) && ($request->get('politik') == 1)) { |
616 | $validator = Validator::make($params, $rules, $messages); | 616 | $validator = Validator::make($params, $rules, $messages); |
617 | 617 | ||
618 | if ($validator->fails()) { | 618 | if ($validator->fails()) { |
619 | return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); | 619 | return json_encode(array("ERROR" => "Error1: Регистрация оборвалась ошибкой! Не все обязательные поля заполнены. Либо вы уже были зарегистрированы в системе.")); |
620 | } | 620 | } |
621 | 621 | ||
622 | if ($user = $this->create($params)) { | 622 | if ($user = $this->create($params)) { |
623 | event(new Registered($user)); | 623 | event(new Registered($user)); |
624 | return json_encode(Array("REDIRECT" => redirect()->to('/')->getTargetUrl())); | 624 | return json_encode(Array("REDIRECT" => redirect()->to('/')->getTargetUrl())); |
625 | } else { | 625 | } else { |
626 | return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); | 626 | return json_encode(Array("ERROR" => "Error2: Данные были утеряны!")); |
627 | } | 627 | } |
628 | 628 | ||
629 | } else { | 629 | } else { |
630 | return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!")); | 630 | return json_encode(Array("ERROR" => "Error3: Вы не согласились с политикой конфидициальности!")); |
631 | } | 631 | } |
632 | } | 632 | } |
633 | 633 | ||
634 | // Звездная оценка и ответ | 634 | // Звездная оценка и ответ |
635 | public function stars_answer(Request $request) { | 635 | public function stars_answer(Request $request) { |
636 | $params = $request->all(); | 636 | $params = $request->all(); |
637 | $rules = [ | 637 | $rules = [ |
638 | 'message' => ['required', 'string', 'max:255'], | 638 | 'message' => ['required', 'string', 'max:255'], |
639 | ]; | 639 | ]; |
640 | 640 | ||
641 | $messages = [ | 641 | $messages = [ |
642 | 'required' => 'Укажите обязательное поле', | 642 | 'required' => 'Укажите обязательное поле', |
643 | 'min' => [ | 643 | 'min' => [ |
644 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', | 644 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', |
645 | 'integer' => 'Поле «:attribute» должно быть :min или больше', | 645 | 'integer' => 'Поле «:attribute» должно быть :min или больше', |
646 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' | 646 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' |
647 | ], | 647 | ], |
648 | 'max' => [ | 648 | 'max' => [ |
649 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', | 649 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', |
650 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', | 650 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', |
651 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' | 651 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' |
652 | ] | 652 | ] |
653 | ]; | 653 | ]; |
654 | $response_worker = ResponseWork::create($params); | 654 | $response_worker = ResponseWork::create($params); |
655 | return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); | 655 | return redirect()->route('resume_profile', ['worker' => $request->get('worker_id')])->with('success', 'Ваше сообщение было отправлено!'); |
656 | } | 656 | } |
657 | 657 | ||
658 | public function TestWorker() | 658 | public function TestWorker() |
659 | { | 659 | { |
660 | $Use = new User(); | 660 | $Use = new User(); |
661 | 661 | ||
662 | $Code_user = $Use->create([ | 662 | $Code_user = $Use->create([ |
663 | 'name' => 'surname name_man', | 663 | 'name' => 'surname name_man', |
664 | 'name_man' => 'name_man', | 664 | 'name_man' => 'name_man', |
665 | 'surname' => 'surname', | 665 | 'surname' => 'surname', |
666 | 'surname2' => 'surname2', | 666 | 'surname2' => 'surname2', |
667 | 'subscribe_email' => '1', | 667 | 'subscribe_email' => '1', |
668 | 'email' => 'email@mail.com', | 668 | 'email' => 'email@mail.com', |
669 | 'telephone' => '1234567890', | 669 | 'telephone' => '1234567890', |
670 | 'password' => Hash::make('password'), | 670 | 'password' => Hash::make('password'), |
671 | 'pubpassword' => base64_encode('password'), | 671 | 'pubpassword' => base64_encode('password'), |
672 | // 'email_verified_at' => Carbon::now(), | 672 | // 'email_verified_at' => Carbon::now(), |
673 | 'is_worker' => 1, | 673 | 'is_worker' => 1, |
674 | ]); | 674 | ]); |
675 | 675 | ||
676 | if ($Code_user->id > 0) { | 676 | if ($Code_user->id > 0) { |
677 | $Worker = new Worker(); | 677 | $Worker = new Worker(); |
678 | $Worker->user_id = $Code_user->id; | 678 | $Worker->user_id = $Code_user->id; |
679 | $Worker->position_work = 1; //'job_titles'; | 679 | $Worker->position_work = 1; //'job_titles'; |
680 | $Worker->email = 'email@email.com'; | 680 | $Worker->email = 'email@email.com'; |
681 | $Worker->telephone = '1234567890'; | 681 | $Worker->telephone = '1234567890'; |
682 | $status = $Worker->save(); | 682 | $status = $Worker->save(); |
683 | 683 | ||
684 | $Title_Worker = new Title_worker(); | 684 | $Title_Worker = new Title_worker(); |
685 | $Title_Worker->worker_id = $Worker->id; | 685 | $Title_Worker->worker_id = $Worker->id; |
686 | $Title_Worker->job_title_id = 1; | 686 | $Title_Worker->job_title_id = 1; |
687 | $Title_Worker->save(); | 687 | $Title_Worker->save(); |
688 | } | 688 | } |
689 | } | 689 | } |
690 | 690 | ||
691 | // Создание пользователя | 691 | // Создание пользователя |
692 | protected function create(array $data) | 692 | protected function create(array $data) |
693 | { | 693 | { |
694 | $Use = new User(); | 694 | $Use = new User(); |
695 | 695 | ||
696 | $Code_user = $Use->create([ | 696 | $Code_user = $Use->create([ |
697 | 'name' => $data['surname']." ".$data['name_man'], | 697 | 'name' => $data['surname']." ".$data['name_man'], |
698 | 'name_man' => $data['name_man'], | 698 | 'name_man' => $data['name_man'], |
699 | 'surname' => $data['surname'], | 699 | 'surname' => $data['surname'], |
700 | 'surname2' => $data['surname2'], | 700 | 'surname2' => $data['surname2'], |
701 | 'subscribe_email' => $data['email'], | 701 | 'subscribe_email' => $data['email'], |
702 | 'email' => $data['email'], | 702 | 'email' => $data['email'], |
703 | 'telephone' => $data['telephone'], | 703 | 'telephone' => $data['telephone'], |
704 | 'password' => Hash::make($data['password']), | 704 | 'password' => Hash::make($data['password']), |
705 | 'pubpassword' => base64_encode($data['password']), | 705 | 'pubpassword' => base64_encode($data['password']), |
706 | 'is_worker' => $data['is_worker'], | 706 | 'is_worker' => $data['is_worker'], |
707 | ]); | 707 | ]); |
708 | 708 | ||
709 | if ($Code_user->id > 0) { | 709 | if ($Code_user->id > 0) { |
710 | $Worker = new Worker(); | 710 | $Worker = new Worker(); |
711 | $Worker->user_id = $Code_user->id; | 711 | $Worker->user_id = $Code_user->id; |
712 | $Worker->position_work = $data['job_titles'] ?? null; | 712 | $Worker->position_work = $data['job_titles'] ?? null; |
713 | $Worker->email = $data['email']; | 713 | $Worker->email = $data['email']; |
714 | $Worker->telephone = $data['telephone']; | 714 | $Worker->telephone = $data['telephone']; |
715 | $Worker->save(); | 715 | $Worker->save(); |
716 | 716 | ||
717 | if (isset($Worker->id) && !empty($data['job_titles'])) { | 717 | if (isset($Worker->id) && !empty($data['job_titles'])) { |
718 | $existJob = Job_title::query()->find($data['job_titles']); | 718 | $existJob = Job_title::query()->find($data['job_titles']); |
719 | if (!$existJob) { | 719 | if ($existJob) { |
720 | $Title_Worker = new Title_worker(); | 720 | $Title_Worker = new Title_worker(); |
721 | $Title_Worker->worker_id = $Worker->id; | 721 | $Title_Worker->worker_id = $Worker->id; |
722 | $Title_Worker->job_title_id = $data['job_titles']; | 722 | $Title_Worker->job_title_id = $data['job_titles']; |
723 | $Title_Worker->save(); | 723 | $Title_Worker->save(); |
724 | } | 724 | } |
725 | 725 | ||
726 | } | 726 | } |
727 | 727 | ||
728 | return $Code_user; | 728 | return $Code_user; |
729 | } | 729 | } |
730 | } | 730 | } |
731 | 731 | ||
732 | // Вакансии избранные | 732 | // Вакансии избранные |
733 | public function colorado(Request $request) { | 733 | public function colorado(Request $request) { |
734 | $Arr = Like_vacancy::Query() | 734 | $Arr = Like_vacancy::Query() |
735 | ->select('code_record') | 735 | ->select('code_record') |
736 | ->where('user_id', Auth::user()->id) | 736 | ->where('user_id', Auth::user()->id) |
737 | ->get(); | 737 | ->get(); |
738 | 738 | ||
739 | if ($Arr->count()) { | 739 | if ($Arr->count()) { |
740 | $A = Array(); | 740 | $A = Array(); |
741 | foreach ($Arr as $it) { | 741 | foreach ($Arr as $it) { |
742 | $A[] = $it->code_record; | 742 | $A[] = $it->code_record; |
743 | } | 743 | } |
744 | 744 | ||
745 | $Query = Ad_employer::query()->whereIn('id', $A); | 745 | $Query = Ad_employer::query()->whereIn('id', $A); |
746 | } else { | 746 | } else { |
747 | $Query = Ad_employer::query()->where('id', '=', '0'); | 747 | $Query = Ad_employer::query()->where('id', '=', '0'); |
748 | } | 748 | } |
749 | 749 | ||
750 | $Query = $Query->with(['jobs', 'cat', 'employer']) | 750 | $Query = $Query->with(['jobs', 'cat', 'employer']) |
751 | ->whereHas('jobs_code', function ($query) use ($request) { | 751 | ->whereHas('jobs_code', function ($query) use ($request) { |
752 | if ($request->ajax()) { | 752 | if ($request->ajax()) { |
753 | if (null !== ($request->get('job'))) { | 753 | if (null !== ($request->get('job'))) { |
754 | $query->where('job_title_id', $request->get('job')); | 754 | $query->where('job_title_id', $request->get('job')); |
755 | } | 755 | } |
756 | } | 756 | } |
757 | }) | 757 | }) |
758 | ->select('ad_employers.*'); | 758 | ->select('ad_employers.*'); |
759 | 759 | ||
760 | if ($request->get('search') !== null) { | 760 | if ($request->get('search') !== null) { |
761 | $search = $request->get('search'); | 761 | $search = $request->get('search'); |
762 | $Query->where('name', 'LIKE', "%$search%"); | 762 | $Query->where('name', 'LIKE', "%$search%"); |
763 | } | 763 | } |
764 | 764 | ||
765 | //dd($Query->get()); | 765 | //dd($Query->get()); |
766 | 766 | ||
767 | $Job_title = Job_title::query()->OrderBy('name')->get(); | 767 | $Job_title = Job_title::query()->OrderBy('name')->get(); |
768 | 768 | ||
769 | $Query_count = $Query->count(); | 769 | $Query_count = $Query->count(); |
770 | 770 | ||
771 | $Query = $Query->OrderBy('updated_at')->paginate(3); | 771 | $Query = $Query->OrderBy('updated_at')->paginate(3); |
772 | 772 | ||
773 | return view('workers.favorite', compact('Query', | 773 | return view('workers.favorite', compact('Query', |
774 | 'Query_count', | 774 | 'Query_count', |
775 | 'Job_title')); | 775 | 'Job_title')); |
776 | 776 | ||
777 | } | 777 | } |
778 | public function pin_chat(Request $request){ | 778 | public function pin_chat(Request $request){ |
779 | $chat_id = $request->get('id'); | 779 | $chat_id = $request->get('id'); |
780 | $is_fixed = $request->get('is_fixed'); | 780 | $is_fixed = $request->get('is_fixed'); |
781 | Chat::pin_chat($chat_id, $is_fixed); | 781 | Chat::pin_chat($chat_id, $is_fixed); |
782 | } | 782 | } |
783 | //Переписка | 783 | //Переписка |
784 | public function dialog(Chat $chat, Request $request) { | 784 | public function dialog(Chat $chat, Request $request) { |
785 | // Получение параметров. | 785 | // Получение параметров. |
786 | if ($request->has('ad_employer')){ | 786 | if ($request->has('ad_employer')){ |
787 | $ad_employer = $request->get('ad_employer'); | 787 | $ad_employer = $request->get('ad_employer'); |
788 | } else { | 788 | } else { |
789 | $ad_employer = 0; | 789 | $ad_employer = 0; |
790 | } | 790 | } |
791 | $supeAdmin=User::superAdmin(); | 791 | $supeAdmin=User::superAdmin(); |
792 | $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); | 792 | $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); |
793 | $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); | 793 | $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); |
794 | 794 | ||
795 | $Messages = Chat::get_chat_messages($chat); | 795 | $Messages = Chat::get_chat_messages($chat); |
796 | 796 | ||
797 | Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]); | 797 | Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]); |
798 | 798 | ||
799 | return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer','supeAdmin')); | 799 | return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer','supeAdmin')); |
800 | } | 800 | } |
801 | 801 | ||
802 | // Даунылоады | 802 | // Даунылоады |
803 | public function download(Worker $worker) { | 803 | public function download(Worker $worker) { |
804 | $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...']; | 804 | $arr_house = ['0' => 'Проверка, проверка, проверка, проверка, проверка...']; |
805 | view()->share('house',$arr_house); | 805 | view()->share('house',$arr_house); |
806 | $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape'); | 806 | $pdf = PDF::loadView('layout.pdf', $arr_house)->setPaper('a4', 'landscape'); |
807 | return $pdf->stream(); | 807 | return $pdf->stream(); |
808 | } | 808 | } |
809 | 809 | ||
810 | // Поднятие анкеты | 810 | // Поднятие анкеты |
811 | public function up(Worker $worker) { | 811 | public function up(Worker $worker) { |
812 | $worker->updated_at = Carbon::now(); | 812 | $worker->updated_at = Carbon::now(); |
813 | $worker->save(); | 813 | $worker->save(); |
814 | // 0 | 814 | // 0 |
815 | return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); | 815 | return redirect()->route('worker.cabinet')->with('success', 'Ваша анкета была поднята выше остальных'); |
816 | } | 816 | } |
817 | 817 | ||
818 | // Форма сертификате | 818 | // Форма сертификате |
819 | public function new_sertificate(Worker $worker) { | 819 | public function new_sertificate(Worker $worker) { |
820 | return view('workers.sertificate_add', compact('worker')); | 820 | return view('workers.sertificate_add', compact('worker')); |
821 | } | 821 | } |
822 | 822 | ||
823 | // Добавление сертификата | 823 | // Добавление сертификата |
824 | public function add_serificate(SertificationRequest $request) { | 824 | public function add_serificate(SertificationRequest $request) { |
825 | $request->validate([ | 825 | $request->validate([ |
826 | 'name' => 'required|string|max:255', | 826 | 'name' => 'required|string|max:255', |
827 | 'end_begin' => 'required|date|date_format:d.m.Y' | 827 | 'end_begin' => 'required|date|date_format:d.m.Y' |
828 | ], | 828 | ], |
829 | [ | 829 | [ |
830 | 'name' => 'Навание сертификата обязательно для заполнения.', | 830 | 'name' => 'Навание сертификата обязательно для заполнения.', |
831 | 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' | 831 | 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' |
832 | ]); | 832 | ]); |
833 | 833 | ||
834 | $params = $request->all(); | 834 | $params = $request->all(); |
835 | 835 | ||
836 | $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']); | 836 | $end_begin = DateTime::createFromFormat('d.m.Y', $params['end_begin']); |
837 | $params['end_begin'] = $end_begin->format('Y-m-d'); | 837 | $params['end_begin'] = $end_begin->format('Y-m-d'); |
838 | 838 | ||
839 | $Sertificate = new sertification(); | 839 | $Sertificate = new sertification(); |
840 | $Sertificate->create($params); | 840 | $Sertificate->create($params); |
841 | 841 | ||
842 | return response()->json([ | 842 | return response()->json([ |
843 | 'success' => true | 843 | 'success' => true |
844 | ]); | 844 | ]); |
845 | } | 845 | } |
846 | 846 | ||
847 | // Удалить сертификат | 847 | // Удалить сертификат |
848 | public function delete_sertificate(sertification $doc) { | 848 | public function delete_sertificate(sertification $doc) { |
849 | $doc->delete(); | 849 | $doc->delete(); |
850 | 850 | ||
851 | return redirect()->route('worker.cabinet'); | 851 | return redirect()->route('worker.cabinet'); |
852 | } | 852 | } |
853 | 853 | ||
854 | // Редактирование сертификата | 854 | // Редактирование сертификата |
855 | public function edit_sertificate(Worker $worker, sertification $doc) { | 855 | public function edit_sertificate(Worker $worker, sertification $doc) { |
856 | return view('workers.sertificate_edit', compact('doc', 'worker')); | 856 | return view('workers.sertificate_edit', compact('doc', 'worker')); |
857 | } | 857 | } |
858 | 858 | ||
859 | // Редактирование обновление сертификата | 859 | // Редактирование обновление сертификата |
860 | public function update_serificate(SertificationRequest $request, sertification $doc) { | 860 | public function update_serificate(SertificationRequest $request, sertification $doc) { |
861 | $request->validate([ | 861 | $request->validate([ |
862 | 'name' => 'required|string|max:255', | 862 | 'name' => 'required|string|max:255', |
863 | 'end_begin' => 'required|date|date_format:d.m.Y' | 863 | 'end_begin' => 'required|date|date_format:d.m.Y' |
864 | ], | 864 | ], |
865 | [ | 865 | [ |
866 | 'name' => 'Навание сертификата обязательно для заполнения.', | 866 | 'name' => 'Навание сертификата обязательно для заполнения.', |
867 | 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' | 867 | 'end_begin' => 'Формат даты должен соответствовать дд.мм.гггг' |
868 | ]); | 868 | ]); |
869 | 869 | ||
870 | $all = $request->all(); | 870 | $all = $request->all(); |
871 | 871 | ||
872 | $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']); | 872 | $end_begin = DateTime::createFromFormat('d.m.Y', $all['end_begin']); |
873 | $all['end_begin'] = $end_begin->format('Y-m-d'); | 873 | $all['end_begin'] = $end_begin->format('Y-m-d'); |
874 | 874 | ||
875 | $doc->worker_id = $all['worker_id']; | 875 | $doc->worker_id = $all['worker_id']; |
876 | $doc->name = $all['name']; | 876 | $doc->name = $all['name']; |
877 | $doc->end_begin = $all['end_begin']; | 877 | $doc->end_begin = $all['end_begin']; |
878 | $doc->save(); | 878 | $doc->save(); |
879 | 879 | ||
880 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); | 880 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); |
881 | } | 881 | } |
882 | 882 | ||
883 | public function edit_diploms(Request $request, Worker $worker) { | 883 | public function edit_diploms(Request $request, Worker $worker) { |
884 | $dop_info_data = $request->input('diploms'); | 884 | $dop_info_data = $request->input('diploms'); |
885 | 885 | ||
886 | if (empty($dop_info_data)) { | 886 | if (empty($dop_info_data)) { |
887 | return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!'); | 887 | return redirect()->route('worker.additional_documents')->with('error', 'Данные не предоставлены!'); |
888 | } | 888 | } |
889 | 889 | ||
890 | foreach ($dop_info_data as $infoblok_id => $status) { | 890 | foreach ($dop_info_data as $infoblok_id => $status) { |
891 | Dop_info::updateOrCreate( | 891 | Dop_info::updateOrCreate( |
892 | ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id], | 892 | ['worker_id' => $worker->id, 'infoblok_id' => $infoblok_id], |
893 | ['status' => $status] | 893 | ['status' => $status] |
894 | ); | 894 | ); |
895 | } | 895 | } |
896 | 896 | ||
897 | return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!'); | 897 | return redirect()->route('worker.additional_documents')->with('success', 'Успешно сохранено!'); |
898 | } | 898 | } |
899 | public function subscribe() { | 899 | public function subscribe() { |
900 | 900 | ||
901 | $user= Auth::user(); | 901 | $user= Auth::user(); |
902 | return view('workers.subcribe',compact('user')); | 902 | return view('workers.subcribe',compact('user')); |
903 | } | 903 | } |
904 | 904 | ||
905 | //Установка уведомлений сохранение | 905 | //Установка уведомлений сохранение |
906 | public function save_subscribe(Request $request) { | 906 | public function save_subscribe(Request $request) { |
907 | 907 | ||
908 | $msg = $request->validate([ | 908 | $msg = $request->validate([ |
909 | 'email' => 'required|email|min:5|max:255', | 909 | 'email' => 'required|email|min:5|max:255', |
910 | ]); | 910 | ]); |
911 | 911 | ||
912 | $user= Auth::user(); | 912 | $user= Auth::user(); |
913 | 913 | ||
914 | User_Model::updateOrCreate( | 914 | User_Model::updateOrCreate( |
915 | ['id' => $user->id], | 915 | ['id' => $user->id], |
916 | ['subscribe_email' => $request->email, | 916 | ['subscribe_email' => $request->email, |
917 | 'subscribe' => request()->has('email_msg') && request('email_msg') === 'on' ? 1 : 0 | 917 | 'subscribe' => request()->has('email_msg') && request('email_msg') === 'on' ? 1 : 0 |
918 | ] | 918 | ] |
919 | ); | 919 | ); |
920 | return redirect()->route('worker.subscribe')->with('success', 'Ваши изменения успешно сохранены'); | 920 | return redirect()->route('worker.subscribe')->with('success', 'Ваши изменения успешно сохранены'); |
921 | 921 | ||
922 | } | 922 | } |
923 | public function delete_add_diplom(Request $request, Worker $worker) { | 923 | public function delete_add_diplom(Request $request, Worker $worker) { |
924 | $infoblok_id = $request->get('infoblok_id'); | 924 | $infoblok_id = $request->get('infoblok_id'); |
925 | 925 | ||
926 | if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0) | 926 | if (Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->count() > 0) |
927 | $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete(); | 927 | $id = Dop_info::query()->where('worker_id', $worker->id)->where('infoblok_id', $infoblok_id)->delete(); |
928 | else { | 928 | else { |
929 | $params['infoblok_id'] = $infoblok_id; | 929 | $params['infoblok_id'] = $infoblok_id; |
930 | $params['worker_id'] = $worker->id; | 930 | $params['worker_id'] = $worker->id; |
931 | $params['status'] = $request->get('val'); | 931 | $params['status'] = $request->get('val'); |
932 | $id = Dop_info::create($params); | 932 | $id = Dop_info::create($params); |
933 | //$id = $worker->infobloks()->sync([$infoblok_id]); | 933 | //$id = $worker->infobloks()->sync([$infoblok_id]); |
934 | } | 934 | } |
935 | 935 | ||
936 | //$Infoblocks = infobloks::query()->get(); | 936 | //$Infoblocks = infobloks::query()->get(); |
937 | return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks')); | 937 | return $id; //redirect()->route('worker.cabinet')->getTargetUrl(); //view('workers.ajax.diploms_dop', compact('worker', 'Infoblocks')); |
938 | } | 938 | } |
939 | 939 | ||
940 | 940 | ||
941 | 941 | ||
942 | // Добавление диплома | 942 | // Добавление диплома |
943 | public function add_diplom_ajax(Request $request) { | 943 | public function add_diplom_ajax(Request $request) { |
944 | // конец | 944 | // конец |
945 | $params = $request->all(); | 945 | $params = $request->all(); |
946 | $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); | 946 | $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); |
947 | 947 | ||
948 | if ($count == 0) $dop_info = Dop_info::create($params); | 948 | if ($count == 0) $dop_info = Dop_info::create($params); |
949 | $Infoblocks = infobloks::query()->get(); | 949 | $Infoblocks = infobloks::query()->get(); |
950 | $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); | 950 | $Worker = Worker::query()->where('id', $request->get('worker_id'))->get(); |
951 | $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); | 951 | $data = Dop_info::query()->where('worker_id', $request->has('worker_id')); |
952 | return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); | 952 | return view('ajax.dop_info', compact('data', 'Infoblocks', 'Worker')); |
953 | } | 953 | } |
954 | 954 | ||
955 | // Добавление диплома без ajax | 955 | // Добавление диплома без ajax |
956 | public function add_diplom(Worker $worker) { | 956 | public function add_diplom(Worker $worker) { |
957 | $worker_id = $worker->id; | 957 | $worker_id = $worker->id; |
958 | $Infoblocks = infobloks::query()->get(); | 958 | $Infoblocks = infobloks::query()->get(); |
959 | return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); | 959 | return view('workers.dop_info', compact('worker_id', 'worker', 'Infoblocks')); |
960 | } | 960 | } |
961 | // Сохранить | 961 | // Сохранить |
962 | // Сохраняю диплом | 962 | // Сохраняю диплом |
963 | public function add_diplom_save(Request $request) { | 963 | public function add_diplom_save(Request $request) { |
964 | $params = $request->all(); | 964 | $params = $request->all(); |
965 | $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); | 965 | $count = Dop_info::query()->where('worker_id', $request->get('worker_id'))->where('infoblok_id', $request->get('infoblok_id'))->count(); |
966 | if ($count == 0) $dop_info = Dop_info::create($params); | 966 | if ($count == 0) $dop_info = Dop_info::create($params); |
967 | return redirect()->route('worker.cabinet'); | 967 | return redirect()->route('worker.cabinet'); |
968 | } | 968 | } |
969 | 969 | ||
970 | // Добавление стандартного документа | 970 | // Добавление стандартного документа |
971 | public function add_document(Worker $worker) { | 971 | public function add_document(Worker $worker) { |
972 | return view('workers.docs', compact('worker')); | 972 | return view('workers.docs', compact('worker')); |
973 | } | 973 | } |
974 | 974 | ||
975 | //Сохранение стандартого документа | 975 | //Сохранение стандартого документа |
976 | public function add_document_save(DocumentsRequest $request) { | 976 | public function add_document_save(DocumentsRequest $request) { |
977 | $params = $request->all(); | 977 | $params = $request->all(); |
978 | place_works::create($params); | 978 | place_works::create($params); |
979 | return response()->json(['success' => true]); | 979 | return response()->json(['success' => true]); |
980 | } | 980 | } |
981 | 981 | ||
982 | // Редактирование документа | 982 | // Редактирование документа |
983 | public function edit_document(place_works $doc, Worker $worker) { | 983 | public function edit_document(place_works $doc, Worker $worker) { |
984 | 984 | ||
985 | return view('workers.docs-edit', compact('doc', 'worker')); | 985 | return view('workers.docs-edit', compact('doc', 'worker')); |
986 | } | 986 | } |
987 | 987 | ||
988 | //Сохранение отредактированного документа | 988 | //Сохранение отредактированного документа |
989 | public function edit_document_save(DocumentsRequest $request, place_works $doc) { | 989 | public function edit_document_save(DocumentsRequest $request, place_works $doc) { |
990 | $params = $request->all(); | 990 | $params = $request->all(); |
991 | $doc->update($params); | 991 | $doc->update($params); |
992 | 992 | ||
993 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); | 993 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись!'); |
994 | } | 994 | } |
995 | 995 | ||
996 | // Удаление документа | 996 | // Удаление документа |
997 | public function delete_document(place_works $doc) { | 997 | public function delete_document(place_works $doc) { |
998 | $doc->delete(); | 998 | $doc->delete(); |
999 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); | 999 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); |
1000 | } | 1000 | } |
1001 | 1001 | ||
1002 | //Отправка нового сообщения | 1002 | //Отправка нового сообщения |
1003 | public function new_message(Request $request) | 1003 | public function new_message(Request $request) |
1004 | { | 1004 | { |
1005 | $params = $request->all(); | 1005 | $params = $request->all(); |
1006 | 1006 | ||
1007 | $id = $params['user_from']; | 1007 | $id = $params['user_from']; |
1008 | 1008 | ||
1009 | Message::add_message( | 1009 | Message::add_message( |
1010 | $request, | 1010 | $request, |
1011 | $params['user_from'], | 1011 | $params['user_from'], |
1012 | $params['user_to'], | 1012 | $params['user_to'], |
1013 | [ | 1013 | [ |
1014 | 'text' => $params['comment'] ?? null, | 1014 | 'text' => $params['comment'] ?? null, |
1015 | 'ad_employer_id' => $params['vacancy'], | 1015 | 'ad_employer_id' => $params['vacancy'], |
1016 | 'flag_new' => 1 | 1016 | 'flag_new' => 1 |
1017 | ], | 1017 | ], |
1018 | file_store_path: "worker/$id" | 1018 | file_store_path: "worker/$id" |
1019 | ); | 1019 | ); |
1020 | 1020 | ||
1021 | if ($request->ajax()) { | 1021 | if ($request->ajax()) { |
1022 | return response([]); | 1022 | return response([]); |
1023 | } | 1023 | } |
1024 | return redirect()->back(); | 1024 | return redirect()->back(); |
1025 | } | 1025 | } |
1026 | 1026 | ||
1027 | 1027 | ||
1028 | public function test123(Request $request) { | 1028 | public function test123(Request $request) { |
1029 | $params = $request->all(); | 1029 | $params = $request->all(); |
1030 | $user1 = $params['user_id']; | 1030 | $user1 = $params['user_id']; |
1031 | $user2 = $params['to_user_id']; | 1031 | $user2 = $params['to_user_id']; |
1032 | 1032 | ||
1033 | $rules = [ | 1033 | $rules = [ |
1034 | 'text' => 'nullable|required_without:file|min:1|max:150000', | 1034 | 'text' => 'nullable|required_without:file|min:1|max:150000', |
1035 | 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' | 1035 | 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' |
1036 | ]; | 1036 | ]; |
1037 | $messages = [ | 1037 | $messages = [ |
1038 | 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', | 1038 | 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', |
1039 | 'min' => [ | 1039 | 'min' => [ |
1040 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', | 1040 | 'string' => 'Поле «:attribute» должно быть не меньше :min символов', |
1041 | 'integer' => 'Поле «:attribute» должно быть :min или больше', | 1041 | 'integer' => 'Поле «:attribute» должно быть :min или больше', |
1042 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' | 1042 | 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' |
1043 | ], | 1043 | ], |
1044 | 'max' => [ | 1044 | 'max' => [ |
1045 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', | 1045 | 'string' => 'Поле «:attribute» должно быть не больше :max символов', |
1046 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', | 1046 | 'integer' => 'Поле «:attribute» должно быть :max или меньше', |
1047 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' | 1047 | 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' |
1048 | ] | 1048 | ] |
1049 | ]; | 1049 | ]; |
1050 | 1050 | ||
1051 | $validator = Validator::make($request->all(), $rules, $messages); | 1051 | $validator = Validator::make($request->all(), $rules, $messages); |
1052 | 1052 | ||
1053 | if ($validator->fails()) { | 1053 | if ($validator->fails()) { |
1054 | $chat = Chat::where('user_id', $user1) | 1054 | $chat = Chat::where('user_id', $user1) |
1055 | ->where('to_user_id', $user2) | 1055 | ->where('to_user_id', $user2) |
1056 | ->where('is_removed', 0) | 1056 | ->where('is_removed', 0) |
1057 | ->first(); | 1057 | ->first(); |
1058 | 1058 | ||
1059 | if ($chat->id){ | 1059 | if ($chat->id){ |
1060 | return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator); | 1060 | return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator); |
1061 | } else { | 1061 | } else { |
1062 | return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); | 1062 | return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); |
1063 | } | 1063 | } |
1064 | } else { | 1064 | } else { |
1065 | $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); | 1065 | $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); |
1066 | 1066 | ||
1067 | //dd('new message', $new_message); | 1067 | //dd('new message', $new_message); |
1068 | return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]); | 1068 | return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]); |
1069 | } | 1069 | } |
1070 | } | 1070 | } |
1071 | 1071 | ||
1072 | // Информация о предыдущих компаниях | 1072 | // Информация о предыдущих компаниях |
1073 | public function new_prev_company(Worker $worker) { | 1073 | public function new_prev_company(Worker $worker) { |
1074 | return view('workers.prev_company_form', compact('worker')); | 1074 | return view('workers.prev_company_form', compact('worker')); |
1075 | } | 1075 | } |
1076 | 1076 | ||
1077 | // Добавление контакта компании | 1077 | // Добавление контакта компании |
1078 | public function add_prev_company(PrevCompanyRequest $request) { | 1078 | public function add_prev_company(PrevCompanyRequest $request) { |
1079 | // Возвращение параметров | 1079 | // Возвращение параметров |
1080 | $all = $request->all(); | 1080 | $all = $request->all(); |
1081 | PrevCompany::create($all); | 1081 | PrevCompany::create($all); |
1082 | 1082 | ||
1083 | return response()->json(['success' => true]); | 1083 | return response()->json(['success' => true]); |
1084 | } | 1084 | } |
1085 | 1085 | ||
1086 | // Редактирование контакта компании | 1086 | // Редактирование контакта компании |
1087 | public function edit_prev_company(PrevCompany $doc, Worker $worker) { | 1087 | public function edit_prev_company(PrevCompany $doc, Worker $worker) { |
1088 | return view('workers.prev_company_edit_form', compact('doc', 'worker')); | 1088 | return view('workers.prev_company_edit_form', compact('doc', 'worker')); |
1089 | } | 1089 | } |
1090 | 1090 | ||
1091 | //Сохранение редактирования контакта компании | 1091 | //Сохранение редактирования контакта компании |
1092 | public function update_prev_company(PrevCompany $doc, Request $request){ | 1092 | public function update_prev_company(PrevCompany $doc, Request $request){ |
1093 | $all = $request->all(); | 1093 | $all = $request->all(); |
1094 | $doc->update($all); | 1094 | $doc->update($all); |
1095 | 1095 | ||
1096 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись'); | 1096 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно отредактировали запись'); |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | // Удаление контакта предыдущей компании | 1099 | // Удаление контакта предыдущей компании |
1100 | public function delete_prev_company(PrevCompany $doc) { | 1100 | public function delete_prev_company(PrevCompany $doc) { |
1101 | $doc->delete(); | 1101 | $doc->delete(); |
1102 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); | 1102 | return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); |
1103 | } | 1103 | } |
1104 | 1104 | ||
1105 | public function autoresponder() | 1105 | public function autoresponder() |
1106 | { | 1106 | { |
1107 | $user = Auth::user(); | 1107 | $user = Auth::user(); |
1108 | return view('workers.autoresponder', compact('user')); | 1108 | return view('workers.autoresponder', compact('user')); |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | public function autoresponderSave(Request $request): RedirectResponse | 1111 | public function autoresponderSave(Request $request): RedirectResponse |
1112 | { | 1112 | { |
1113 | /** @var Employer $employer */ | 1113 | /** @var Employer $employer */ |
1114 | $employer = Auth::user(); | 1114 | $employer = Auth::user(); |
1115 | $employer->autoresponder = $request->get('autoresponder', false) === 'on'; | 1115 | $employer->autoresponder = $request->get('autoresponder', false) === 'on'; |
1116 | $employer->autoresponder_message = $request->get('autoresponder_message'); | 1116 | $employer->autoresponder_message = $request->get('autoresponder_message'); |
1117 | $employer->save(); | 1117 | $employer->save(); |
1118 | 1118 | ||
1119 | return redirect(route('worker.autoresponder')); | 1119 | return redirect(route('worker.autoresponder')); |
1120 | } | 1120 | } |
1121 | /** | 1121 | /** |
1122 | * @throws JsonException | 1122 | * @throws JsonException |
1123 | */ | 1123 | */ |
1124 | public function resumeAutoLiftForm(): View | 1124 | public function resumeAutoLiftForm(): View |
1125 | { | 1125 | { |
1126 | $worker = Auth::user()->workers[0]; | 1126 | $worker = Auth::user()->workers[0]; |
1127 | 1127 | ||
1128 | $options = $worker->autoliftOptions ?? new WorkerAutoliftOption(); | 1128 | $options = $worker->autoliftOptions ?? new WorkerAutoliftOption(); |
1129 | 1129 | ||
1130 | return view('workers.resume_autolift', compact('worker', 'options')); | 1130 | return view('workers.resume_autolift', compact('worker', 'options')); |
1131 | } | 1131 | } |
1132 | 1132 | ||
1133 | /** | 1133 | /** |
1134 | * @throws JsonException | 1134 | * @throws JsonException |
1135 | */ | 1135 | */ |
1136 | public function resumeAutoLiftSave(Request $request) | 1136 | public function resumeAutoLiftSave(Request $request) |
1137 | { | 1137 | { |
1138 | $worker = Auth::user()->workers[0]; | 1138 | $worker = Auth::user()->workers[0]; |
1139 | 1139 | ||
1140 | $worker->autoliftOptions()->updateOrCreate( | 1140 | $worker->autoliftOptions()->updateOrCreate( |
1141 | [ | 1141 | [ |
1142 | 'worker_id' => $worker->id, | 1142 | 'worker_id' => $worker->id, |
1143 | ], | 1143 | ], |
1144 | [ | 1144 | [ |
1145 | 'is_enabled' => $request->get('is_enabled') === 'true', | 1145 | 'is_enabled' => $request->get('is_enabled') === 'true', |
1146 | 'times_per_day' => $request->get('times_per_day'), | 1146 | 'times_per_day' => $request->get('times_per_day'), |
1147 | 'days_repeat' => $request->get('days_repeat'), | 1147 | 'days_repeat' => $request->get('days_repeat'), |
1148 | 'time_send_first' => $request->get('time_send_first'), | 1148 | 'time_send_first' => $request->get('time_send_first'), |
1149 | 'time_send_second' => $request->get('time_send_second'), | 1149 | 'time_send_second' => $request->get('time_send_second'), |
1150 | 'time_send_third' => $request->get('time_send_third'), | 1150 | 'time_send_third' => $request->get('time_send_third'), |
1151 | 'time_send_tg' => $request->get('time_send_tg'), | 1151 | 'time_send_tg' => $request->get('time_send_tg'), |
1152 | 'autolift_site' => $request->get('autolift_site') === 'on', | 1152 | 'autolift_site' => $request->get('autolift_site') === 'on', |
1153 | ] | 1153 | ] |
1154 | ); | 1154 | ); |
1155 | 1155 | ||
1156 | return response()->json(['success' => true]); | 1156 | return response()->json(['success' => true]); |
1157 | } | 1157 | } |
1158 | } | 1158 | } |
1159 | 1159 | ||
1160 | 1160 |