Commit a67c9d7ef4a8e42af8fdcd3778dffb18791677a0

Authored by Сергей П
1 parent f0c09cba93
Exists in master

Массовая рассылка сообщений + правки от Марины

Showing 11 changed files with 171 additions and 122 deletions Side-by-side Diff

app/Http/Controllers/EmployerController.php
... ... @@ -10,6 +10,7 @@ use App\Http\Requests\MessagesRequiest;
10 10 use App\Http\Requests\VacancyRequestEdit;
11 11 use App\Mail\MailCreateEmployer;
12 12 use App\Mail\MailSotrudnichestvo;
  13 +use App\Mail\MassSendingMessages;
13 14 use App\Mail\SendAllMessages;
14 15 use App\Models\Ad_employer;
15 16 use App\Models\ad_response;
... ... @@ -21,6 +22,7 @@ use App\Models\Job_title;
21 22 use App\Models\Like_worker;
22 23 use App\Models\Message;
23 24 use App\Models\Worker;
  25 +use App\Models\MessagesRequests;
24 26 use Carbon\Carbon;
25 27 use Illuminate\Auth\Events\Registered;
26 28 use Illuminate\Database\Eloquent\Builder;
... ... @@ -736,8 +738,16 @@ class EmployerController extends Controller
736 738 public function send_all_messages() {
737 739 $id = Auth()->user()->id;
738 740 $sending = Employer::query()->where('user_id', '=', "$id")->first();
  741 +
  742 + $job_titles = Job_title::query()
  743 + ->where('is_remove', '=', 0)
  744 + ->where('is_bd', '=', 1)
  745 + ->orderByDesc('sort')
  746 + ->get()
  747 + ;
  748 +
739 749 if ($sending->sending_is)
740   - return view('employers.send_all');
  750 + return view('employers.send_all', compact('job_titles'));
741 751 else
742 752 return view('employers.send_all_danger');
743 753 }
... ... @@ -745,14 +755,25 @@ class EmployerController extends Controller
745 755 // Отправка сообщений для информации
746 756 public function send_all_post(Request $request) {
747 757 $data = $request->all();
  758 + $data['user'] = Auth()->user();
748 759  
749   - $emails = User_Model::query()->where('is_worker', '1')->get();
  760 + $id = MessagesRequests::create([
  761 + 'user_id' => Auth()->user()->id,
  762 + 'job_titles' => json_encode($data['job_title_ids']),
  763 + 'text' => $data['message_text'],
  764 + ]);
  765 +
  766 + if (!empty($id)){
  767 + Mail::to(env('EMAIL_ADMIN'))->send(new MassSendingMessages($data));
  768 + }
  769 +
  770 + /*$emails = User_Model::query()->where('is_worker', '1')->get();
750 771  
751 772 foreach ($emails as $e) {
752 773 Mail::to($e->email)->send(new SendAllMessages($data));
753   - }
  774 + }*/
754 775  
755   - return redirect()->route('employer.send_all_messages')->with('success', 'Письма были отправлены');
  776 + return redirect()->route('employer.send_all_messages')->with('success', 'Запрос на рассылку был успешно отправлен.');
756 777 }
757 778  
758 779 // База резюме
app/Mail/MassSendingMessages.php
... ... @@ -0,0 +1,44 @@
  1 +<?php
  2 +
  3 +namespace App\Mail;
  4 +
  5 +use App\Models\User;
  6 +use Illuminate\Bus\Queueable;
  7 +use Illuminate\Contracts\Queue\ShouldQueue;
  8 +use Illuminate\Mail\Mailable;
  9 +use Illuminate\Mail\Mailables\Address;
  10 +use Illuminate\Mail\Mailables\Content;
  11 +use Illuminate\Mail\Mailables\Envelope;
  12 +use Illuminate\Queue\SerializesModels;
  13 +
  14 +class MassSendingMessages extends Mailable
  15 +{
  16 + use Queueable, SerializesModels;
  17 +
  18 + protected $data;
  19 +
  20 + public function __construct($data)
  21 + {
  22 + $this->data = $data;
  23 + }
  24 +
  25 + public function envelope(): Envelope
  26 + {
  27 + return new Envelope(
  28 + subject: 'Запрос на рассылку сообщений',
  29 + );
  30 + }
  31 +
  32 + public function build()
  33 + {
  34 +
  35 + // Вернуть все данные
  36 + return $this->view('emails.added_mass_sending_messages', ['data' => $this->data]);
  37 + }
  38 +
  39 +
  40 + public function attachments(): array
  41 + {
  42 + return [];
  43 + }
  44 +}
