繁体   English   中英

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

[英]how to send a notification to the customer after 30 minutes?

我试图在 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.');
}

_Construct 在 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)

队列足以完成此任务。

您应该使用延迟调度 - https://laravel.com/docs/7.x/queues#delayed-dispatching

当用户使用 api 端点或创建一些实体时,您调度延迟 30 分钟。

像这样的东西:

SendNotification::dispatch($podcast)->delay(now()->addMinutes(30));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM