Blame view
app/Models/MessagesRequests.php
1.47 KB
a67c9d7ef Массовая рассылка... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class MessagesRequests extends Model { use HasFactory; protected $fillable = [ 'user_id', 'job_titles', 'text', 'is_rejected', 'is_sent' ]; |
633ea705f Массовая рассылка... |
19 20 21 22 23 24 25 26 27 28 |
public function getJobsAttribute() { $job_titles_ids = json_decode($this->attributes['job_titles'], true); return Job_title::whereIn('id', $job_titles_ids)->get(); } public function user() { return $this->belongsTo(User::class, 'user_id'); } |
d2571da21 Правки по массово... |
29 30 31 32 |
public static function send_message($message_request_id) { $message_request = MessagesRequests::find($message_request_id); |
f98ccb92c Массова рассылка |
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
$job_ids = json_decode($message_request->job_titles); if (!empty($job_ids)){ $workers = Title_worker::select('worker_id') ->whereIN('job_title_id', $job_ids) ->groupBy('worker_id') ->get() ; if ($workers->count()){ $message_params = [ 'text' => $message_request->text ]; foreach ($workers as $worker){ Message::add_message(null, $message_request->user_id, $worker->worker_id, $message_params, file_store_path : '/', is_admin_chat: true); } } } |
d2571da21 Правки по массово... |
51 52 53 54 |
$message_request->update(['is_sent' => now()]); return true; } |
a67c9d7ef Массовая рассылка... |
55 |
} |