app/Models/MessagesRequests.php
... ... @@ -0,0 +1,19 @@
  1 +<?php
  2 +
  3 +namespace App\Models;
  4 +
  5 +use Illuminate\Database\Eloquent\Factories\HasFactory;
  6 +use Illuminate\Database\Eloquent\Model;
  7 +
  8 +class MessagesRequests extends Model
  9 +{
  10 + use HasFactory;
  11 +
  12 + protected $fillable = [
  13 + 'user_id',
  14 + 'job_titles',
  15 + 'text',
  16 + 'is_rejected',
  17 + 'is_sent'
  18 + ];
  19 +}
database/migrations/2024_08_05_094303_create_message_requests_table.php
... ... @@ -0,0 +1,36 @@
  1 +<?php
  2 +
  3 +use Illuminate\Database\Migrations\Migration;
  4 +use Illuminate\Database\Schema\Blueprint;
  5 +use Illuminate\Support\Facades\Schema;
  6 +
  7 +return new class extends Migration
  8 +{
  9 + /**
  10 + * Run the migrations.
  11 + *
  12 + * @return void
  13 + */
  14 + public function up()
  15 + {
  16 + Schema::create('messages_requests', function (Blueprint $table) {
  17 + $table->id();
  18 + $table->bigInteger('user_id')->nullable(false);
  19 + $table->text('job_titles')->nullable(false);
  20 + $table->text('text')->nullable();
  21 + $table->dateTime('is_rejected')->nullable(true);
  22 + $table->dateTime('is_sent')->nullable(true);
  23 + $table->timestamps();
  24 + });
  25 + }
  26 +
  27 + /**
  28 + * Reverse the migrations.
  29 + *
  30 + * @return void
  31 + */
  32 + public function down()
  33 + {
  34 + Schema::dropIfExists('messages_requests');
  35 + }
  36 +};
resources/views/emails/added_mass_sending_messages.blade.php
... ... @@ -0,0 +1,3 @@
  1 +<div>
  2 + Добавлен новый запрос на рассылку от "{{ $data['user']->name }}".
  3 +</div>
resources/views/employers/send_all.blade.php
... ... @@ -26,70 +26,27 @@
26 26 <div class="cabinet__descr">
27 27 <h2 class="title cabinet__title">Рассылка сообщений</h2>
28 28 @include('messages_error')
29   - <p class="cabinet__text"><b>Контактные данные</b></p>
30   - <p class="cabinet__text">Все поля обязательны для заполнения *</p>
31   - </div>
32   - <div class="cabinet__inputs">
33   - <div class="cabinet__inputs-item form-group">
34   - <label class="form-group__label">Название судоходной компании</label>
35   - <div class="form-group__item">
36   - <input type="text" class="input" name="name_company" placeholder="ООО Река Море" value="{{ old('name_company') ?? $Employer[0]->name_company }}" required>
37   - </div>
38   - </div>
39   -
40   - <div class="cabinet__inputs-item form-group">
41   - <label class="form-group__label">Электронная почта</label>
42   - <div class="form-group__item">
43   - <input type="email" class="input" name="email" placeholder="info@rekamore.su" value="{{ old('email') ?? $Employer[0]->email }}" required>
44   - </div>
45   - </div>
46   -
47   - <div class="cabinet__inputs-item form-group">
48   - <label class="form-group__label">Номер телефона</label>
49   - <div class="form-group__item">
50   - <input type="tel" class="input" name="telephone" placeholder="+7 (___) ___-__-__" value="{{ old('telephone') ?? $Employer[0]->telephone }}" required>
51   - </div>
52   - </div>
53   -
54   - <div class="cabinet__inputs-item form-group">
55   - <label class="form-group__label">Адрес (Город)</label>
56   - <div class="form-group__item">
57   - <input type="text" class="input" name="city" placeholder="Мурманск" value="{{ old('city') ?? $Employer[0]->city }}" required>
58   - </div>
59   - </div>
60   -
61   - <!--<div class="cabinet__inputs-item form-group">
62   - <label class="form-group__label">Адрес компании</label>
63   - <div class="form-group__item">
64   - <div class="select">
65   - <select class="js-select2">
66   - <option selected disabled>Выберите должность из списка</option>
67   - <option>Вариант 1</option>
68   - <option>Вариант 2</option>
69   - <option>Вариант 3</option>
70   - <option>Вариант 4</option>
71   - <option>Вариант 5</option>
72   - <option>Вариант 6</option>
73   - </select>
74   - </div>
75   - </div>
76   - </div>-->
77 29 </div>
78 30 </div>
79 31  
80 32 <div class="cabinet__body-item">
81   - <div class="cabinet__descr">
82   - <p class="cabinet__text"><b>Ваше сообщение</b></p>
83   - </div>
84 33 <div class="cabinet__inputs">
85 34 <div class="cabinet__inputs-item cabinet__inputs-item_fullwidth form-group">
86   - <label class="form-group__label">Тема сообщения</label>
  35 + <label class="form-group__label">Выберите должность</label>
