UserCertifyApplyNotification.php 1.66 KB
<?php

namespace App\Notifications;

use App\Models\User;
use App\Models\UserCertify;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Notification;

class UserCertifyApplyNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public UserCertify $userCertify;

    public User $applyUser;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(UserCertify $userCertify)
    {
        $this->userCertify = $userCertify;
        $this->applyUser   = $userCertify->getAttribute('user');
    }

    /**
     * Get the notification's delivery channels.
     *
     * @return array
     */
    public function via(): array
    {
        return ['wechat', 'jPush'];
    }


    public function toJPush(User $notifiable): array
    {
        return [
            'user'    => $notifiable->getKey(),
            'title'   => $this->applyUser->getAttribute('nick_name') . '提交了认证申请',
            'content' => '点击查看详情',
            'data'    => ['type' => 'userAuth', 'value' => '']
        ];
    }

    public function toWechat(User $notifiable): array
    {
        return [
            'openId'   => $notifiable->getAttribute('official_id'),
            'template' => 'DWu2Opezt2ricor_x38tq-PWna8k26ehJbhRbNwua4c',
            'data'     => [
                'keyword1' => $this->applyUser->getAttribute('nick_name'),
                'keyword2' => (string)$this->userCertify->getAttribute('created_at'),
                'keyword3' => '无',
            ],
            "page"     => '/packageLogin/pages/applyList'
        ];
    }
}