OrderNoPayNotification.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <?php
  2. namespace App\Notifications;
  3. use App\Channels\SendMiniChannel;
  4. use App\Models\Model;
  5. use App\Models\User;
  6. use Illuminate\Bus\Queueable;
  7. use Illuminate\Notifications\Notification;
  8. use Illuminate\Contracts\Queue\ShouldQueue;
  9. use Illuminate\Notifications\Messages\MailMessage;
  10. class OrderNoPayNotification extends Notification
  11. {
  12. use Queueable;
  13. public static $user;
  14. public static $order;
  15. /**
  16. * Create a new notification instance.
  17. *
  18. * @return void
  19. */
  20. public function __construct(User $user,$order)
  21. {
  22. //
  23. self::$user = $user;
  24. self::$order = $order;
  25. }
  26. /**
  27. * Get the notification's delivery channels.
  28. *
  29. * @param mixed $notifiable
  30. * @return array
  31. */
  32. public function via($notifiable)
  33. {
  34. return [SendMiniChannel::class];
  35. }
  36. /**
  37. * Get the mail representation of the notification.
  38. *
  39. * @param mixed $notifiable
  40. * @return \Illuminate\Notifications\Messages\MailMessage
  41. */
  42. public function toMail($notifiable)
  43. {
  44. return (new MailMessage)
  45. ->line('The introduction to the notification.')
  46. ->action('Notification Action', url('/'))
  47. ->line('Thank you for using our application!');
  48. }
  49. /**
  50. * Get the array representation of the notification.
  51. *
  52. * @param mixed $notifiable
  53. * @return array
  54. */
  55. public function toArray($notifiable)
  56. {
  57. return [
  58. //
  59. ];
  60. }
  61. /**
  62. * 发送微信小程序消息通知
  63. *
  64. * */
  65. public function toSendMini($notifiable)
  66. {
  67. $order = self::$order;
  68. $user = self::$user;
  69. $app = app('wechat.mini_program');
  70. $page = 'pages/my_riding/my_riding?order='.$order->no.'&index='.$order->order_type;
  71. $data = [
  72. 'template_id' => config('wechat.mini_program.message_template.to_be_paid'), // 所需下发的订阅模板id
  73. 'touser' => $user->auth->credential, // 接收者(用户)的 openid
  74. 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
  75. 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
  76. 'date1' => [
  77. // 用车时间
  78. 'value' => $order->start_use_bike_time,
  79. ],
  80. 'thing2' => [
  81. // 骑行时间
  82. 'value' => floor($order->use_bike_time_length / 60) . 'h' . ($order->use_bike_time_length % 60) . 'm',
  83. ],
  84. 'amount3' => [
  85. // 待支付金额
  86. 'value' => $order->pay_money,
  87. ],
  88. 'thing4' => [
  89. // 费用明细
  90. 'value' => '点击卡片查看明细',
  91. ],
  92. ],
  93. ];
  94. $app->subscribe_message->send($data);
  95. }
  96. }