PaymentConfirm.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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('🛒 '.trans('common.payment.manual')."\n———————————————\n\t\tℹ️ ".trans('common.account').": %s\n\t\t💰 ".trans('user.shop.price').":%1.2f\n\t\t📦 ".trans('model.goods.attribute').": %s\n\t\t", $order->user->username,
  28. $order->amount, $goods->name ?? trans('user.recharge_credit'));
  29. foreach (User::role('Super Admin')->get() as $admin) {
  30. if (! $admin->telegram_user_id) {
  31. continue;
  32. }
  33. return TelegramMessage::create()
  34. ->to($admin->telegram_user_id)
  35. ->token(sysConfig('telegram_token'))
  36. ->content($message)
  37. ->button(trans('common.status.reject'), route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 0]))
  38. ->button(trans('common.confirm'), route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 1]));
  39. }
  40. return false;
  41. }
  42. public function toCustom($notifiable): array
  43. {
  44. $order = $this->order;
  45. $goods = $this->order->goods;
  46. return [
  47. 'title' => '🛒 '.trans('common.payment.manual'),
  48. 'body' => [
  49. [
  50. 'keyname' => 'ℹ️ '.trans('common.account'),
  51. 'value' => $order->user->username,
  52. ],
  53. [
  54. 'keyname' => '💰 '.trans('user.shop.price'),
  55. 'value' => sprintf('%1.2f', $order->amount),
  56. ],
  57. [
  58. 'keyname' => '📦 '.trans('model.goods.attribute'),
  59. 'value' => $goods->name ?? trans('user.recharge_credit'),
  60. ],
  61. ],
  62. 'markdown' => '- ℹ️ '.trans('common.account').': '.$order->user->username.PHP_EOL.'- 💰 '.trans('user.shop.price').': '.sprintf('%1.2f', $order->amount).PHP_EOL.'- 📦 '.trans('user.shop.price').': '.($goods->name ?? trans('user.recharge_credit')),
  63. 'button' => [
  64. route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 0]),
  65. route('payment.notify', ['method' => 'manual', 'sign' => $this->sign, 'status' => 1]),
  66. ],
  67. ];
  68. }
  69. }