PaymentConfirm.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. namespace App\Notifications;
  3. use App\Models\Order;
  4. use App\Models\User;
  5. use Illuminate\Bus\Queueable;
  6. use Illuminate\Notifications\Notification;
  7. use NotificationChannels\Telegram\TelegramMessage;
  8. class PaymentConfirm extends Notification
  9. {
  10. use Queueable;
  11. private $order;
  12. private $sign;
  13. public function __construct(Order $order)
  14. {
  15. $this->order = $order;
  16. $this->sign = string_encrypt($order->payment->id);
  17. }
  18. public function via($notifiable)
  19. {
  20. return sysConfig('payment_confirm_notification');
  21. }
  22. public function toTelegram($notifiable)
  23. {
  24. $order = $this->order;
  25. $goods = $this->order->goods;
  26. $message = sprintf("🛒 人工支付\n———————————————\n\t\tℹ️ 账号:%s\n\t\t💰 金额:%1.2f\n\t\t📦 商品:%s\n\t\t", $order->user->username, $order->amount, $goods->name ?? '余额充值');
  27. foreach (User::role('Super Admin')->get() as $admin) {
  28. if (! $admin->telegram_user_id) {
  29. continue;
  30. }
  31. return TelegramMessage::create()
  32. ->to($admin->telegram_user_id)
  33. ->token(sysConfig('telegram_token'))
  34. ->content($message)
  35. ->button('否 決', route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 0]))
  36. ->button('确 认', route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 1]));
  37. }
  38. return false;
  39. }
  40. public function toCustom($notifiable)
  41. {
  42. $order = $this->order;
  43. $goods = $this->order->goods;
  44. return [
  45. 'title' => '🛒 人工支付',
  46. 'body' => [
  47. [
  48. 'keyname' => 'ℹ️ 账号',
  49. 'value' => $order->user->username,
  50. ],
  51. [
  52. 'keyname' => '💰 金额',
  53. 'value' => sprintf('%1.2f', $order->amount),
  54. ],
  55. [
  56. 'keyname' => '📦 商品',
  57. 'value' => $goods->name ?? '余额充值',
  58. ],
  59. ],
  60. 'markdown' => '- ℹ️ 账号: '.$order->user->username.PHP_EOL.'- 💰 金额: '.sprintf('%1.2f', $order->amount).PHP_EOL.'- 📦 商品: '.($goods->name ?? '余额充值'),
  61. 'button' => [
  62. route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 0]),
  63. route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 1]),
  64. ],
  65. ];
  66. }
  67. }