增加 生日提醒
This commit is contained in:
parent
c2bbe7ab0f
commit
bec1b251dd
@ -99,3 +99,6 @@ EMQX_API_KEY=
|
|||||||
EMQX_API_SECRET_KEY=
|
EMQX_API_SECRET_KEY=
|
||||||
|
|
||||||
USER_GROUP_BIRTHDAY=1
|
USER_GROUP_BIRTHDAY=1
|
||||||
|
|
||||||
|
DASHBOARD_BASE_URL=https://dash.laecloud.com
|
||||||
|
DASHBOARD_BIRTHDAY_PATH=/birthdays
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Models\UserGroup;
|
use App\Models\UserGroup;
|
||||||
|
use App\Notifications\TodayIsUserBirthday;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
@ -40,9 +41,8 @@ public function handle(): void
|
|||||||
User::birthday()->chunk(100, function ($users) use ($birthday_group) {
|
User::birthday()->chunk(100, function ($users) use ($birthday_group) {
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
$birthday_group->setTempGroup($user, $birthday_group, now()->addDay());
|
$birthday_group->setTempGroup($user, $birthday_group, now()->addDay());
|
||||||
|
$user->notify(new TodayIsUserBirthday());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
109
app/Notifications/TodayIsUserBirthday.php
Normal file
109
app/Notifications/TodayIsUserBirthday.php
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Notifications;
|
||||||
|
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Notifications\Messages\MailMessage;
|
||||||
|
use Illuminate\Notifications\Notification;
|
||||||
|
use Illuminate\Support\Facades\URL;
|
||||||
|
|
||||||
|
class TodayIsUserBirthday extends Notification implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new notification instance.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the notification's delivery channels.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function via($notifiable): array
|
||||||
|
{
|
||||||
|
return ['mail'];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the mail representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return MailMessage
|
||||||
|
*/
|
||||||
|
public function toMail(mixed $notifiable): MailMessage
|
||||||
|
{
|
||||||
|
$url = URL::format(config('settings.dashboard.base_url'), config('settings.dashboard.birthday_path'));
|
||||||
|
|
||||||
|
|
||||||
|
$lyrics = [
|
||||||
|
[
|
||||||
|
"Happy Birthday",
|
||||||
|
"好想把我的心意传达给你。"
|
||||||
|
],
|
||||||
|
['今天祝你生日快乐!',
|
||||||
|
'这是第几次呢 假装忘记了(实际上)。',
|
||||||
|
'心里很清楚 只是在装傻。'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'今天祝你生日快乐!',
|
||||||
|
'蛋糕上的蜡烛要立几根好呢。连备用的都一起买好了!'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'Happy Birthday!',
|
||||||
|
'人与人的相遇真是不可思议。'
|
||||||
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'你知道吗?',
|
||||||
|
'你对我而言很重要(一定要说出来)',
|
||||||
|
'会不会太迟了呢?我喜欢你,还会更喜欢你。',
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'即使以心传心但也一定有着极限的。所以要好好地说出来。'
|
||||||
|
],
|
||||||
|
|
||||||
|
];
|
||||||
|
|
||||||
|
$lyric = $lyrics[array_rand($lyrics)];
|
||||||
|
|
||||||
|
$email = (new MailMessage)
|
||||||
|
->subject('Happy Birthday!')
|
||||||
|
->greeting('Happy Birthday!');
|
||||||
|
|
||||||
|
foreach ($lyric as $line) {
|
||||||
|
$email->line($line);
|
||||||
|
}
|
||||||
|
|
||||||
|
$email->line('生日快乐🎂')
|
||||||
|
->line('在生日当天,我们还为您提供了专属用户组,您可以前往仪表盘查看。')
|
||||||
|
->action('前往仪表盘', $url)
|
||||||
|
->line('感谢您继续使用 ' . config('app.display_name') . '。');
|
||||||
|
|
||||||
|
return $email;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the array representation of the notification.
|
||||||
|
*
|
||||||
|
* @param mixed $notifiable
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function toArray($notifiable)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
//
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
@ -17,6 +17,24 @@
|
|||||||
|
|
||||||
<p>邮箱: {{ $user->email }}</p>
|
<p>邮箱: {{ $user->email }}</p>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<p>生日: {{ $user->birthday_at }},
|
||||||
|
{{-- 是不是今天 --}}
|
||||||
|
@if ($user->birthday_at->isToday())
|
||||||
|
<span class="text-danger">今天就是。</span>
|
||||||
|
@else
|
||||||
|
{{-- 距离下次生日的时间 --}}
|
||||||
|
@if ($user->birthday_at->isFuture())
|
||||||
|
还有 {{ $user->birthday_at->diffInDays() }} 天 {{ $user->birthday_at->diffInHours() }} 小时
|
||||||
|
@else
|
||||||
|
已经过去 {{ $user->birthday_at->diffInDays() }} 天 {{ $user->birthday_at->diffInHours() }} 小时
|
||||||
|
@endif
|
||||||
|
。
|
||||||
|
@endif
|
||||||
|
</p>
|
||||||
|
|
||||||
|
|
||||||
{{-- hosts --}}
|
{{-- hosts --}}
|
||||||
<h3>主机列表</h3>
|
<h3>主机列表</h3>
|
||||||
<table class="table table-hover">
|
<table class="table table-hover">
|
||||||
|
Loading…
Reference in New Issue
Block a user