Lae/app/Notifications/User/TodayIsUserBirthday.php

113 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2022-12-30 12:55:45 +00:00
<?php
2023-01-13 14:11:56 +00:00
namespace App\Notifications\User;
2022-12-30 12:55:45 +00:00
2023-03-01 15:00:34 +00:00
use App\Notifications\Channels\WebChannel;
2022-12-30 12:55:45 +00:00
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
class TodayIsUserBirthday extends Notification implements ShouldQueue
{
use Queueable;
2023-03-01 15:00:34 +00:00
private string $subject = '生日快乐';
private string $greeting = '生日快乐🎂';
2022-12-30 12:55:45 +00:00
/**
* Get the notification's delivery channels.
*/
2023-01-10 13:42:27 +00:00
public function via(): array
2022-12-30 12:55:45 +00:00
{
2023-03-01 15:00:34 +00:00
return [WebChannel::class, 'mail'];
2022-12-30 12:55:45 +00:00
}
/**
* Get the mail representation of the notification.
*/
2023-01-10 13:42:27 +00:00
public function toMail(): MailMessage
2023-03-01 15:00:34 +00:00
{
$email = (new MailMessage)
->subject($this->subject)
->greeting($this->greeting);
$lyrics = $this->lyrics();
foreach ($lyrics as $lyric) {
$email->line($lyric);
}
$email->line($this->suffixText());
return $email;
}
/**
* Get the array representation of the notification.
*/
public function toArray(): array
{
return [
'title' => $this->greeting,
'message' => $this->lyrics(true).$this->suffixText(),
];
}
protected function lyrics(bool $to_string = false): array|string
2022-12-30 12:55:45 +00:00
{
$lyrics = [
[
2023-01-30 16:14:07 +00:00
'Happy Birthday',
'好想把我的心意传达给你。',
2022-12-30 12:55:45 +00:00
],
2022-12-30 13:01:47 +00:00
[
'今天祝你生日快乐!',
2022-12-30 12:55:45 +00:00
'这是第几次呢 假装忘记了(实际上)。',
2023-01-30 16:14:07 +00:00
'心里很清楚 只是在装傻。',
2022-12-30 12:55:45 +00:00
],
[
'今天祝你生日快乐!',
2023-01-30 16:14:07 +00:00
'蛋糕上的蜡烛要立几根好呢。连备用的都一起买好了!',
2022-12-30 12:55:45 +00:00
],
[
'Happy Birthday!',
2023-01-30 16:14:07 +00:00
'人与人的相遇真是不可思议。',
2022-12-30 12:55:45 +00:00
],
[
'你知道吗?',
'你对我而言很重要(一定要说出来)',
'会不会太迟了呢?我喜欢你,还会更喜欢你。',
],
[
2023-01-30 16:14:07 +00:00
'即使以心传心但也一定有着极限的。所以要好好地说出来。',
2022-12-30 12:55:45 +00:00
],
];
2023-03-01 15:00:34 +00:00
$random_lyrics = $lyrics[array_rand($lyrics)];
2022-12-30 12:55:45 +00:00
2023-03-01 15:00:34 +00:00
if ($to_string) {
$lyric_string = '';
foreach ($random_lyrics as $lyric) {
$lyric_string .= $lyric.PHP_EOL.PHP_EOL;
}
2022-12-30 12:55:45 +00:00
2023-03-01 15:00:34 +00:00
return $lyric_string;
2022-12-30 12:55:45 +00:00
}
2023-03-01 15:00:34 +00:00
return $random_lyrics;
}
public function suffixText(): string
{
2023-03-01 14:27:11 +00:00
$today = now()->format('Y-m-d');
2023-03-01 15:00:34 +00:00
return <<<EOF
2023-03-01 14:27:11 +00:00
在这特别的日子里,我们将 《ハピハピ♪バースデイソング ~チノ》 中的歌词献给特别的你。
2023-03-01 15:00:34 +00:00
2023-03-01 14:27:11 +00:00
{$today}, 生日快乐!
EOF;
2022-12-30 12:55:45 +00:00
}
}