Commit d44b9332decd01ce0d0bb9dc1aee89f1c1244ca5

Authored by Hayk Nazaryan
1 parent bbaa986c09
Exists in master

vacancy update and create popups

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()->back()->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 $users = User_Model::query()->with('workers')->with('jobtitles'); 569 $users = User_Model::query()->with('workers')->with('jobtitles');
570 570
571 if ($request->has('search')) { 571 if ($request->has('search')) {
572 $find_key = $request->get('search'); 572 $find_key = $request->get('search');
573 $users = $users->where('name', 'LIKE', "%$find_key%") 573 $users = $users->where('name', 'LIKE', "%$find_key%")
574 ->orWhere('surname', 'LIKE', "%$find_key%") 574 ->orWhere('surname', 'LIKE', "%$find_key%")
575 ->orWhere('name_man', 'LIKE', "%$find_key%") 575 ->orWhere('name_man', 'LIKE', "%$find_key%")
576 ->orWhere('email', 'LIKE', "%$find_key%") 576 ->orWhere('email', 'LIKE', "%$find_key%")
577 ->orWhere('telephone', 'LIKE', "%$find_key%"); 577 ->orWhere('telephone', 'LIKE', "%$find_key%");
578 } 578 }
579 579
580 // Данные 580 // Данные
581 $users = $users 581 $users = $users
582 ->Baseuser() 582 ->Baseuser()
583 ->orderByDesc(Worker::select('created_at') 583 ->orderByDesc(Worker::select('created_at')
584 ->whereColumn('workers.user_id', 'users.id')); 584 ->whereColumn('workers.user_id', 'users.id'));
585 $count_users = $users->count(); 585 $count_users = $users->count();
586 $users = $users->paginate(10); 586 $users = $users->paginate(10);
587 587
588 $export_options = DbExportColumns::toArray(); 588 $export_options = DbExportColumns::toArray();
589 589
590 $jobs_titles = Job_title::select('id', 'name') 590 $jobs_titles = Job_title::select('id', 'name')
591 ->where('is_remove', '=', 0) 591 ->where('is_remove', '=', 0)
592 ->where('is_bd', '=', 2) 592 ->where('is_bd', '=', 2)
593 ->orderByDesc('sort') 593 ->orderByDesc('sort')
594 ->orderBy('name', 'asc') 594 ->orderBy('name', 'asc')
595 ->get() 595 ->get()
596 ->toArray() 596 ->toArray()
597 ; 597 ;
598 598
599 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles')); 599 return view('employers.bd', compact('users', 'count_users', 'export_options', 'jobs_titles'));
600 } 600 }
601 601
602 //Настройка уведомлений 602 //Настройка уведомлений
603 public function subscribe() { 603 public function subscribe() {
604 return view('employers.subcribe'); 604 return view('employers.subcribe');
605 } 605 }
606 606
607 //Установка уведомлений сохранение 607 //Установка уведомлений сохранение
608 public function save_subscribe(Request $request) { 608 public function save_subscribe(Request $request) {
609 dd($request->all()); 609 dd($request->all());
610 $msg = $request->validate([ 610 $msg = $request->validate([
611 'subscribe_email' => 'required|email|min:5|max:255', 611 'subscribe_email' => 'required|email|min:5|max:255',
612 ]); 612 ]);
613 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку'); 613 return redirect()->route('employer.subscribe')->with('Вы успешно подписались на рассылку');
614 } 614 }
615 615
616 //Сбросить форму с паролем 616 //Сбросить форму с паролем
617 public function password_reset() { 617 public function password_reset() {
618 $email = Auth()->user()->email; 618 $email = Auth()->user()->email;
619 return view('employers.password-reset', compact('email')); 619 return view('employers.password-reset', compact('email'));
620 } 620 }
621 621
622 //Обновление пароля 622 //Обновление пароля
623 public function new_password(Request $request) { 623 public function new_password(Request $request) {
624 $use = Auth()->user(); 624 $use = Auth()->user();
625 $request->validate([ 625 $request->validate([
626 'password' => 'required|string', 626 'password' => 'required|string',
627 'new_password' => 'required|string', 627 'new_password' => 'required|string',
628 'new_password2' => 'required|string' 628 'new_password2' => 'required|string'
629 ]); 629 ]);
630 630
631 if ($request->get('new_password') == $request->get('new_password2')) 631 if ($request->get('new_password') == $request->get('new_password2'))
632 if ($request->get('password') !== $request->get('new_password')) { 632 if ($request->get('password') !== $request->get('new_password')) {
633 $credentials = $request->only('email', 'password'); 633 $credentials = $request->only('email', 'password');
634 if (Auth::attempt($credentials)) { 634 if (Auth::attempt($credentials)) {
635 635
636 if (!is_null($use->email_verified_at)){ 636 if (!is_null($use->email_verified_at)){
637 637
638 $user_data = User_Model::find($use->id); 638 $user_data = User_Model::find($use->id);
639 $user_data->update([ 639 $user_data->update([
640 'password' => Hash::make($request->get('new_password')), 640 'password' => Hash::make($request->get('new_password')),
641 'pubpassword' => base64_encode($request->get('new_password')), 641 'pubpassword' => base64_encode($request->get('new_password')),
642 ]); 642 ]);
643 return redirect() 643 return redirect()
644 ->route('employer.password_reset') 644 ->route('employer.password_reset')
645 ->with('success', 'Поздравляю! Вы обновили свой пароль!'); 645 ->with('success', 'Поздравляю! Вы обновили свой пароль!');
646 } 646 }
647 647
648 return redirect() 648 return redirect()
649 ->route('employer.password_reset') 649 ->route('employer.password_reset')
650 ->withError('Данная учетная запись не было верифицированна!'); 650 ->withError('Данная учетная запись не было верифицированна!');
651 } 651 }
652 } 652 }
653 653
654 return redirect() 654 return redirect()
655 ->route('employer.password_reset') 655 ->route('employer.password_reset')
656 ->withErrors('Не совпадение данных, обновите пароли!'); 656 ->withErrors('Не совпадение данных, обновите пароли!');
657 } 657 }
658 658
659 659
660 660
661 // Форма Удаление пипла 661 // Форма Удаление пипла
662 public function delete_people() { 662 public function delete_people() {
663 $login = Auth()->user()->email; 663 $login = Auth()->user()->email;
664 return view('employers.delete_people', compact('login')); 664 return view('employers.delete_people', compact('login'));
665 } 665 }
666 666
667 // Удаление аккаунта 667 // Удаление аккаунта
668 public function action_delete_user(Request $request) { 668 public function action_delete_user(Request $request) {
669 $Answer = $request->all(); 669 $Answer = $request->all();
670 $user_id = Auth()->user()->id; 670 $user_id = Auth()->user()->id;
671 $request->validate([ 671 $request->validate([
672 'password' => 'required|string', 672 'password' => 'required|string',
673 ]); 673 ]);
674 674
675 $credentials = $request->only('email', 'password'); 675 $credentials = $request->only('email', 'password');
676 if (Auth::attempt($credentials)) { 676 if (Auth::attempt($credentials)) {
677 Auth::logout(); 677 Auth::logout();
678 $it = User_Model::find($user_id); 678 $it = User_Model::find($user_id);
679 $it->delete(); 679 $it->delete();
680 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт'); 680 return redirect()->route('index')->with('success', 'Вы успешно удалили свой аккаунт');
681 } else { 681 } else {
682 return redirect()->route('employer.delete_people') 682 return redirect()->route('employer.delete_people')
683 ->withErrors( 'Неверный пароль! Нужен корректный пароль'); 683 ->withErrors( 'Неверный пароль! Нужен корректный пароль');
684 } 684 }
685 } 685 }
686 686
687 public function ajax_delete_user(Request $request) { 687 public function ajax_delete_user(Request $request) {
688 $Answer = $request->all(); 688 $Answer = $request->all();
689 $user_id = Auth()->user()->id; 689 $user_id = Auth()->user()->id;
690 $request->validate([ 690 $request->validate([
691 'password' => 'required|string', 691 'password' => 'required|string',
692 ]); 692 ]);
693 $credentials = $request->only('email', 'password'); 693 $credentials = $request->only('email', 'password');
694 if (Auth::attempt($credentials)) { 694 if (Auth::attempt($credentials)) {
695 695
696 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт', 696 return json_encode(Array('SUCCESS' => 'Вы успешно удалили свой аккаунт',
697 'email' => $request->get('email'), 697 'email' => $request->get('email'),
698 'password' => $request->get('password'))); 698 'password' => $request->get('password')));
699 } else { 699 } else {
700 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль')); 700 return json_encode(Array('ERROR' => 'Неверный пароль! Нужен корректный пароль'));
701 } 701 }
702 } 702 }
703 703
704 // Рассылка сообщений 704 // Рассылка сообщений
705 public function send_all_messages() { 705 public function send_all_messages() {
706 $id = Auth()->user()->id; 706 $id = Auth()->user()->id;
707 $sending = Employer::query()->where('user_id', '=', "$id")->first(); 707 $sending = Employer::query()->where('user_id', '=', "$id")->first();
708 708
709 $job_titles = Job_title::query() 709 $job_titles = Job_title::query()
710 ->where('is_remove', '=', 0) 710 ->where('is_remove', '=', 0)
711 ->where('is_bd', '=', 1) 711 ->where('is_bd', '=', 1)
712 ->orderByDesc('sort') 712 ->orderByDesc('sort')
713 ->get(); 713 ->get();
714 714
715 if ($sending->sending_is) 715 if ($sending->sending_is)
716 return view('employers.send_all', compact('job_titles')); 716 return view('employers.send_all', compact('job_titles'));
717 else 717 else
718 return view('employers.send_all_danger'); 718 return view('employers.send_all_danger');
719 } 719 }
720 720
721 // Отправка сообщений для информации 721 // Отправка сообщений для информации
722 public function send_all_post(Request $request) { 722 public function send_all_post(Request $request) {
723 $data = $request->all(); 723 $data = $request->all();
724 $data['user'] = Auth()->user(); 724 $data['user'] = Auth()->user();
725 725
726 $id = MessagesRequests::create([ 726 $id = MessagesRequests::create([
727 'user_id' => $data['user']->id, 727 'user_id' => $data['user']->id,
728 'job_titles' => isset($data['job_title_ids']) ? json_encode($data['job_title_ids']) : null, 728 'job_titles' => isset($data['job_title_ids']) ? json_encode($data['job_title_ids']) : null,
729 'text' => $data['message_text'], 729 'text' => $data['message_text'],
730 ]); 730 ]);
731 731
732 try { 732 try {
733 if (!empty($id)) { 733 if (!empty($id)) {
734 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data)); 734 Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data));
735 } 735 }
736 } catch (Throwable $e) { 736 } catch (Throwable $e) {
737 Log::error($e); 737 Log::error($e);
738 return redirect()->route('employer.send_all_messages')->with('error', 'Ошибка почтового сервера, пожалуйста, повторите рассылку позднее'); 738 return redirect()->route('employer.send_all_messages')->with('error', 'Ошибка почтового сервера, пожалуйста, повторите рассылку позднее');
739 } 739 }
740 740
741 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.'); 741 return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.');
742 } 742 }
743 743
744 // База резюме 744 // База резюме
745 public function bd_tupe(Request $request) { 745 public function bd_tupe(Request $request) {
746 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get(); 746 $Resume = User_Model::query()->with('workers')->where('is_bd', '=', '1')->get();
747 747
748 return view('employers.bd_tupe', compact('Resume')); 748 return view('employers.bd_tupe', compact('Resume'));
749 } 749 }
750 750
751 ////////////////////////////////////////////////////////////////// 751 //////////////////////////////////////////////////////////////////
752 // Отправил сообщение 752 // Отправил сообщение
753 ////////////////////////////////////////////////////////////////// 753 //////////////////////////////////////////////////////////////////
754 public function new_message(Request $request) 754 public function new_message(Request $request)
755 { 755 {
756 $params = $request->all(); 756 $params = $request->all();
757 757
758 $id = $params['_user_id']; 758 $id = $params['_user_id'];
759 $message_params = [ 759 $message_params = [
760 'title' => $params['title'], 760 'title' => $params['title'],
761 'text' => $params['text'], 761 'text' => $params['text'],
762 'ad_employer_id' => $params['_vacancy'], 762 'ad_employer_id' => $params['_vacancy'],
763 'flag_new' => 1 763 'flag_new' => 1
764 ]; 764 ];
765 765
766 $message = Message::add_message( 766 $message = Message::add_message(
767 $request, 767 $request,
768 $params['_user_id'], 768 $params['_user_id'],
769 $params['_to_user_id'], 769 $params['_to_user_id'],
770 $message_params, 770 $message_params,
771 file_store_path: "worker/$id" 771 file_store_path: "worker/$id"
772 ); 772 );
773 773
774 return redirect()->route('employer.dialog', ['chat' => $message->chat_id_to]); 774 return redirect()->route('employer.dialog', ['chat' => $message->chat_id_to]);
775 } 775 }
776 776
777 // Восстановление пароля 777 // Восстановление пароля
778 public function repair_password(Request $request) { 778 public function repair_password(Request $request) {
779 $params = $request->get('email'); 779 $params = $request->get('email');
780 } 780 }
781 781
782 // Избранные люди на корабль 782 // Избранные люди на корабль
783 public function selected_people(Request $request) { 783 public function selected_people(Request $request) {
784 $id = $request->get('id'); 784 $id = $request->get('id');
785 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')-> 785 $favorite_people = Job_title::query()->orderByDesc('sort')->OrderBy('name')->
786 where('is_remove', '=', '0')-> 786 where('is_remove', '=', '0')->
787 where('is_bd', '=', '0')-> 787 where('is_bd', '=', '0')->
788 where('position_id', $id)-> 788 where('position_id', $id)->
789 get(); 789 get();
790 return view('favorite_people', compact('favorite_people')); 790 return view('favorite_people', compact('favorite_people'));
791 } 791 }
792 792
793 /** 793 /**
794 * @throws JsonException 794 * @throws JsonException
795 */ 795 */
796 public function vacancyAutoLiftForm(): View 796 public function vacancyAutoLiftForm(): View
797 { 797 {
798 $employer = Auth::user()->employers[0]; 798 $employer = Auth::user()->employers[0];
799 $vacancies = $employer 799 $vacancies = $employer
800 ->ads() 800 ->ads()
801 ->where('is_remove', 0) 801 ->where('is_remove', 0)
802 ->where('active_is', 1) 802 ->where('active_is', 1)
803 ->get(); 803 ->get();
804 804
805 $options = $employer->autoliftOptions ?? new EmployerAutoliftOption(); 805 $options = $employer->autoliftOptions ?? new EmployerAutoliftOption();
806 806
807 $leftDays = 0; 807 $leftDays = 0;
808 808
809 if ($options->days_repeat) { 809 if ($options->days_repeat) {
810 $leftDays = $options->days_repeat - now()->diffInDays(Carbon::parse($options->created_at)); 810 $leftDays = $options->days_repeat - now()->diffInDays(Carbon::parse($options->created_at));
811 } 811 }
812 812
813 813
814 return view('employers.vacancy_autolift', compact('vacancies', 'options', 'leftDays')); 814 return view('employers.vacancy_autolift', compact('vacancies', 'options', 'leftDays'));
815 } 815 }
816 816
817 /** 817 /**
818 * @throws JsonException 818 * @throws JsonException
819 */ 819 */
820 public function vacancyAutoLiftSave(Request $request) 820 public function vacancyAutoLiftSave(Request $request)
821 { 821 {
822 $employer = Auth::user()->employers[0]; 822 $employer = Auth::user()->employers[0];
823 823
824 $employer->autoliftOptions()->updateOrCreate( 824 $employer->autoliftOptions()->updateOrCreate(
825 [ 825 [
826 'employer_id' => $employer->id, 826 'employer_id' => $employer->id,
827 ], 827 ],
828 [ 828 [
829 'is_enabled' => $request->get('is_enabled') === 'true', 829 'is_enabled' => $request->get('is_enabled') === 'true',
830 'times_per_day' => $request->get('times_per_day'), 830 'times_per_day' => $request->get('times_per_day'),
831 'days_repeat' => $request->get('days_repeat'), 831 'days_repeat' => $request->get('days_repeat'),
832 'time_send_first' => $request->get('time_send_first'), 832 'time_send_first' => $request->get('time_send_first'),
833 'time_send_second' => $request->get('time_send_second'), 833 'time_send_second' => $request->get('time_send_second'),
834 'time_send_third' => $request->get('time_send_third'), 834 'time_send_third' => $request->get('time_send_third'),
835 'time_send_tg' => $request->get('time_send_tg'), 835 'time_send_tg' => $request->get('time_send_tg'),
836 ] 836 ]
837 ); 837 );
838 838
839 foreach ($request->get('vacancies') as $vacancy) { 839 foreach ($request->get('vacancies') as $vacancy) {
840 Ad_employer::query() 840 Ad_employer::query()
841 ->where('id', $vacancy['id']) 841 ->where('id', $vacancy['id'])
842 ->update([ 842 ->update([
843 'autolift_site' => $vacancy['autolift_site'] === 'true', //they're arriving as strings 843 'autolift_site' => $vacancy['autolift_site'] === 'true', //they're arriving as strings
844 'autosend_tg' => $vacancy['autosend_tg'] === 'true', 844 'autosend_tg' => $vacancy['autosend_tg'] === 'true',
845 ]); 845 ]);
846 } 846 }
847 847
848 return response(['success' => true]); 848 return response(['success' => true]);
849 } 849 }
850 850
851 public function autoresponder() 851 public function autoresponder()
852 { 852 {
853 $user = Auth::user(); 853 $user = Auth::user();
854 return view('employers.autoresponder', compact('user')); 854 return view('employers.autoresponder', compact('user'));
855 } 855 }
856 856
857 public function autoresponderSave(Request $request): RedirectResponse 857 public function autoresponderSave(Request $request): RedirectResponse
858 { 858 {
859 $user = Auth::user(); 859 $user = Auth::user();
860 $user->autoresponder = $request->get('autoresponder', false) === 'on'; 860 $user->autoresponder = $request->get('autoresponder', false) === 'on';
861 $user->autoresponder_message = $request->get('autoresponder_message'); 861 $user->autoresponder_message = $request->get('autoresponder_message');
862 $user->save(); 862 $user->save();
863 863
864 return redirect(route('employer.autoresponder')); 864 return redirect(route('employer.autoresponder'));
865 } 865 }
866 } 866 }
867 867