OrderLongTimeNoPayNotification.php 3.6 KB

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