generated from liutk/owl-admin-base
38 lines
932 B
PHP
38 lines
932 B
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Enums\MessageType;
|
|
use App\Models\Employee;
|
|
use App\Models\Message;
|
|
|
|
class MessageService
|
|
{
|
|
/**
|
|
* 创建消息通知
|
|
*
|
|
* @param array<int, \App\Models\Employee|int> $employees
|
|
*/
|
|
public function create(MessageType $type, ?string $title, ?string $content, array $employees = [], array $additional = [])
|
|
{
|
|
$employeeIds = collect($employees)->map(function ($employee) {
|
|
if ($employee instanceof Employee) {
|
|
return $employee->id;
|
|
}
|
|
return $employee;
|
|
})->all();
|
|
|
|
$message = Message::create([
|
|
'type' => $type,
|
|
'title' => $title,
|
|
'content' => $content,
|
|
'additional' => $additional,
|
|
'employee_ids' => $employeeIds,
|
|
]);
|
|
|
|
switch ($message->type) {
|
|
// @todo 根据消息类型发送通知
|
|
}
|
|
}
|
|
}
|