为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
慕无忌1623718 2022-10-14 16:31:44
在他点击确认交付后,我试图在 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)
查看完整描述

1 回答

?
萧十郎

TA贡献1815条经验 获得超13个赞

队列足以完成此任务。

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

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

像这样的东西:

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


查看完整回答
反对 回复 2022-10-14
  • 1 回答
  • 0 关注
  • 128 浏览

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号