ActivitySubmitWorkPassNotification.php 1.88 KB
<?php

namespace App\Notifications;

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

class ActivitySubmitWorkPassNotification extends Notification implements ShouldQueue
{
    use Queueable;

    public ActivityWork $work;

    /**
     * Create a new notification instance.
     *
     * @return void
     */
    public function __construct(ActivityWork $work)
    {
        $this->work = $work;
    }

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

    /**
     * @param \App\Models\User $notifiable
     * @return array
     */
    public function toSms(User $notifiable): array
    {
        return [
            'phone' => $notifiable->getPhoneNotificationKey(),
            'data'  => [
                'template' => 'SMS_463623202',
                'content'  => '恭喜,您参与的试唱《${song_name}》已达成合作!请在海星试唱应用内,和厂牌:${brand_name},商谈进一步合作。',
                'data'     => [
                    'song_name'  => $this->work->getAttribute('activity_name'),
                    'brand_name' => $this->work->getAttribute('project')?->getAttribute('name')
                ]
            ]
        ];
    }

    /**
     * @param \App\Models\User $notifiable
     * @return array
     */
    public function toJPush(User $notifiable): array
    {
        return [
            'user'    => $notifiable->getKey(),
            'title'   => '《' . $this->work->getAttribute('activity_name') . '》试唱结果通知',
            'content' => '恭喜,您参与的试唱已达成合作!',
            'data'    => ['type' => 'ToMysing', 'value' => $this->work->getAttribute('activity_id')]
        ];
    }
}