87 36 <div class="form-group__item">
88   - <input type="text" name="text_sms" class="input" value="{{ old('text_sms') ?? '' }}" required>
  37 + <div class="select">
  38 + <select class="js-select2" name="job_title_ids[]" id="job_title_ids[]" multiple="multiple">
  39 + @if ($job_titles->count())
  40 + @foreach($job_titles as $job_title)
  41 + <option value="{{ $job_title->id }}">{{ $job_title->name }}</option>
  42 + @endforeach
  43 + @endif
  44 + </select>
  45 + </div>
89 46 </div>
90 47 </div>
91 48 <div class="cabinet__inputs-item cabinet__inputs-item_fullwidth form-group">
92   - <label class="form-group__label">О компании (Приглашение)</label>
  49 + <label class="form-group__label">Введите текст сообщения</label>
93 50 <div class="form-group__item">
94 51 <textarea class="textarea" name="message_text" required>{{ old('message_text') ?? '' }}</textarea>
95 52 </div>
resources/views/info_company_new.blade.php
... ... @@ -211,10 +211,10 @@
211 211 </a>
212 212 @endif
213 213  
214   - <div class="bold font20">{{ $flot->name }}</div>
215   - <div class="flot-label"><div class="flot-label-name">DWT</div> {{ $flot->DWT }}</div>
216   - <div class="flot-label"><div class="flot-label-name">Мощность</div> {{ $flot->POWER_GD }}</div>
217   - <div class="flot-label"><div class="flot-label-name">IMO</div> {{ $flot->IMO }}</div>
  214 + <div class="flot-label"><div class="flot-label-name">Название:</div>{{ $flot->name }}</div>
  215 + <div class="flot-label"><div class="flot-label-name">DWT:</div> {{ $flot->DWT }}</div>
  216 + <div class="flot-label"><div class="flot-label-name">Мощность:</div> {{ $flot->POWER_GD }}</div>
  217 + <div class="flot-label"><div class="flot-label-name">IMO:</div> {{ $flot->IMO }}</div>
