如何在 30 分钟后向客户发送通知?

在他点击确认交付后,我试图在 30 分钟后向客户应用发送通知。我创建了一个事件侦听器来发送该通知,但是如何让侦听器侦听一个事件并在 30 分钟后发送该通知?


这是我在 APIController 中的确认交付功能:


public function confirm_delivery(Request $request)

{

    $id = (int)$request->order_id;

    $order = Order::find($id);

    Order::where('user_id', $user->id)->find($id)->update(['stage' => 9]);

    $type = 'CUSTOMER_';

    $uuid = $user->uniqid;

    $order_id =$id;

    $order_no =$order->order_no;

    //Todo::Event to send notfifiction for user to rate place after 30 mins

    event(new CustomerRatePlaceEvent($type,$uuid,$order_id,$order_no));

    return ResponseHelper::customizedResponse(true, 1, 'Order delivered to customer.');

}


_在 CustomerRatePlaceEvent 中构造:


public $type;

public $uuid;

public $order_id;

public $order_no;


public function __construct($type,$uuid,$order_id,$order_no)

{

    $this->type = $type;

    $this->uuid = $uuid;

    $this->order_id = $order_id;

    $this->order_no = $order_no;

}

事件服务提供者:


 CustomerRatePlaceEvent::class => [

     CustomerRatePlaceListener::class,

 ],

CustomerRatePlaceListener:


public function handle($event)

{

    NotificationHelper::ٌratePlaceNotification($event->type,$event->uuid,$event->order_id,$event->order_no);

}

(通知代码在一个辅助函数中,它工作正常:NotificationHelper::ٌratePlaceNotification)


慕无忌1623718
浏览 100回答 1
1回答

萧十郎

队列足以完成此任务。您应该使用延迟调度 - https://laravel.com/docs/7.x/queues#delayed-dispatching当用户使用 api 端点或创建某些实体时,您调度延迟 30 分钟。像这样的东西:SendNotification::dispatch($podcast)->delay(now()->addMinutes(30));
打开App,查看更多内容
随时随地看视频慕课网APP