Database.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace addons\shopro\channel;
  3. use addons\shopro\notification\Notification;
  4. use app\admin\model\shopro\notification\Notification as NotificationModel;
  5. class Database
  6. {
  7. public function __construct()
  8. {
  9. }
  10. /**
  11. * 发送 模板消息
  12. *
  13. * @param mixed $notifiable // 通知用户
  14. * @param 通知内容
  15. * @return void
  16. */
  17. public function send($notifiable, Notification $notification)
  18. {
  19. $data = [];
  20. if (method_exists($notification, 'toDatabase')) {
  21. $data = $notification->toDatabase($notifiable);
  22. $notificationModel = new NotificationModel();
  23. $notificationModel->id = \fast\Random::uuid();
  24. $notificationModel->notification_type = $notification->notification_type;
  25. $notificationModel->type = $notification->event;
  26. $notificationModel->notifiable_id = $notifiable['id'];
  27. $notificationModel->notifiable_type = $notifiable->getNotifiableType();
  28. $notificationModel->data = $data;
  29. $notificationModel->save();
  30. }
  31. return true;
  32. }
  33. }