Files
water-back/app/Notifications/SystemRemindUserSign.php
2023-01-11 11:00:43 +08:00

82 lines
1.9 KiB
PHP

<?php
namespace App\Notifications;
use App\Channels\WechatMiniChannel;
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Channels\DatabaseChannel;
use Illuminate\Notifications\Notification;
use Modules\User\Models\User;
class SystemRemindUserSign extends Notification
{
use Queueable;
protected $content;
protected $title;
protected $url;
/**
* Create a new notification instance.
*
* @return void
*/
public function __construct()
{
$this->title = '喝水打卡提醒';
$this->content = '您今天还没有喝水打卡,请前去打卡';
$this->url = config('user.web.base');
}
public function via(): array
{
return [DatabaseChannel::class, WechatMiniChannel::class];
}
/**
* Notes: 喝水打卡提醒
*
* @Author: 玄尘
* @Date: 2022/8/8 8:48
* @param User $notifiable
* @return bool
*/
public function toWeChat(User $notifiable): bool
{
if ($notifiable->isOfficialSubscribe()) {
$app = app('wechat.official_account');
$app->template_message->send([
'touser' => $notifiable->wechat->official_openid,
'template_id' => 'N7-vo1bSYXahw22pplkHtI7WGg96dPf1KdMxbKdx6ao',
'url' => $this->url,
'data' => [
'first' => $this->title,
'keyword1' => now(),
'keyword2' => $this->content,
'remark' => '',
],
]);
}
return true;
}
/**
* 发送到数据库
*
* @param mixed $notifiable
* @return array
*/
public function toDatabase(User $notifiable): array
{
return [
'title' => $this->title,
'content' => $this->content,
'url' => $this->url,
];
}
}