Commit daf1507c4655cbfd74db83a146b52931162b4911

Authored by Hayk Nazaryan
1 parent 44e612f7e4
Exists in master

order vacancies on autolift

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