PaymentReceived.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. private $amount;
  12. private $sn;
  13. public function __construct($sn, $amount)
  14. {
  15. $this->amount = $amount;
  16. $this->sn = $sn;
  17. }
  18. public function via($notifiable)
  19. {
  20. return sysConfig('payment_received_notification');
  21. }
  22. public function toMail($notifiable)
  23. {
  24. return (new MailMessage)
  25. ->subject(__('Payment Received'))
  26. ->line(__('Payment for #:sn has been received! Total amount: ¥:amount.', ['sn' => $this->sn, 'amount' => $this->amount]))
  27. ->action(__('Invoice Detail'), route('invoiceInfo', $this->sn));
  28. }
  29. public function toDataBase($notifiable)
  30. {
  31. return [
  32. 'sn' => $this->sn,
  33. 'amount' => $this->amount,
  34. ];
  35. }
  36. // todo: 需要重新审视发送对象
  37. public function toTelegram($notifiable)
  38. {
  39. $message = sprintf(
  40. "💰成功收款%s元\n———————————————\n订单号:%s",
  41. $this->amount,
  42. $this->sn
  43. );
  44. return TelegramMessage::create()
  45. ->to($notifiable->telegram_user_id)
  46. ->token(sysConfig('telegram_token'))
  47. ->content($message);
  48. }
  49. }