Commit c51424e4b5fbf9b4e026b48a925fd63f0d001e5c

Authored by Hayk Nazaryan
1 parent 0cca95c684
Exists in master

vacancy update redirect to list

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