123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- <?php
- namespace App\Notifications;
- use App\Channels\SendMiniChannel;
- use App\Models\Model;
- use App\Models\User;
- use Illuminate\Bus\Queueable;
- use Illuminate\Notifications\Notification;
- use Illuminate\Contracts\Queue\ShouldQueue;
- use Illuminate\Notifications\Messages\MailMessage;
- use Illuminate\Support\Facades\Log;
- use Overtrue\EasySms\EasySms;
- class OrderLongTimeNoPayNotification extends Notification
- {
- use Queueable;
- public static $user;
- public static $order;
- /**
- * Create a new notification instance.
- *
- * @return void
- */
- public function __construct(User $user,$order)
- {
- //
- self::$user = $user;
- self::$order = $order;
- }
- /**
- * Get the notification's delivery channels.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function via($notifiable)
- {
- return [SendMiniChannel::class];
- }
- /**
- * Get the mail representation of the notification.
- *
- * @param mixed $notifiable
- * @return \Illuminate\Notifications\Messages\MailMessage
- */
- public function toMail($notifiable)
- {
- return (new MailMessage)
- ->line('The introduction to the notification.')
- ->action('Notification Action', url('/'))
- ->line('Thank you for using our application!');
- }
- /**
- * Get the array representation of the notification.
- *
- * @param mixed $notifiable
- * @return array
- */
- public function toArray($notifiable)
- {
- return [
- //
- ];
- }
- /**
- * 发送微信小程序消息通知
- *
- * */
- public function toSendMini($notifiable)
- {
- $order = self::$order;
- $user = self::$user;
- $app = app('wechat.mini_program');
- $page = 'pages/my_riding/my_riding?order='.$order->no.'&index='.$order->order_type;
- $data = [
- 'template_id' => 'CBp8jWZHVOQBIB7_n4EHuDv3ik12gOvlaXsOG2U0dPc',//config('wechat.mini_program.message_template.to_be_paid'), // 所需下发的订阅模板id
- 'touser' => $user->auth->credential, // 接收者(用户)的 openid
- 'page' => $page, // 点击模板卡片后的跳转页面,仅限本小程序内的页面。支持带参数,(示例index?foo=bar)。该字段不填则模板无跳转。
- 'data' => [ // 模板内容,格式形如 { "key1": { "value": any }, "key2": { "value": any } }
- 'date1' => [
- // 用车时间
- 'value' => $order->start_use_bike_time,
- ],
- 'thing2' => [
- // 骑行时间
- 'value' => floor($order->use_bike_time_length / 60) . 'h' . ($order->use_bike_time_length % 60) . 'm',
- ],
- 'amount3' => [
- // 待支付金额
- 'value' => $order->pay_money,
- ],
- 'thing4' => [
- // 费用明细
- 'value' => '点击卡片查看明细',
- ],
- ],
- ];
- $res = $app->subscribe_message->send($data);
- if($res['errcode'] !== 0){
- Log::warning($res);
- // $config = config('easySms');
- // $easySms = $easySms = new EasySms($config);
- app('easy_sms')->send($user->mobile, [
- 'template' => '565177',
- 'data' => [
- 'truename' => $user->truename,
- 'time' => $order->start_use_bike_time
- ]
- ]);
- }
- }
- }
|