OrderRefundNotification.php 3.2 KB

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