You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
ymww_backend/addons/shopro/job/Notification.php

49 lines
1.8 KiB

<?php
namespace addons\shopro\job;
use think\queue\Job;
use think\exception\HttpResponseException;
/**
* 队列消息通知
*/
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'];
$notifiable_name = $data['notifiable_name'];
// 重新实例化 notification 实例
if (class_exists($notification_name)) {
$notification = new $notification_name($notification['data']);
}
// 重新实例化 notifiable
if (class_exists($notifiable_name)) {
$notifiable = new $notifiable_name();
$notifiables = $notifiable->where('id', 'in', array_column($notifiables, 'id'))->select();
}
// 发送消息
\addons\shopro\library\notify\Notify::sendNow($notifiables, $notification);
// 删除 job
$job->delete();
} catch (HttpResponseException $e) {
$data = $e->getResponse()->getData();
$message = $data ? ($data['msg'] ?? '') : $e->getMessage();
format_log_error($e, 'Notification.send.HttpResponseException', $message);
} catch (\Exception $e) {
format_log_error($e, 'Notification.send.' . ($notification->event ?? ''));
}
}
}