Commit 5e17adedfd9de60a9f68025b3d5802c3dfb0226a

Authored by Hayk Nazaryan
1 parent 1c1dedea99
Exists in master

fix vacancy up

Showing 1 changed file with 1 additions and 2 deletions Inline Diff

app/Http/Controllers/EmployerController.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\BaseUser_min_Request; 7 use App\Http\Requests\BaseUser_min_Request;
8 use App\Http\Requests\FlotRequest; 8 use App\Http\Requests\FlotRequest;
9 use App\Http\Requests\MessagesRequiest; 9 use App\Http\Requests\MessagesRequiest;
10 use App\Http\Requests\VacancyRequestEdit; 10 use App\Http\Requests\VacancyRequestEdit;
11 use App\Mail\MailCreateEmployer; 11 use App\Mail\MailCreateEmployer;
12 use App\Mail\MailSotrudnichestvo; 12 use App\Mail\MailSotrudnichestvo;
13 use App\Mail\MassSendingMessages; 13 use App\Mail\MassSendingMessages;
14 use App\Mail\SendAllMessages; 14 use App\Mail\SendAllMessages;
15 use App\Models\Ad_employer; 15 use App\Models\Ad_employer;
16 use App\Models\ad_response; 16 use App\Models\ad_response;
17 use App\Models\Category; 17 use App\Models\Category;
18 use App\Models\Chat; 18 use App\Models\Chat;
19 use App\Models\Employer; 19 use App\Models\Employer;
20 use App\Models\EmployerAutoliftOption; 20 use App\Models\EmployerAutoliftOption;
21 use App\Models\Flot; 21 use App\Models\Flot;
22 use App\Models\Job_title; 22 use App\Models\Job_title;
23 use App\Models\Like_worker; 23 use App\Models\Like_worker;
24 use App\Models\Message; 24 use App\Models\Message;
25 use App\Models\Worker; 25 use App\Models\Worker;
26 use App\Models\MessagesRequests; 26 use App\Models\MessagesRequests;
27 use Carbon\Carbon; 27 use Carbon\Carbon;
28 use Illuminate\Auth\Events\Registered; 28 use Illuminate\Auth\Events\Registered;
29 use Illuminate\Database\Eloquent\Builder; 29 use Illuminate\Database\Eloquent\Builder;
30 use Illuminate\Http\RedirectResponse; 30 use Illuminate\Http\RedirectResponse;
31 use Illuminate\Http\Request; 31 use Illuminate\Http\Request;
32 use Illuminate\Support\Facades\Auth; 32 use Illuminate\Support\Facades\Auth;
33 use Illuminate\Support\Facades\Cache; 33 use Illuminate\Support\Facades\Cache;
34 use Illuminate\Support\Facades\DB; 34 use Illuminate\Support\Facades\DB;
35 use Illuminate\Support\Facades\Hash; 35 use Illuminate\Support\Facades\Hash;
36 use Illuminate\Support\Facades\Log; 36 use Illuminate\Support\Facades\Log;
37 use Illuminate\Support\Facades\Mail; 37 use Illuminate\Support\Facades\Mail;
38 use Illuminate\Support\Facades\Storage; 38 use Illuminate\Support\Facades\Storage;
39 use App\Models\User as User_Model; 39 use App\Models\User as User_Model;
40 use Illuminate\Support\Facades\Validator; 40 use Illuminate\Support\Facades\Validator;
41 use App\Enums\DbExportColumns; 41 use App\Enums\DbExportColumns;
42 use Illuminate\View\View; 42 use Illuminate\View\View;
43 use JsonException; 43 use JsonException;
44 use Throwable; 44 use Throwable;
45 45
46 class EmployerController extends Controller 46 class EmployerController extends Controller
47 { 47 {
48 public function vacancie($vacancy, Request $request) { 48 public function vacancie($vacancy, Request $request) {
49 $title = 'Заголовок вакансии'; 49 $title = 'Заголовок вакансии';
50 $Query = Ad_employer::with('jobs')-> 50 $Query = Ad_employer::with('jobs')->
51 with('cat')-> 51 with('cat')->
52 with('employer')-> 52 with('employer')->
53 with('jobs_code')-> 53 with('jobs_code')->
54 select('ad_employers.*')-> 54 select('ad_employers.*')->
55 where('id', '=', $vacancy)->get(); 55 where('id', '=', $vacancy)->get();
56 56
57 if ($Query[0]->active_is===0 || $Query[0]->is_remove!=0){ 57 if ($Query[0]->active_is===0 || $Query[0]->is_remove!=0){
58 58
59 abort(404); 59 abort(404);
60 60
61 } 61 }
62 62
63 if (isset(Auth()->user()->id)) 63 if (isset(Auth()->user()->id))
64 $uid = Auth()->user()->id; 64 $uid = Auth()->user()->id;
65 else 65 else
66 $uid = 0; 66 $uid = 0;
67 $title = $Query[0]->name; 67 $title = $Query[0]->name;
68 if ($request->ajax()) { 68 if ($request->ajax()) {
69 return view('ajax.vacance-item', compact('Query','uid')); 69 return view('ajax.vacance-item', compact('Query','uid'));
70 } else { 70 } else {
71 return view('vacance-item', compact('title', 'Query', 'uid')); 71 return view('vacance-item', compact('title', 'Query', 'uid'));
72 } 72 }
73 } 73 }
74 74
75 public function logout() { 75 public function logout() {
76 Auth::logout(); 76 Auth::logout();
77 return redirect()->route('index') 77 return redirect()->route('index')
78 ->with('success', 'Вы вышли из личного кабинета'); 78 ->with('success', 'Вы вышли из личного кабинета');
79 } 79 }
80 80
81 public function employer_info() { 81 public function employer_info() {
82 // код юзера 82 // код юзера
83 $user_info = Auth()->user(); 83 $user_info = Auth()->user();
84 // вьюшка для вывода данных 84 // вьюшка для вывода данных
85 return view('employers.info', compact('user_info')); 85 return view('employers.info', compact('user_info'));
86 } 86 }
87 87
88 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) { 88 public function employer_info_save(User_Model $user, BaseUser_min_Request $request) {
89 // Все данные через реквест 89 // Все данные через реквест
90 $all = $request->all(); 90 $all = $request->all();
91 unset($all['_token']); 91 unset($all['_token']);
92 // обновление 92 // обновление
93 $user->update($all); 93 $user->update($all);
94 return redirect()->route('employer.employer_info'); 94 return redirect()->route('employer.employer_info');
95 } 95 }
96 96
97 public function cabinet() { 97 public function cabinet() {
98 $id = Auth()->user()->id; 98 $id = Auth()->user()->id;
99 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 99 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
100 WhereHas('users', 100 WhereHas('users',
101 function (Builder $query) use ($id) {$query->Where('id', $id); 101 function (Builder $query) use ($id) {$query->Where('id', $id);
102 })->get(); 102 })->get();
103 return view('employers.cabinet45', compact('Employer')); 103 return view('employers.cabinet45', compact('Employer'));
104 } 104 }
105 105
106 public function slider_flot() { 106 public function slider_flot() {
107 $id = Auth()->user()->id; 107 $id = Auth()->user()->id;
108 $Employer = Employer::query()->with('users')->with('ads')->with('flots')-> 108 $Employer = Employer::query()->with('users')->with('ads')->with('flots')->
109 WhereHas('users', 109 WhereHas('users',
110 function (Builder $query) use ($id) {$query->Where('id', $id); 110 function (Builder $query) use ($id) {$query->Where('id', $id);
111 })->get(); 111 })->get();
112 return view('employers.fly-flot', compact('Employer')); 112 return view('employers.fly-flot', compact('Employer'));
113 } 113 }
114 114
115 public function cabinet_save(Employer $Employer, Request $request) { 115 public function cabinet_save(Employer $Employer, Request $request) {
116 $params = $request->all(); 116 $params = $request->all();
117 $params['user_id'] = Auth()->user()->id; 117 $params['user_id'] = Auth()->user()->id;
118 $id = $Employer->id; 118 $id = $Employer->id;
119 119
120 if ($request->has('logo')) { 120 if ($request->has('logo')) {
121 if (!empty($Employer->logo)) { 121 if (!empty($Employer->logo)) {
122 Storage::delete($Employer->logo); 122 Storage::delete($Employer->logo);
123 } 123 }
124 $params['logo'] = $request->file('logo')->store("employer/$id", 'public'); 124 $params['logo'] = $request->file('logo')->store("employer/$id", 'public');
125 } 125 }
126 126
127 $Employer->update($params); 127 $Employer->update($params);
128 128
129 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены'); 129 return redirect()->route('employer.cabinet')->with('success', 'Данные были успешно сохранены');
130 } 130 }
131 131
132 public function save_add_flot(FlotRequest $request) { 132 public function save_add_flot(FlotRequest $request) {
133 // отмена 133 // отмена
134 $params = $request->all(); 134 $params = $request->all();
135 135
136 if ($request->has('image')) { 136 if ($request->has('image')) {
137 $params['image'] = $request->file('image')->store("flot", 'public'); 137 $params['image'] = $request->file('image')->store("flot", 'public');
138 } 138 }
139 Flot::create($params); 139 Flot::create($params);
140 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get(); 140 $data_flots = Flot::query()->where('employer_id', $request->get('employer_if'))->get();
141 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 141 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
142 } 142 }
143 143
144 public function edit_flot(Flot $Flot, Employer $Employer) { 144 public function edit_flot(Flot $Flot, Employer $Employer) {
145 return view('employers.edit-flot', compact('Flot', 'Employer')); 145 return view('employers.edit-flot', compact('Flot', 'Employer'));
146 } 146 }
147 147
148 public function update_flot(FlotRequest $request, Flot $Flot) { 148 public function update_flot(FlotRequest $request, Flot $Flot) {
149 $params = $request->all(); 149 $params = $request->all();
150 150
151 if ($request->has('image')) { 151 if ($request->has('image')) {
152 if (!empty($flot->image)) { 152 if (!empty($flot->image)) {
153 Storage::delete($flot->image); 153 Storage::delete($flot->image);
154 } 154 }
155 $params['image'] = $request->file('image')->store("flot", 'public'); 155 $params['image'] = $request->file('image')->store("flot", 'public');
156 } else { 156 } else {
157 if (!empty($flot->image)) $params['image'] = $flot->image; 157 if (!empty($flot->image)) $params['image'] = $flot->image;
158 } 158 }
159 159
160 $Flot->update($params); 160 $Flot->update($params);
161 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен'); 161 return redirect()->route('employer.slider_flot')->with('success', 'Новый корабль был добавлен');
162 } 162 }
163 163
164 public function delete_flot(Flot $Flot) { 164 public function delete_flot(Flot $Flot) {
165 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get(); 165 $data_flots = Flot::query()->where('employer_id', $Flot->employer_id)->get();
166 166
167 if (isset($Flot->id)) $Flot->delete(); 167 if (isset($Flot->id)) $Flot->delete();
168 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален'); 168 return redirect()->route('employer.slider_flot')->with('success', 'Корабль был удален');
169 } 169 }
170 170
171 // Форма добавления вакансий 171 // Форма добавления вакансий
172 public function cabinet_vacancie() { 172 public function cabinet_vacancie() {
173 /** @var User_Model $user */ 173 /** @var User_Model $user */
174 $user = Auth()->user(); 174 $user = Auth()->user();
175 175
176 if ($user->is_public) { 176 if ($user->is_public) {
177 $categories = Category::query()->active()->get(); 177 $categories = Category::query()->active()->get();
178 178
179 $jobs = Job_title::query() 179 $jobs = Job_title::query()
180 ->orderByDesc('sort') 180 ->orderByDesc('sort')
181 ->OrderBy('name') 181 ->OrderBy('name')
182 ->where('is_remove', '=', '0') 182 ->where('is_remove', '=', '0')
183 ->where('is_bd', '=', '0') 183 ->where('is_bd', '=', '0')
184 ->get(); 184 ->get();
185 185
186 $Employer = Employer::query() 186 $Employer = Employer::query()
187 ->with(['users', 'ads', 'flots']) 187 ->with(['users', 'ads', 'flots'])
188 ->whereHas('users', fn (Builder $query) => $query->where('id', $user->id)) 188 ->whereHas('users', fn (Builder $query) => $query->where('id', $user->id))
189 ->get(); 189 ->get();
190 190
191 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories')); 191 return view('employers.add_vacancy', compact('Employer', 'jobs', 'categories'));
192 } 192 }
193 193
194 return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"]); 194 return redirect()->route('page', ['pages' => "Usloviya-razmescheniya"]);
195 // return redirect()->route('employer.cabinet_vacancie_danger'); 195 // return redirect()->route('employer.cabinet_vacancie_danger');
196 } 196 }
197 197
198 // Форма предупреждения об оплате 198 // Форма предупреждения об оплате
199 public function cabinet_vacancie_danger() { 199 public function cabinet_vacancie_danger() {
200 return view('employers.add_vacancy_danger'); 200 return view('employers.add_vacancy_danger');
201 } 201 }
202 202
203 // Сохранение вакансии 203 // Сохранение вакансии
204 public function cabinet_vacancy_save1(VacancyRequestEdit $request) { 204 public function cabinet_vacancy_save1(VacancyRequestEdit $request) {
205 $params_emp = $request->all(); 205 $params_emp = $request->all();
206 206
207 $params_job["job_title_id"] = $params_emp['job_title_id']; 207 $params_job["job_title_id"] = $params_emp['job_title_id'];
208 208
209 $ad_jobs = Ad_employer::create($params_emp); 209 $ad_jobs = Ad_employer::create($params_emp);
210 $ad_jobs->jobs()->sync($request->get('job_title_id')); 210 $ad_jobs->jobs()->sync($request->get('job_title_id'));
211 211
212 return redirect()->route('employer.vacancy_list')->with('success', 'Вакансия успешно опубликована'); 212 return redirect()->route('employer.vacancy_list')->with('success', 'Вакансия успешно опубликована');
213 } 213 }
214 214
215 // Список вакансий 215 // Список вакансий
216 public function vacancy_list(Request $request) { 216 public function vacancy_list(Request $request) {
217 $id = Auth()->user()->id; 217 $id = Auth()->user()->id;
218 218
219 $Employer = Employer::query()->where('user_id', $id)->first(); 219 $Employer = Employer::query()->where('user_id', $id)->first();
220 $vacancy_list = Ad_employer::query() 220 $vacancy_list = Ad_employer::query()
221 ->with('jobs') 221 ->with('jobs')
222 ->with('jobs_code') 222 ->with('jobs_code')
223 ->where('employer_id', $Employer->id) 223 ->where('employer_id', $Employer->id)
224 ->where('is_remove', 0) 224 ->where('is_remove', 0)
225 ->orderbyDesc('updated_at') 225 ->orderbyDesc('updated_at')
226 ; 226 ;
227 227
228 if (($request->has('search')) && (!empty($request->get('search')))) { 228 if (($request->has('search')) && (!empty($request->get('search')))) {
229 $search = $request->get('search'); 229 $search = $request->get('search');
230 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%"); 230 $vacancy_list = $vacancy_list->where('name', 'LIKE', "%$search%");
231 } 231 }
232 232
233 if ($request->get('sort')) { 233 if ($request->get('sort')) {
234 $sort = $request->get('sort'); 234 $sort = $request->get('sort');
235 switch ($sort) { 235 switch ($sort) {
236 case 'nopublic': $vacancy_list->orderByDesc('updated_at') 236 case 'nopublic': $vacancy_list->orderByDesc('updated_at')
237 ->where('active_is', 0); 237 ->where('active_is', 0);
238 break; 238 break;
239 case 'public': $vacancy_list->orderByDesc('updated_at') 239 case 'public': $vacancy_list->orderByDesc('updated_at')
240 ->where('active_is',1); 240 ->where('active_is',1);
241 break; 241 break;
242 default: $vacancy_list->orderByDesc('updated_at'); 242 default: $vacancy_list->orderByDesc('updated_at');
243 break; 243 break;
244 } 244 }
245 } else { 245 } else {
246 $vacancy_list = $vacancy_list->orderByDesc('updated_at')->orderBy('id'); 246 $vacancy_list = $vacancy_list->orderByDesc('updated_at')->orderBy('id');
247 } 247 }
248 248
249 $vacancy_list = $vacancy_list->paginate(10); 249 $vacancy_list = $vacancy_list->paginate(10);
250 250
251 if ($request->ajax()) { 251 if ($request->ajax()) {
252 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer')); 252 return view('employers.ajax.list_vacancy', compact('vacancy_list', 'Employer'));
253 } else { 253 } else {
254 return view('employers.list_vacancy', compact('vacancy_list', 'Employer')); 254 return view('employers.list_vacancy', compact('vacancy_list', 'Employer'));
255 } 255 }
256 } 256 }
257 257
258 // Карточка вакансии 258 // Карточка вакансии
259 public function vacancy_edit(Ad_employer $ad_employer) { 259 public function vacancy_edit(Ad_employer $ad_employer) {
260 $id = Auth()->user()->id; 260 $id = Auth()->user()->id;
261 $Positions = Category::query()->where('is_remove', '=', '0')->get(); 261 $Positions = Category::query()->where('is_remove', '=', '0')->get();
262 262
263 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 263 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
264 where('is_remove', '=', '0')-> 264 where('is_remove', '=', '0')->
265 where('is_bd', '=', '0')->get(); 265 where('is_bd', '=', '0')->get();
266 266
267 $Employer = Employer::query()->with('users')->with('ads')-> 267 $Employer = Employer::query()->with('users')->with('ads')->
268 with('flots')->where('user_id', $id)->first(); 268 with('flots')->where('user_id', $id)->first();
269 269
270 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs')); 270 return view('employers.edit_vacancy', compact('ad_employer', 'Positions','Employer', 'jobs'));
271 } 271 }
272 272
273 // Сохранение-редактирование записи 273 // Сохранение-редактирование записи
274 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) { 274 public function vacancy_save_me(VacancyRequestEdit $request, Ad_employer $ad_employer) {
275 $params = $request->all(); 275 $params = $request->all();
276 276
277 $ad_employer->update($params); 277 $ad_employer->update($params);
278 $ad_employer->active_is = 1; 278 $ad_employer->active_is = 1;
279 $ad_employer->save(); 279 $ad_employer->save();
280 $ad_employer->jobs()->sync($request->get('job_title_id')); 280 $ad_employer->jobs()->sync($request->get('job_title_id'));
281 281
282 $id = Auth()->user()->id; 282 $id = Auth()->user()->id;
283 $Positions = Category::query()->where('is_remove', '=', '0')->get(); 283 $Positions = Category::query()->where('is_remove', '=', '0')->get();
284 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name') 284 $jobs = Job_title::query()->orderByDesc('sort')->OrderBy('name')
285 ->where('is_remove', '=', '0') 285 ->where('is_remove', '=', '0')
286 ->where('is_bd', '=', '0') 286 ->where('is_bd', '=', '0')
287 ->get(); 287 ->get();
288 288
289 $Employer = Employer::query() 289 $Employer = Employer::query()
290 ->with('users')->with('ads')->with('flots')->where('user_id', $id)->first(); 290 ->with('users')->with('ads')->with('flots')->where('user_id', $id)->first();
291 291
292 return redirect()->route('employer.vacancy_list')->with('success', 'Вакансия успешно отредактирована'); 292 return redirect()->route('employer.vacancy_list')->with('success', 'Вакансия успешно отредактирована');
293 } 293 }
294 294
295 // Сохранение карточки вакансии 295 // Сохранение карточки вакансии
296 public function vacancy_save(Request $request, Ad_employer $ad_employer) { 296 public function vacancy_save(Request $request, Ad_employer $ad_employer) {
297 $all = $request->all(); 297 $all = $request->all();
298 $ad_employer->update($all); 298 $ad_employer->update($all);
299 return redirect()->route('employer.cabinet_vacancie'); 299 return redirect()->route('employer.cabinet_vacancie');
300 } 300 }
301 301
302 // Удаление карточки вакансии 302 // Удаление карточки вакансии
303 public function vacancy_delete(Ad_employer $ad_employer) { 303 public function vacancy_delete(Ad_employer $ad_employer) {
304 $ad_employer->delete(); 304 $ad_employer->delete();
305 305
306 return redirect()->route('employer.vacancy_list') 306 return redirect()->route('employer.vacancy_list')
307 ->with('success', 'Вакансия удалена'); 307 ->with('success', 'Вакансия удалена');
308 } 308 }
309 309
310 // Обновление даты 310 // Обновление даты
311 public function vacancy_up(Ad_employer $ad_employer) { 311 public function vacancy_up(Ad_employer $ad_employer) {
312 $up = date('m/d/Y h:i:s', time()); 312 $ad_employer->updated_at = now();
313 $ad_employer->updated_at = $up;
314 $ad_employer->save(); 313 $ad_employer->save();
315 314
316 return redirect()->route('employer.vacancy_list') 315 return redirect()->route('employer.vacancy_list')
317 ->with('success', 'Вакансия поднята'); 316 ->with('success', 'Вакансия поднята');
318 } 317 }
319 318
320 //Видимость вакансии 319 //Видимость вакансии
321 public function vacancy_eye(Ad_employer $ad_employer, $status) { 320 public function vacancy_eye(Ad_employer $ad_employer, $status) {
322 $statusMessages = [ 321 $statusMessages = [
323 'Вакансия скрыта', 322 'Вакансия скрыта',
324 'Вакансия видна работникам' 323 'Вакансия видна работникам'
325 ]; 324 ];
326 325
327 $vac_emp = Ad_employer::findOrFail($ad_employer->id); 326 $vac_emp = Ad_employer::findOrFail($ad_employer->id);
328 $vac_emp->active_is = $status; 327 $vac_emp->active_is = $status;
329 $vac_emp->save(); 328 $vac_emp->save();
330 329
331 return redirect()->route('employer.vacancy_list') 330 return redirect()->route('employer.vacancy_list')
332 ->with('success', $statusMessages[$status]); 331 ->with('success', $statusMessages[$status]);
333 } 332 }
334 333
335 //Вакансия редактирования (шаблон) 334 //Вакансия редактирования (шаблон)
336 public function vacancy_update(Ad_employer $id) { 335 public function vacancy_update(Ad_employer $id) {
337 336
338 } 337 }
339 338
340 //Отклики на вакансию - лист 339 //Отклики на вакансию - лист
341 public function answers(Employer $employer, Request $request) { 340 public function answers(Employer $employer, Request $request) {
342 $user_id = Auth()->user()->id; 341 $user_id = Auth()->user()->id;
343 $answer = Ad_employer::query()->where('employer_id', $employer->id); 342 $answer = Ad_employer::query()->where('employer_id', $employer->id);
344 if ($request->has('search')) { 343 if ($request->has('search')) {
345 $search = trim($request->get('search')); 344 $search = trim($request->get('search'));
346 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%"); 345 if (!empty($search)) $answer = $answer->where('name', 'LIKE', "%$search%");
347 } 346 }
348 347
349 $answer = $answer->with('response')->OrderByDESC('id')->get(); 348 $answer = $answer->with('response')->OrderByDESC('id')->get();
350 349
351 return view('employers.list_answer', compact('answer', 'user_id', 'employer')); 350 return view('employers.list_answer', compact('answer', 'user_id', 'employer'));
352 } 351 }
353 352
354 //Обновление статуса 353 //Обновление статуса
355 public function supple_status(employer $employer, ad_response $ad_response, $flag) { 354 public function supple_status(employer $employer, ad_response $ad_response, $flag) {
356 $ad_response->update(Array('flag' => $flag)); 355 $ad_response->update(Array('flag' => $flag));
357 return redirect()->route('employer.answers', ['employer' => $employer->id]); 356 return redirect()->route('employer.answers', ['employer' => $employer->id]);
358 } 357 }
359 358
360 //Страницы сообщений список 359 //Страницы сообщений список
361 public function messages($type_message) { 360 public function messages($type_message) {
362 $user_id = Auth()->user()->id; 361 $user_id = Auth()->user()->id;
363 $superAdmin =User_Model::superAdmin(); 362 $superAdmin =User_Model::superAdmin();
364 $chats = Chat::get_user_chats($user_id); 363 $chats = Chat::get_user_chats($user_id);
365 $admin_chat = Chat::get_user_admin_chat($user_id); 364 $admin_chat = Chat::get_user_admin_chat($user_id);
366 $user_type = 'employer'; 365 $user_type = 'employer';
367 366
368 return view('employers.messages', compact('chats', 'admin_chat', 'user_id', 'user_type','superAdmin')); 367 return view('employers.messages', compact('chats', 'admin_chat', 'user_id', 'user_type','superAdmin'));
369 } 368 }
370 369
371 // Диалог между пользователями 370 // Диалог между пользователями
372 public function dialog(Chat $chat, Request $request) { 371 public function dialog(Chat $chat, Request $request) {
373 // Получение параметров. 372 // Получение параметров.
374 if ($request->has('ad_employer')){ 373 if ($request->has('ad_employer')){
375 $ad_employer = $request->get('ad_employer'); 374 $ad_employer = $request->get('ad_employer');
376 } else { 375 } else {
377 $ad_employer = 0; 376 $ad_employer = 0;
378 } 377 }
379 $superAdmin =User_Model::superAdmin(); 378 $superAdmin =User_Model::superAdmin();
380 379
381 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first(); 380 $sender = User_Model::query()->with('workers')->with('employers')->where('id', $chat->user_id)->first();
382 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first(); 381 $companion = User_Model::query()->with('workers')->with('employers')->where('id', $chat->to_user_id)->first();
383 382
384 $Messages = Chat::get_chat_messages($chat); 383 $Messages = Chat::get_chat_messages($chat);
385 384
386 Message::where('user_id', '=', $chat->to_user_id)->where('to_user_id', '=', $chat->user_id)->update(['flag_new' => 0]); 385 Message::where('user_id', '=', $chat->to_user_id)->where('to_user_id', '=', $chat->user_id)->update(['flag_new' => 0]);
387 386
388 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages','chat','superAdmin')); 387 return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages','chat','superAdmin'));
389 } 388 }
390 389
391 public function pin_chat(Request $request){ 390 public function pin_chat(Request $request){
392 $chat_id = $request->get('id'); 391 $chat_id = $request->get('id');
393 $is_fixed = $request->get('is_fixed'); 392 $is_fixed = $request->get('is_fixed');
394 393
395 $chat = Chat::pin_chat($chat_id, $is_fixed); 394 $chat = Chat::pin_chat($chat_id, $is_fixed);
396 $message = $chat->is_fixed ? 'Сообщение закреплено' : 'Сообщение откреплено'; 395 $message = $chat->is_fixed ? 'Сообщение закреплено' : 'Сообщение откреплено';
397 return redirect()->back()->with('success', $message); 396 return redirect()->back()->with('success', $message);
398 } 397 }
399 398
400 public function remove_chat(Request $request){ 399 public function remove_chat(Request $request){
401 $chat_id = $request->get('id'); 400 $chat_id = $request->get('id');
402 Chat::remove_chat($chat_id); 401 Chat::remove_chat($chat_id);
403 } 402 }
404 403
405 // Регистрация работодателя 404 // Регистрация работодателя
406 public function register_employer(Request $request) 405 public function register_employer(Request $request)
407 { 406 {
408 $rules = [ 407 $rules = [
409 'surname' => ['nullable', 'string', 'max:255'], 408 'surname' => ['nullable', 'string', 'max:255'],
410 'name_man' => ['nullable', 'string', 'max:255'], 409 'name_man' => ['nullable', 'string', 'max:255'],
411 'email' => ['required', 'email', 'max:255', 'unique:users'], 410 'email' => ['required', 'email', 'max:255', 'unique:users'],
412 'name_company' => ['required', 'string', 'max:255'], 411 'name_company' => ['required', 'string', 'max:255'],
413 'password' => ['required', 'string', 'min:6'], 412 'password' => ['required', 'string', 'min:6'],
414 'password_confirmation' => ['required', 'same:password'], 413 'password_confirmation' => ['required', 'same:password'],
415 'politik' => ['required', 'accepted'], 414 'politik' => ['required', 'accepted'],
416 ]; 415 ];
417 416
418 $messages = [ 417 $messages = [
419 'required' => 'Укажите обязательное поле', 418 'required' => 'Укажите обязательное поле',
420 'email' => 'Введите корректный email', 419 'email' => 'Введите корректный email',
421 'unique' => 'Email уже зарегистрирован', 420 'unique' => 'Email уже зарегистрирован',
422 'same' => 'Пароль и подтверждение пароля не совпадают', 421 'same' => 'Пароль и подтверждение пароля не совпадают',
423 'min' => [ 422 'min' => [
424 'string' => 'Поле должно быть не менее :min символов', 423 'string' => 'Поле должно быть не менее :min символов',
425 ], 424 ],
426 'max' => [ 425 'max' => [
427 'string' => 'Поле должно быть не более :max символов', 426 'string' => 'Поле должно быть не более :max символов',
428 ], 427 ],
429 'accepted' => 'Необходимо согласиться с политикой конфиденциальности', 428 'accepted' => 'Необходимо согласиться с политикой конфиденциальности',
430 ]; 429 ];
431 430
432 $validator = Validator::make($request->all(), $rules, $messages); 431 $validator = Validator::make($request->all(), $rules, $messages);
433 432
434 if ($validator->fails()) { 433 if ($validator->fails()) {
435 return response()->json(['ERRORS' => $validator->errors()], 422); 434 return response()->json(['ERRORS' => $validator->errors()], 422);
436 } 435 }
437 436
438 $params = $request->all(); 437 $params = $request->all();
439 438
440 if (empty($params['surname'])) { 439 if (empty($params['surname'])) {
441 $params['surname'] = 'Неизвестно'; 440 $params['surname'] = 'Неизвестно';
442 } 441 }
443 if (empty($params['name_man'])) { 442 if (empty($params['name_man'])) {
444 $params['name_man'] = 'Неизвестно'; 443 $params['name_man'] = 'Неизвестно';
445 } 444 }
446 445
447 if ($user = $this->create($params)) { 446 if ($user = $this->create($params)) {
448 event(new Registered($user)); 447 event(new Registered($user));
449 448
450 try { 449 try {
451 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params)); 450 Mail::to(env('EMAIL_ADMIN'))->send(new MailCreateEmployer($params));
452 } catch (Throwable $e) { 451 } catch (Throwable $e) {
453 Log::error('Ошибка при отправке письма: ' . $e->getMessage()); 452 Log::error('Ошибка при отправке письма: ' . $e->getMessage());
454 } 453 }
455 454
456 Auth::guard()->login($user); 455 Auth::guard()->login($user);
457 456
458 return response()->json([ 457 return response()->json([
459 'REDIRECT' => route('employer.cabinet'), 458 'REDIRECT' => route('employer.cabinet'),
460 ]); 459 ]);
461 } 460 }
462 461
463 return response()->json([ 462 return response()->json([
464 'ERROR' => 'Произошла ошибка при регистрации. Попробуйте снова.', 463 'ERROR' => 'Произошла ошибка при регистрации. Попробуйте снова.',
465 ]); 464 ]);
466 } 465 }
467 466
468 // Создание пользователя 467 // Создание пользователя
469 protected function create(array $data) 468 protected function create(array $data)
470 { 469 {
471 $Use = new User_Model(); 470 $Use = new User_Model();
472 $Code_user = $Use->create([ 471 $Code_user = $Use->create([
473 'name' => $data['surname']." ".$data['name_man'], 472 'name' => $data['surname']." ".$data['name_man'],
474 'name_man' => $data['name_man'], 473 'name_man' => $data['name_man'],
475 'surname' => $data['surname'], 474 'surname' => $data['surname'],
476 'surname2' => $data['surname2'], 475 'surname2' => $data['surname2'],
477 'subscribe_email' => $data['email'], 476 'subscribe_email' => $data['email'],
478 'email' => $data['email'], 477 'email' => $data['email'],
479 'telephone' => $data['telephone'], 478 'telephone' => $data['telephone'],
480 'is_worker' => 0, 479 'is_worker' => 0,
481 'password' => Hash::make($data['password']), 480 'password' => Hash::make($data['password']),
482 'pubpassword' => base64_encode($data['password']), 481 'pubpassword' => base64_encode($data['password']),
483 'email_verified_at' => Carbon::now() 482 'email_verified_at' => Carbon::now()
484 ]); 483 ]);
485 484
486 if ($Code_user->id > 0) { 485 if ($Code_user->id > 0) {
487 $Employer = new Employer(); 486 $Employer = new Employer();
488 $Employer->user_id = $Code_user->id; 487 $Employer->user_id = $Code_user->id;
489 $Employer->name_company = $data['name_company']; 488 $Employer->name_company = $data['name_company'];
490 $Employer->email = $data['email']; 489 $Employer->email = $data['email'];
491 $Employer->telephone = $data['telephone']; 490 $Employer->telephone = $data['telephone'];
492 $Employer->code = Tools::generator_id(10); 491 $Employer->code = Tools::generator_id(10);
493 $Employer->save(); 492 $Employer->save();
494 493
495 return $Code_user; 494 return $Code_user;
496 } 495 }
497 } 496 }
498 497
499 // Отправка сообщения от работодателя 498 // Отправка сообщения от работодателя
500 public function send_message(MessagesRequiest $request) { 499 public function send_message(MessagesRequiest $request) {
501 $params = $request->all(); 500 $params = $request->all();
502 501
503 $user1 = $params['user_id']; 502 $user1 = $params['user_id'];
504 $user2 = $params['to_user_id']; 503 $user2 = $params['to_user_id'];
505 504
506 if ($request->has('file')) { 505 if ($request->has('file')) {
507 $params['file'] = $request->file('file')->store("messages", 'public'); 506 $params['file'] = $request->file('file')->store("messages", 'public');
508 } 507 }
509 Message::create($params); 508 Message::create($params);
510 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]); 509 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
511 } 510 }
512 511
513 public function test123(Request $request) { 512 public function test123(Request $request) {
514 $params = $request->all(); 513 $params = $request->all();
515 $user1 = $params['user_id']; 514 $user1 = $params['user_id'];
516 $user2 = $params['to_user_id']; 515 $user2 = $params['to_user_id'];
517 516
518 $rules = [ 517 $rules = [
519 'text' => 'nullable|required_without:file|min:1|max:150000', 518 'text' => 'nullable|required_without:file|min:1|max:150000',
520 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000' 519 'file' => 'nullable|file|mimes:doc,docx,xlsx,csv,txt,xlx,xls,pdf|max:150000'
521 ]; 520 ];
522 $messages = [ 521 $messages = [
523 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен', 522 'required_without' => 'Поле «:attribute» обязательно, если файл не прикреплен',
524 'min' => [ 523 'min' => [
525 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 524 'string' => 'Поле «:attribute» должно быть не меньше :min символов',
526 'integer' => 'Поле «:attribute» должно быть :min или больше', 525 'integer' => 'Поле «:attribute» должно быть :min или больше',
527 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' 526 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт'
528 ], 527 ],
529 'max' => [ 528 'max' => [
530 'string' => 'Поле «:attribute» должно быть не больше :max символов', 529 'string' => 'Поле «:attribute» должно быть не больше :max символов',
531 'integer' => 'Поле «:attribute» должно быть :max или меньше', 530 'integer' => 'Поле «:attribute» должно быть :max или меньше',
532 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' 531 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт'
533 ] 532 ]
534 ]; 533 ];
535 534
536 $validator = Validator::make($request->all(), $rules, $messages); 535 $validator = Validator::make($request->all(), $rules, $messages);
537 536
538 if ($validator->fails()) { 537 if ($validator->fails()) {
539 return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator); 538 return redirect()->route('cabinet.messages', ['type_message' => 'input'])->withErrors($validator);
540 } 539 }
541 540
542 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages'); 541 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
543 return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]); 542 return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]);
544 543
545 } 544 }
546 545
547 //Избранные люди 546 //Избранные люди
548 public function favorites(Request $request) 547 public function favorites(Request $request)
549 { 548 {
550 $likedWorkersIds = Like_worker::query() 549 $likedWorkersIds = Like_worker::query()
551 ->where('user_id', Auth::user()->id) 550 ->where('user_id', Auth::user()->id)
552 ->get() 551 ->get()
553 ->pluck('code_record') 552 ->pluck('code_record')
554 ->toArray(); 553 ->toArray();
555 554
556 $workerBuilder = Worker::query() 555 $workerBuilder = Worker::query()
557 ->whereIn('id', $likedWorkersIds); 556 ->whereIn('id', $likedWorkersIds);
558 557
559 if (($request->has('search')) && (!empty($request->get('search')))) { 558 if (($request->has('search')) && (!empty($request->get('search')))) {
560 $search = $request->get('search'); 559 $search = $request->get('search');
561 560
562 $workerBuilder->whereHas('users', function (Builder $query) use ($search) { 561 $workerBuilder->whereHas('users', function (Builder $query) use ($search) {
563 $query->where('surname', 'LIKE', "%$search%") 562 $query->where('surname', 'LIKE', "%$search%")
564 ->orWhere('name_man', 'LIKE', "%$search%") 563 ->orWhere('name_man', 'LIKE', "%$search%")
565 ->orWhere('surname2', 'LIKE', "%$search%"); 564 ->orWhere('surname2', 'LIKE', "%$search%");
566 }); 565 });
567 } 566 }
568 567
569 $Workers = $workerBuilder->get(); 568 $Workers = $workerBuilder->get();
570 569
571 return view('employers.favorite', compact('Workers')); 570 return view('employers.favorite', compact('Workers'));
572 } 571 }
573 572
574 // База данных 573 // База данных
575 public function bd(Request $request) { 574 public function bd(Request $request) {
576 if (!Auth::user()->show_database) { 575 if (!Auth::user()->show_database) {
577 return redirect()->route('employer.employer_info'); 576 return redirect()->route('employer.employer_info');
578 } 577 }
579 578
580 $users = User_Model::query()->with('workers')->with('jobtitles'); 579 $users = User_Model::query()->with('workers')->with('jobtitles');
581 580
582 if ($request->has('search')) { 581 if ($request->has('search')) {
583 $find_key = $request->get('search'); 582 $find_key = $request->get('search');
584 $users = $users->where('name', 'LIKE', "%$find_key%") 583 $users = $users->where('name', 'LIKE', "%$find_key%")
585 ->orWhere('surname', 'LIKE', "%$find_key%") 584 ->orWhere('surname', 'LIKE', "%$find_key%")
586 ->orWhere('name_man', 'LIKE', "%$find_key%") 585 ->orWhere('name_man', 'LIKE', "%$find_key%")
587 ->orWhere('email', 'LIKE', "%$find_key%") 586 ->orWhere('email', 'LIKE', "%$find_key%")
588 ->orWhere('telephone', 'LIKE', "%$find_key%"); 587 ->orWhere('telephone', 'LIKE', "%$find_key%");
589 } 588 }
590 $count_users = $users->count(); 589 $count_users = $users->count();
591 590
592 // Данные 591 // Данные
593 $users = $users 592 $users = $users
594 ->Baseuser() 593 ->Baseuser()
595 ->orderByDesc('created_at') 594 ->orderByDesc('created_at')
596 ->paginate(10); 595 ->paginate(10);
597 596
598 $export_options = DbExportColumns::toArray(); 597 $export_options = DbExportColumns::toArray();
599 598
600 $jobs_titles = Job_title::select('id', 'name') 599 $jobs_titles = Job_title::select('id', 'name')
601 ->where('is_remove', '=', 0) 600 ->where('is_remove', '=', 0)
602 ->where('is_bd', '=', 2) 601 ->where('is_bd', '=', 2)
603 ->orderByDesc('sort') 602 ->orderByDesc('sort')
604 ->orderBy('name', 'asc') 603 ->orderBy('name', 'asc')
605 ->get() 604 ->get()
606 ->toArray() 605 ->toArray()
607 ; 606 ;
608 607
609 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles')); 608 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles'));
610 } 609 }
611 610
612 //Настройка уведомлений 611 //Настройка уведомлений
613 public function subscribe() { 612 public function subscribe() {
614 613
615 $user=Auth::user(); 614 $user=Auth::user();
616 615
617 return view('employers.subcribe',compact('user')); 616 return view('employers.subcribe',compact('user'));
618 } 617 }
619 618
620 //Установка уведомлений сохранение 619 //Установка уведомлений сохранение
621 public function save_subscribe(Request $request) { 620 public function save_subscribe(Request $request) {
622 621
623 $msg = $request->validate([ 622 $msg = $request->validate([
624 'email' => 'required|email|min:5|max:255', 623 'email' => 'required|email|min:5|max:255',
625 ]); 624 ]);
626 $user= Auth::user(); 625 $user= Auth::user();
627 626
628 User_Model::updateOrCreate( 627 User_Model::updateOrCreate(
629 ['id' => $user->id], 628 ['id' => $user->id],
630 ['subscribe_email' => $request->email, 629 ['subscribe_email' => $request->email,
631 'subscribe' => request()->has('email_msg') && request('email_msg') === 'on' ? 1 : 0 630 'subscribe' => request()->has('email_msg') && request('email_msg') === 'on' ? 1 : 0
632 ] 631 ]
633 ); 632 );
634 return redirect()->route('employer.subscribe')->with('success', 'Ваши изменения успешно сохранены'); 633 return redirect()->route('employer.subscribe')->with('success', 'Ваши изменения успешно сохранены');
635 } 634 }
636 //Сбросить форму с паролем 635 //Сбросить форму с паролем
637 public function password_reset() { 636 public function password_reset() {
638 $email = Auth()->user()->email; 637 $email = Auth()->user()->email;
639 return view('employers.password-reset', compact('email')); 638 return view('employers.password-reset', compact('email'));
640 } 639 }
641 640
642 //Обновление пароля 641 //Обновление пароля
643 public function new_password(Request $request) { 642 public function new_password(Request $request) {
644 $use = Auth()->user(); 643 $use = Auth()->user();
645 $request->validate([ 644 $request->validate([
646 'password' => 'required|string', 645 'password' => 'required|string',
647 'new_password' => 'required|string', 646 'new_password' => 'required|string',
648 'new_password2' => 'required|string' 647 'new_password2' => 'required|string'
649 ]); 648 ]);
650 649
651 if ($request->get('new_password') == $request->get('new_password2')) 650 if ($request->get('new_password') == $request->get('new_password2'))
652 if ($request->get('password') !== $request->get('new_password')) { 651 if ($request->get('password') !== $request->get('new_password')) {
653 $credentials = $request->only('email', 'password'); 652 $credentials = $request->only('email', 'password');
654 if (Auth::attempt($credentials)) { 653 if (Auth::attempt($credentials)) {
655 654
656 if (!is_null($use->email_verified_at)){ 655 if (!is_null($use->email_verified_at)){
657 656
658 $user_data = User_Model::find($use->id); 657 $user_data = User_Model::find($use->id);
659 $user_data->update([ 658 $user_data->update([
660 'password' => Hash::make($request->get('new_password')), 659 'password' => Hash::make($request->get('new_password')),
661 'pubpassword' => base64_encode($request->get('new_password')), 660 'pubpassword' => base64_encode($request->get('new_password')),
662 ]); 661 ]);
663 return redirect() 662 return redirect()
664 ->route('employer.password_reset') 663 ->route('employer.password_reset')
665 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 664 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
666 } 665 }
667 666
668 return redirect() 667 return redirect()
669 ->route('employer.password_reset') 668 ->route('employer.password_reset')
670 ->withError('Данная учетная запись не было верифицированна!'); 669 ->withError('Данная учетная запись не было верифицированна!');
671 } 670 }
672 } 671 }
673 672
674 return redirect() 673 return redirect()
675 ->route('employer.password_reset') 674 ->route('employer.password_reset')
676 ->withErrors('Не совпадение данных, обновите пароли!'); 675 ->withErrors('Не совпадение данных, обновите пароли!');
677 } 676 }
678 677
679 678
680 679
681 // Форма Удаление пипла 680 // Форма Удаление пипла
682 public function delete_people() { 681 public function delete_people() {
683 $login = Auth()->user()->email; 682 $login = Auth()->user()->email;
684 return view('employers.delete_people', compact('login')); 683 return view('employers.delete_people', compact('login'));
685 } 684 }
686 685
687 // Удаление аккаунта 686 // Удаление аккаунта
688 public function action_delete_user(Request $request) { 687 public function action_delete_user(Request $request) {
689 $Answer = $request->all(); 688 $Answer = $request->all();
690 $user_id = Auth()->user()->id; 689 $user_id = Auth()->user()->id;
691 $request->validate([ 690 $request->validate([
692 'password' => 'required|string', 691 'password' => 'required|string',
693 ]); 692 ]);
694 693
695 $credentials = $request->only('email', 'password'); 694 $credentials = $request->only('email', 'password');
696 if (Auth::attempt($credentials)) { 695 if (Auth::attempt($credentials)) {
697 Auth::logout(); 696 Auth::logout();
698 $it = User_Model::find($user_id); 697 $it = User_Model::find($user_id);
699 $it->delete(); 698 $it->delete();
700 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 699 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
701 } else { 700 } else {
702 return redirect()->route('employer.delete_people') 701 return redirect()->route('employer.delete_people')
703 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 702 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
704 } 703 }
705 } 704 }
706 705
707 public function ajax_delete_user(Request $request) { 706 public function ajax_delete_user(Request $request) {
708 $Answer = $request->all(); 707 $Answer = $request->all();
709 $user_id = Auth()->user()->id; 708 $user_id = Auth()->user()->id;
710 $request->validate([ 709 $request->validate([
711 'password' => 'required|string', 710 'password' => 'required|string',
712 ]); 711 ]);
713 $credentials = $request->only('email', 'password'); 712 $credentials = $request->only('email', 'password');
714 if (Auth::attempt($credentials)) { 713 if (Auth::attempt($credentials)) {
715 714
716 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт', 715 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт',
717 'email' => $request->get('email'), 716 'email' => $request->get('email'),
718 'password' => $request->get('password'))); 717 'password' => $request->get('password')));
719 } else { 718 } else {
720 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль')); 719 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль'));
721 } 720 }
722 } 721 }
723 722
724 // Рассылка сообщений 723 // Рассылка сообщений
725 public function send_all_messages() { 724 public function send_all_messages() {
726 $id = Auth()->user()->id; 725 $id = Auth()->user()->id;
727 $sending = Employer::query()->where('user_id', '=', "$id")->first(); 726 $sending = Employer::query()->where('user_id', '=', "$id")->first();
728 727
729 $job_titles = Job_title::query() 728 $job_titles = Job_title::query()
730 ->where('is_remove', '=', 0) 729 ->where('is_remove', '=', 0)
731 ->where('is_bd', '=', 1) 730 ->where('is_bd', '=', 1)
732 ->orderByDesc('sort') 731 ->orderByDesc('sort')
733 ->get(); 732 ->get();
734 733
735 if ($sending->sending_is) 734 if ($sending->sending_is)
736 return view('employers.send_all', compact('job_titles')); 735 return view('employers.send_all', compact('job_titles'));
737 else 736 else
738 return view('employers.send_all_danger'); 737 return view('employers.send_all_danger');
739 } 738 }
740 739
741 // Отправка сообщений для информации 740 // Отправка сообщений для информации
742 public function send_all_post(Request $request) { 741 public function send_all_post(Request $request) {
743 $data = $request->all(); 742 $data = $request->all();
744 $data['user'] = Auth()->user(); 743 $data['user'] = Auth()->user();
745 744
746 $id = MessagesRequests::create([ 745 $id = MessagesRequests::create([
747 'user_id' => $data['user']->id, 746 'user_id' => $data['user']->id,
748 'job_titles' => isset($data['job_title_ids']) ? json_encode($data['job_title_ids']) : null, 747 'job_titles' => isset($data['job_title_ids']) ? json_encode($data['job_title_ids']) : null,
749 'text' => $data['message_text'], 748 'text' => $data['message_text'],
750 ]); 749 ]);
751 750
752 try { 751 try {
753 if (!empty($id)) { 752 if (!empty($id)) {
754 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data)); 753 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data));
755 } 754 }
756 } catch (Throwable $e) { 755 } catch (Throwable $e) {
757 Log::error($e); 756 Log::error($e);
758 return redirect()->route('employer.send_all_messages')->with('error', 'Ошибка почтового сервера, пожалуйста, повторите рассылку позднее'); 757 return redirect()->route('employer.send_all_messages')->with('error', 'Ошибка почтового сервера, пожалуйста, повторите рассылку позднее');
759 } 758 }
760 759
761 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.'); 760 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.');
762 } 761 }
763 762
764 // База резюме 763 // База резюме
765 public function bd_tupe(Request $request) { 764 public function bd_tupe(Request $request) {
766 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get(); 765 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get();
767 766
768 return view('employers.bd_tupe', compact('Resume')); 767 return view('employers.bd_tupe', compact('Resume'));
769 } 768 }
770 769
771 ////////////////////////////////////////////////////////////////// 770 //////////////////////////////////////////////////////////////////
772 // Отправил сообщение 771 // Отправил сообщение
773 ////////////////////////////////////////////////////////////////// 772 //////////////////////////////////////////////////////////////////
774 public function new_message(Request $request) 773 public function new_message(Request $request)
775 { 774 {
776 $params = $request->all(); 775 $params = $request->all();
777 776
778 $id = $params['_user_id']; 777 $id = $params['_user_id'];
779 $message_params = [ 778 $message_params = [
780 'title' => $params['title'], 779 'title' => $params['title'],
781 'text' => $params['text'], 780 'text' => $params['text'],
782 'ad_employer_id' => $params['_vacancy'], 781 'ad_employer_id' => $params['_vacancy'],
783 'flag_new' => 1 782 'flag_new' => 1
784 ]; 783 ];
785 784
786 $message = Message::add_message( 785 $message = Message::add_message(
787 $request, 786 $request,
788 $params['_user_id'], 787 $params['_user_id'],
789 $params['_to_user_id'], 788 $params['_to_user_id'],
790 $message_params, 789 $message_params,
791 file_store_path: "worker/$id" 790 file_store_path: "worker/$id"
792 ); 791 );
793 792
794 return redirect()->route('employer.dialog', ['chat' => $message->chat_id_to]); 793 return redirect()->route('employer.dialog', ['chat' => $message->chat_id_to]);
795 } 794 }
796 795
797 // Восстановление пароля 796 // Восстановление пароля
798 public function repair_password(Request $request) { 797 public function repair_password(Request $request) {
799 $params = $request->get('email'); 798 $params = $request->get('email');
800 } 799 }
801 800
802 // Избранные люди на корабль 801 // Избранные люди на корабль
803 public function selected_people(Request $request) { 802 public function selected_people(Request $request) {
804 $id = $request->get('id'); 803 $id = $request->get('id');
805 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 804 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
806 where('is_remove', '=', '0')-> 805 where('is_remove', '=', '0')->
807 where('is_bd', '=', '0')-> 806 where('is_bd', '=', '0')->
808 where('position_id', $id)-> 807 where('position_id', $id)->
809 get(); 808 get();
810 return view('favorite_people', compact('favorite_people')); 809 return view('favorite_people', compact('favorite_people'));
811 } 810 }
812 811
813 /** 812 /**
814 * @throws JsonException 813 * @throws JsonException
815 */ 814 */
816 public function vacancyAutoLiftForm(): View|RedirectResponse 815 public function vacancyAutoLiftForm(): View|RedirectResponse
817 { 816 {
818 if (!Auth::user()->can_autolift) { 817 if (!Auth::user()->can_autolift) {
819 return redirect()->route('employer.employer_info'); 818 return redirect()->route('employer.employer_info');
820 } 819 }
821 820
822 $employer = Auth::user()->employers[0]; 821 $employer = Auth::user()->employers[0];
823 $vacancies = $employer 822 $vacancies = $employer
824 ->ads() 823 ->ads()
825 ->where('is_remove', 0) 824 ->where('is_remove', 0)
826 ->where('active_is', 1) 825 ->where('active_is', 1)
827 ->orderBy('id', 'desc') 826 ->orderBy('id', 'desc')
828 ->get(); 827 ->get();
829 828
830 $options = $employer->autoliftOptions ?? new EmployerAutoliftOption(); 829 $options = $employer->autoliftOptions ?? new EmployerAutoliftOption();
831 830
832 $leftDays = 0; 831 $leftDays = 0;
833 832
834 if ($options->days_repeat) { 833 if ($options->days_repeat) {
835 $leftDays = $options->days_repeat - now()->diffInDays(Carbon::parse($options->created_at)); 834 $leftDays = $options->days_repeat - now()->diffInDays(Carbon::parse($options->created_at));
836 } 835 }
837 836
838 837
839 return view('employers.vacancy_autolift', compact('vacancies', 'options', 'leftDays')); 838 return view('employers.vacancy_autolift', compact('vacancies', 'options', 'leftDays'));
840 } 839 }
841 840
842 /** 841 /**
843 * @throws JsonException 842 * @throws JsonException
844 */ 843 */
845 public function vacancyAutoLiftSave(Request $request) 844 public function vacancyAutoLiftSave(Request $request)
846 { 845 {
847 $employer = Auth::user()->employers[0]; 846 $employer = Auth::user()->employers[0];
848 847
849 $employer->autoliftOptions()->updateOrCreate( 848 $employer->autoliftOptions()->updateOrCreate(
850 [ 849 [
851 'employer_id' => $employer->id, 850 'employer_id' => $employer->id,
852 ], 851 ],
853 [ 852 [
854 'is_enabled' => $request->get('is_enabled') === 'true', 853 'is_enabled' => $request->get('is_enabled') === 'true',
855 'times_per_day' => $request->get('times_per_day'), 854 'times_per_day' => $request->get('times_per_day'),
856 'days_repeat' => $request->get('days_repeat'), 855 'days_repeat' => $request->get('days_repeat'),
857 'time_send_first' => $request->get('time_send_first'), 856 'time_send_first' => $request->get('time_send_first'),
858 'time_send_second' => $request->get('time_send_second'), 857 'time_send_second' => $request->get('time_send_second'),
859 'time_send_third' => $request->get('time_send_third'), 858 'time_send_third' => $request->get('time_send_third'),
860 'time_send_tg' => $request->get('time_send_tg'), 859 'time_send_tg' => $request->get('time_send_tg'),
861 ] 860 ]
862 ); 861 );
863 862
864 foreach ($request->get('vacancies') as $vacancy) { 863 foreach ($request->get('vacancies') as $vacancy) {
865 $data = [ 864 $data = [
866 'autolift_site' => $vacancy['autolift_site'] === 'true', 865 'autolift_site' => $vacancy['autolift_site'] === 'true',
867 'autosend_tg' => $vacancy['autosend_tg'] === 'true', 866 'autosend_tg' => $vacancy['autosend_tg'] === 'true',
868 ]; 867 ];
869 868
870 $adEmployer = Ad_employer::query()->find($vacancy['id']); 869 $adEmployer = Ad_employer::query()->find($vacancy['id']);
871 870
872 if ($vacancy['autolift_site'] === 'true' && !$adEmployer->autolift_site) { 871 if ($vacancy['autolift_site'] === 'true' && !$adEmployer->autolift_site) {
873 $data['updated_at'] = now(); 872 $data['updated_at'] = now();
874 } 873 }
875 874
876 DB::table('ad_employers')->where('id', $vacancy['id']) 875 DB::table('ad_employers')->where('id', $vacancy['id'])
877 ->update($data); 876 ->update($data);
878 } 877 }
879 878
880 return response(['success' => true]); 879 return response(['success' => true]);
881 } 880 }
882 881
883 public function autoresponder() 882 public function autoresponder()
884 { 883 {
885 $user = Auth::user(); 884 $user = Auth::user();
886 return view('employers.autoresponder', compact('user')); 885 return view('employers.autoresponder', compact('user'));
887 } 886 }
888 887
889 public function autoresponderSave(Request $request): RedirectResponse 888 public function autoresponderSave(Request $request): RedirectResponse
890 { 889 {
891 $user = Auth::user(); 890 $user = Auth::user();
892 $user->autoresponder = $request->get('autoresponder', false) === 'on'; 891 $user->autoresponder = $request->get('autoresponder', false) === 'on';
893 $user->autoresponder_message = $request->get('autoresponder_message'); 892 $user->autoresponder_message = $request->get('autoresponder_message');
894 $user->save(); 893 $user->save();
895 894
896 return redirect(route('employer.autoresponder')); 895 return redirect(route('employer.autoresponder'));
897 } 896 }
898 } 897 }
899 898