PaymentReceived.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Notifications;
  3. use App\Models\User;
  4. use Illuminate\Bus\Queueable;
  5. use Illuminate\Contracts\Queue\ShouldQueue;
  6. use Illuminate\Notifications\Messages\MailMessage;
  7. use Illuminate\Notifications\Notification;
  8. use NotificationChannels\Telegram\TelegramMessage;
  9. class PaymentReceived extends Notification implements ShouldQueue
  10. {
  11. use Queueable;
  12. private $amount;
  13. private $sn;
  14. public function __construct($sn, $amount)
  15. {
  16. $this->amount = $amount;
  17. $this->sn = $sn;
  18. }
  19. public function via($notifiable)
  20. {
  21. return sysConfig('payment_received_notification');
  22. }
  23. public function toMail($notifiable)
  24. {
  25. return (new MailMessage)
  26. ->subject(__('Payment Received'))
  27. ->line(__('Payment for #:sn has been received! Total amount: ¥:amount.', ['sn' => $this->sn, 'amount' => $this->amount]))
  28. ->action(__('Invoice Detail'), route('invoiceInfo', $this->sn));
  29. }
  30. public function toDataBase($notifiable)
  31. {
  32. return [
  33. 'sn' => $this->sn,
  34. 'amount' => $this->amount,
  35. ];
  36. }
  37. // todo: 需要重新审视发送对象
  38. public function toTelegram($notifiable)
  39. {
  40. foreach (User::role('Super Admin')->get() as $admin) {
  41. $message = sprintf(
  42. "💰成功收款%s元\n———————————————\n订单号:%s",
  43. $this->amount,
  44. $this->sn
  45. );
  46. return TelegramMessage::create()
  47. ->to($admin->telegram_user_id)
  48. ->token(sysConfig('telegram_token'))
  49. ->content($message);
  50. }
  51. }
  52. }