PaymentReceived.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. /**
  38. * @param $notifiable
  39. * @return TelegramMessage|\NotificationChannels\Telegram\Traits\HasSharedLogic
  40. */
  41. public function toTelegram($notifiable)
  42. {
  43. foreach (User::role('Super Admin')->get() as $admin) {
  44. $message = sprintf(
  45. "💰成功收款%s元\n———————————————\n订单号:%s",
  46. $this->amount,
  47. $this->sn
  48. );
  49. return TelegramMessage::create()
  50. ->to($admin->telegram_id)
  51. ->token(sysConfig('telegram_token'))
  52. ->content($message);
  53. }
  54. }
  55. }