Commit ebedc593670c071424793bc14402aa7cd541c662

Authored by Hayk Nazaryan
Exists in master

Merge branch 'master' of http://gitlab.nologostudio.ru/alarionov/rekamore-su

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