218 218 </div>
219 219 @endforeach
220 220 @endif
resources/views/js/favorite-worker.blade.php
1 1 <script>
2   - console.log('js выполняется...123');
3   -
4 2 $(document).ready(function() {
5 3 $(document).on('click', '.js_box_favorit', function () {
6   - var _this = $(this);
7   - var id = _this.attr('id');
8   - var id_worker = _this.attr('data-val');
9   - console.log('active='+id);
10   - console.log('is_worker='+id_worker);
  4 + var this_btn = $(this);
  5 + var id_worker = this_btn.attr('data-val');
  6 + var data = {code_record: id_worker};
11 7  
12   - if ($( "#"+id ).hasClass( "active" )) {
13   - console.log('Download 41... final');
14   - $.ajax({
15   - type: "GET",
16   - url: "{{ route('like_resume') }}",
17   - data: "code_record=" + id_worker,
18   - success: function (data) {
19   - console.log('Выбор сортировки');
20   - console.log(data);
  8 + if (this_btn.hasClass('active')){
  9 + data.delete = 1;
  10 + }
21 11  
22   - },
23   - headers: {
24   - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
25   - },
26   - error: function (data) {
27   - data = JSON.stringify(data);
28   - console.log('Error: ' + data);
29   - }
30   - });
31   - } else {
32   - console.log('Не выполнить условие никогда');
33   - $.ajax({
34   - type: "GET",
35   - url: "{{ route('like_resume') }}",
36   - data: "code_record=" + id_worker + "&delete=1",
37   - success: function (data) {
38   - console.log('Выбор сортировки');
39   - console.log(data);
40   - },
41   - headers: {
42   - 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
43   - },
44   - error: function (data) {
45   - data = JSON.stringify(data);
46   - console.log('Error: ' + data);
47   - }
48   - });
  12 + if (this_btn.hasClass('active')){
  13 + this_btn.removeClass('active');
  14 + } else{
  15 + this_btn.addClass('active');
49 16 }
  17 +
  18 + $.ajax({
  19 + type: "GET",
  20 + url: "{{ route('like_resume') }}",
  21 + data: data,
  22 + success: function (data) {
  23 +
  24 + },
  25 + headers: {
  26 + 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
  27 + },
  28 + error: function (data) {
  29 + data = JSON.stringify(data);
  30 + console.log('Error: ' + data);
  31 + }
  32 + });
50 33 });
51 34 });
52 35 </script>
resources/views/resume.blade.php
... ... @@ -32,21 +32,7 @@
32 32  
33 33 <script>
34 34 $(document).ready(function() {
35   - $(document).on('click', '.js_box_favorites', function () {
36   - var _this = $(this);
37   - var id_worker = _this.attr('data-val');
38 35  
39   - if (_this.hasClass('active')) {
40   - add_in_array(id_worker);
41   - console.log('Добавлено в избранное id=' + id_worker);
42   - } else {
43   - delete_in_array(id_worker);
44   - console.log('Удалено из избранных id='+id_worker)
45   - }
46   - var str = $.cookie('favorite_worker');
47   - console.log("Вывод куков "+str);
48   -
49   - });
50 36 });
51 37  
52 38 //помеченный элемент
resources/views/resume/resume_blocks.blade.php
... ... @@ -6,7 +6,7 @@
6 6 <img src="@isset ($res->photo) {{ asset(Storage::url($res->photo)) }} @else {{ asset('images/default_man.jpg')}} @endif" alt="" class="main__resume-base-body-item-photo">
7 7 <div>
8 8 <div class="main__resume-base-body-item-buttons">
9   - <button type="button" data-id="{{ $res->id }}" id="elem{{ $res->id }}" class="like js-toggle js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($res) }}" data-val="{{ $res->id }}">
  9 + <button type="button" data-id="{{ $res->id }}" id="elem{{ $res->id }}" class="like js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($res) }}" data-val="{{ $res->id }}">
10 10 <svg>
11 11 <use xlink:href="{{ asset('images/sprite.svg#heart') }}"></use>
12 12 </svg>
resources/views/worker.blade.php
... ... @@ -80,7 +80,7 @@
80 80 <p class="thing__text">Сложно сказать, почему ключевые особенности структуры проекта рассмотрены
81 81 исключительно в разрезе маркетинговых и финансовых предпосылок.</p>
82 82 <div class="main__resume-profile-about-buttons thing__bottom">
83   - <button type="button" class="like js-toggle js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($Query[0]) }}" data-val="{{ $Query[0]->id }}" id="elem{{ $Query[0]->id }}"
  83 + <button type="button" class="like js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($Query[0]) }}" data-val="{{ $Query[0]->id }}" id="elem{{ $Query[0]->id }}"
84 84 name="header-like-button"
85 85 >
86 86 <svg class="mr-10">
... ... @@ -339,7 +339,7 @@
339 339 @if (App\Classes\StatusUser::Status()==0)
340 340 @if ((!Auth()->user()->is_worker) && (Auth()->user()->is_message))
341 341 <div class="main__resume-profile-about-buttons flex width100">
342   - <button type="button" class="like js-toggle active mr-10 js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($Query[0]) }}"
  342 + <button type="button" class="like mr-10 js_box_favorit {{ \App\Classes\LikesClass::get_status_worker($Query[0]) }}"
343 343 name="footer-like-button"
344 344 >
345 345 <svg class="mr-10">