PaymentConfirm.php 2.7 KB

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