PaymentReceived.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Notifications;
  3. use Illuminate\Bus\Queueable;
  4. use Illuminate\Contracts\Queue\ShouldQueue;
  5. use Illuminate\Notifications\Messages\MailMessage;
  6. use Illuminate\Notifications\Notification;
  7. use NotificationChannels\Telegram\TelegramMessage;
  8. class PaymentReceived extends Notification implements ShouldQueue
  9. {
  10. use Queueable;
  11. public function __construct(private readonly string $sn, private readonly string $amountWithSign)
  12. {
  13. }
  14. public function via($notifiable)
  15. {
  16. return sysConfig('payment_received_notification');
  17. }
  18. public function toMail($notifiable): MailMessage
  19. {
  20. return (new MailMessage)->subject(__('Payment Received'))->line(__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amountWithSign]))->action(__('Invoice Detail'),
  21. route('invoiceInfo', $this->sn));
  22. }
  23. public function toDataBase($notifiable): array
  24. {
  25. return [
  26. 'sn' => $this->sn,
  27. 'amount' => $this->amountWithSign,
  28. ];
  29. }
  30. // todo: 需要重新审视发送对象
  31. public function toTelegram($notifiable): TelegramMessage
  32. {
  33. return TelegramMessage::create()->to($notifiable->telegram_user_id)->token(sysConfig('telegram_token'))->content('💰'.__('Payment for #:sn has been received! Total amount: :amount.', ['sn' => $this->sn, 'amount' => $this->amountWithSign]));
  34. }
  35. }