Notification.php
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
namespace addons\shopro\job;
use think\queue\Job;
/**
* 队列消息通知
*/
class Notification extends BaseJob
{
/**
* 发送通知
*/
public function send(Job $job, $data){
try {
// 这里获取到的 $notifiables 和 notification 两个都是数组,不是类,尴尬, 更可恨的 notification 只是 {"delay":0,"event":"changemobile"}
$notifiables = $data['notifiables'];
$notification = $data['notification'];
// 因为 notification 只有参数,需要把对应的类传过来,在这里重新初始化
$notification_name = $data['notification_name'];
// 重新实例化 notification 实例
$notification = new $notification_name($notification['data']);
// 发送消息
\addons\shopro\library\notify\Notify::sendNow($notifiables, $notification);
// 删除 job
$job->delete();
} catch (\Exception $e) {
// 队列执行失败
\think\Log::write('queue-' . get_class()
. (isset($notification->event) ? ('-' . $notification->event) : '')
. ':执行失败,错误信息:' . $e->getMessage());
}
}
}