Commit 1c1dedea990bf839e146a3431707cbec9a666d14

Authored by Hayk Nazaryan
1 parent b0574d0f76
Exists in master

fix update on autolift

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