diff --git a/app/Console/Commands/DeleteExpiredAutoliftOptions.php b/app/Console/Commands/DeleteExpiredAutoliftOptions.php index 15d5b9d..095db12 100644 --- a/app/Console/Commands/DeleteExpiredAutoliftOptions.php +++ b/app/Console/Commands/DeleteExpiredAutoliftOptions.php @@ -3,6 +3,7 @@ namespace App\Console\Commands; use App\Models\EmployerAutoliftOption; +use App\Models\WorkerAutoliftOption; use Illuminate\Console\Command; class DeleteExpiredAutoliftOptions extends Command @@ -18,6 +19,11 @@ class DeleteExpiredAutoliftOptions extends Command ->update([ 'is_enabled' => false ]); + WorkerAutoliftOption::query() + ->whereRaw('`updated_at` < DATE_SUB(NOW(), INTERVAL `days_repeat` DAY)') + ->update([ + 'is_enabled' => false + ]); return Command::SUCCESS; } } diff --git a/app/Console/Commands/DispatchResumeLiftJobCommand.php b/app/Console/Commands/DispatchResumeLiftJobCommand.php new file mode 100644 index 0000000..9fdeb09 --- /dev/null +++ b/app/Console/Commands/DispatchResumeLiftJobCommand.php @@ -0,0 +1,41 @@ +timezone('Europe/Moscow')->format('H:i'); + + $employers = WorkerAutoliftOption::query() + ->where(function ($query) use ($now) { + $query->where('times_per_day', 1) + ->where('time_send_first', $now); + }) + ->orWhere(function ($query) use ($now) { + $query->where('times_per_day', 2) + ->where('time_send_first', $now) + ->where('time_send_second', $now); + }) + ->orWhere(function ($query) use ($now) { + $query->where('times_per_day', 3) + ->where('time_send_first', $now) + ->where('time_send_second', $now) + ->where('time_send_third', $now); + }) + ->get(); + + LiftVacancyJob::dispatch($employers->pluck('employer_id')->toArray()); + + return Command::SUCCESS; + } +} diff --git a/app/Console/Commands/DispatchVacancyLiftJobCommand.php b/app/Console/Commands/DispatchVacancyLiftJobCommand.php index 42e29ab..bc9b1eb 100644 --- a/app/Console/Commands/DispatchVacancyLiftJobCommand.php +++ b/app/Console/Commands/DispatchVacancyLiftJobCommand.php @@ -13,7 +13,7 @@ class DispatchVacancyLiftJobCommand extends Command public function handle() { - $now = now()->format('H:i'); + $now = now()->timezone('Europe/Moscow')->format('H:i'); $employers = EmployerAutoliftOption::query() ->where(function ($query) use ($now) { diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index bf18bbb..fbeaf6e 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -11,6 +11,7 @@ class Kernel extends ConsoleKernel { $schedule->command('vacancy:delete_expired')->dailyAt('00:00'); $schedule->command('vacancy:dispatch')->everyMinute(); + $schedule->command('resume:dispatch')->everyMinute(); } protected function commands() diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index e1fbc24..67ef335 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -811,6 +811,7 @@ class EmployerController extends Controller 'employer_id' => $employer->id, ], [ + 'is_enabled' => $request->get('is_enabled'), 'times_per_day' => $request->get('times_per_day'), 'days_repeat' => $request->get('days_repeat'), 'time_send_first' => $request->get('time_send_first'), @@ -834,17 +835,16 @@ class EmployerController extends Controller public function autoresponder() { - $employer = Auth::user()->employers[0]; - return view('employers.autoresponder', compact('employer')); + $user = Auth::user(); + return view('employers.autoresponder', compact('user')); } public function autoresponderSave(Request $request): RedirectResponse { - /** @var Employer $employer */ - $employer = Auth::user()->employers[0]; - $employer->autoresponder = $request->get('autoresponder', false) === 'on'; - $employer->autoresponder_message = $request->get('autoresponder_message'); - $employer->save(); + $user = Auth::user(); + $user->autoresponder = $request->get('autoresponder', false) === 'on'; + $user->autoresponder_message = $request->get('autoresponder_message'); + $user->save(); return redirect(route('employer.autoresponder')); } diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index 70d55d7..ad3f3be 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -11,6 +11,8 @@ use App\Models\Ad_employer; use App\Models\ad_response; use App\Models\Chat; use App\Models\Dop_info; +use App\Models\Employer; +use App\Models\EmployerAutoliftOption; use App\Models\infobloks; use App\Models\Job_title; use App\Models\Like_vacancy; @@ -24,10 +26,12 @@ use App\Models\Title_worker; use App\Models\User; use App\Models\User as User_Model; use App\Models\Worker; +use App\Models\WorkerAutoliftOption; use Barryvdh\DomPDF\Facade\Pdf; use Carbon\Carbon; use Illuminate\Auth\Events\Registered; use Illuminate\Database\Eloquent\Builder; +use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Illuminate\Pagination\LengthAwarePaginator; use Illuminate\Support\Facades\Auth; @@ -35,6 +39,8 @@ use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Hash; use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; +use Illuminate\View\View; +use JsonException; use PhpOffice\PhpSpreadsheet\Spreadsheet; use PhpOffice\PhpSpreadsheet\Writer\Xlsx; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -282,7 +288,8 @@ class WorkerController extends Controller $jobIds = $request->input('job_title_list', []); - $users = DB::select( + /* //query for mysql ver 8.0 or higher + $users = DB::select( "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` from users join workers on `users`.`id` = `workers`.`user_id` @@ -295,6 +302,17 @@ class WorkerController extends Controller '$[*]' COLUMNS (id INT PATH '$')) pw where pw.id = job_titles.id) )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') + );*/ + + $users = DB::select( + "select `job_titles`.`name`, `users`.`surname`, `users`.`name_man`, `users`.`surname2`, `users`.`email`, `users`.`telephone` + from users + join workers on `users`.`id` = `workers`.`user_id` + join `job_titles` + where `users`.`is_bd` = 1 + and (`workers`.`position_work` = `job_titles`.`id` + or `workers`.`positions_work` + )". ((!empty($jobIds)) ? 'and job_titles.id in ('. implode(',', $jobIds).')' : '') ); $users = collect($users); @@ -1053,5 +1071,59 @@ class WorkerController extends Controller $doc->delete(); return redirect()->route('worker.cabinet')->with('success', 'Вы успешно удалили запись!'); } + + public function autoresponder() + { + $user = Auth::user(); + return view('workers.autoresponder', compact('user')); + } + + public function autoresponderSave(Request $request): RedirectResponse + { + /** @var Employer $employer */ + $employer = Auth::user(); + $employer->autoresponder = $request->get('autoresponder', false) === 'on'; + $employer->autoresponder_message = $request->get('autoresponder_message'); + $employer->save(); + + return redirect(route('worker.autoresponder')); + } + /** + * @throws JsonException + */ + public function resumeAutoLiftForm(): View + { + $worker = Auth::user()->workers[0]; + + $options = $worker->autoliftOptions ?? new WorkerAutoliftOption(); + + return view('workers.resume_autolift', compact('worker', 'options')); + } + + /** + * @throws JsonException + */ + public function resumeAutoLiftSave(Request $request) + { + $worker = Auth::user()->workers[0]; + + $worker->autoliftOptions()->updateOrCreate( + [ + 'worker_id' => $worker->id, + ], + [ + 'is_enabled' => $request->get('is_enabled') === 'on', + 'times_per_day' => $request->get('times_per_day'), + 'days_repeat' => $request->get('days_repeat'), + 'time_send_first' => $request->get('time_send_first'), + 'time_send_second' => $request->get('time_send_second'), + 'time_send_third' => $request->get('time_send_third'), + 'time_send_tg' => $request->get('time_send_tg'), + 'autolift_site' => $request->get('autolift_site') === 'on', + ] + ); + + return response()->json(['success' => true]); + } } diff --git a/app/Jobs/LiftResumeJob.php b/app/Jobs/LiftResumeJob.php new file mode 100644 index 0000000..f4cb8eb --- /dev/null +++ b/app/Jobs/LiftResumeJob.php @@ -0,0 +1,32 @@ +workerIds = $workerIds; + } + + public function handle() + { + Worker::query() + ->whereIn('id', $this->workerIds) + ->update([ + 'updated_at' => now() + ]); + } +} diff --git a/app/Models/Employer.php b/app/Models/Employer.php index 1d23ef1..a78bab4 100644 --- a/app/Models/Employer.php +++ b/app/Models/Employer.php @@ -35,8 +35,6 @@ class Employer extends Model 'status_hidden', 'email_2', 'telephone_2', - 'autoresponder', - 'autoresponder_message', ]; /* diff --git a/app/Models/User.php b/app/Models/User.php index c5ed660..a49a67b 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -47,6 +47,8 @@ class User extends Authenticatable 'is_manager', 'subscribe_email', 'subscribe', + 'autoresponder', + 'autoresponder_message', ]; /** @@ -173,7 +175,7 @@ class User extends Authenticatable } if ($jobIds !== null && count($jobIds) > 0) { - return Job_title::whereIn('id', $jobIds)->first()->name; + return Job_title::whereIn('id', $jobIds)->first()?->name; } return null; } diff --git a/app/Models/Worker.php b/app/Models/Worker.php index 5f812c0..8d693df 100644 --- a/app/Models/Worker.php +++ b/app/Models/Worker.php @@ -136,4 +136,9 @@ class Worker extends Model $job_titles_ids = json_decode($this->attributes['positions_work'], true); return Job_title::whereIn('id', $job_titles_ids)->get(); } + + public function autoliftOptions() + { + return $this->hasOne(WorkerAutoliftOption::class); + } } diff --git a/app/Models/WorkerAutoliftOption.php b/app/Models/WorkerAutoliftOption.php new file mode 100644 index 0000000..5815d6c --- /dev/null +++ b/app/Models/WorkerAutoliftOption.php @@ -0,0 +1,37 @@ + $value === null ? 0 : 1 + ); + } + + public function worker(): BelongsTo + { + return $this->belongsTo(Worker::class); + } +} diff --git a/app/Observers/MessageObserver.php b/app/Observers/MessageObserver.php index b107298..c0f6813 100644 --- a/app/Observers/MessageObserver.php +++ b/app/Observers/MessageObserver.php @@ -5,25 +5,24 @@ namespace App\Observers; use App\Models\Chat; use App\Models\Employer; use App\Models\Message; +use App\Models\User; use Illuminate\Http\Request; class MessageObserver { public function created(Message $message): void { - /** @var Employer $employer */ - $employer = Employer::query() - ->where('user_id', $message->to_user_id) - ->first(); + /** @var User $user */ + $user = User::find($message->to_user_id); - if ($employer === null || !$employer->autoresponder) { + if ($user === null || !$user->autoresponder) { return; } $recentAutoresponderMessage = Message::query() ->where('user_id', $message->to_user_id) ->where('to_user_id', $message->user_id) - ->where('text', $employer->autoresponder_message) + ->where('text', $user->autoresponder_message) ->where('created_at', '>', now()->subDays(4)) ->orderBy('id', 'desc') ->first(); @@ -37,7 +36,7 @@ class MessageObserver user_id: $message->to_user_id, to_user_id: $message->user_id, message_params: [ - 'text' => $employer->autoresponder_message, + 'text' => $user->autoresponder_message, 'flag_new' => 1 ] ); diff --git a/database/migrations/2024_10_25_120802_move_autoresponder_colomns.php b/database/migrations/2024_10_25_120802_move_autoresponder_colomns.php new file mode 100644 index 0000000..b53db94 --- /dev/null +++ b/database/migrations/2024_10_25_120802_move_autoresponder_colomns.php @@ -0,0 +1,36 @@ +dropColumn('autoresponder'); + $table->dropColumn('autoresponder_message'); + }); + + Schema::table('users', function (Blueprint $table) { + $table->boolean('autoresponder')->default(false); + $table->text('autoresponder_message')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // + } +}; diff --git a/database/migrations/2024_10_28_114521_create_worker_autolift_options_table.php b/database/migrations/2024_10_28_114521_create_worker_autolift_options_table.php new file mode 100644 index 0000000..882210a --- /dev/null +++ b/database/migrations/2024_10_28_114521_create_worker_autolift_options_table.php @@ -0,0 +1,40 @@ +id(); + $table->unsignedBigInteger('worker_id'); + $table->foreign('worker_id')->references('id')->on('workers')->onDelete('cascade'); + $table->boolean('autolift_site')->default(true); + $table->integer('times_per_day')->index()->default(1); + $table->integer('days_repeat')->default(1); + $table->string('time_send_first')->index(); + $table->string('time_send_second')->index()->nullable(); + $table->string('time_send_third')->index()->nullable(); + $table->boolean('is_enabled')->default(true); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('worker_autolift_options'); + } +}; diff --git a/public/js/script-vc.js b/public/js/script-vc.js index a1503a5..bd34071 100644 --- a/public/js/script-vc.js +++ b/public/js/script-vc.js @@ -130,7 +130,6 @@ let scripts = function () { toggle.addEventListener('change', () => { if (toggle.checked) { - toggle.disabled = true; prompts[0].classList.add('hidden'); prompts[1].classList.remove('hidden'); } else { diff --git a/resources/views/employers/autoresponder.blade.php b/resources/views/employers/autoresponder.blade.php index 5275646..0d8ec2a 100644 --- a/resources/views/employers/autoresponder.blade.php +++ b/resources/views/employers/autoresponder.blade.php @@ -21,14 +21,16 @@
В этом разделе вы сможете задать автоматический ответ на письма, поступающие в почтовый ящик.
+В этом разделе вы сможете задать автоматический ответ на письма, поступающие в + почтовый ящик.