Notice.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Niucloud-admin 企业快速开发的saas管理平台
  4. // +----------------------------------------------------------------------
  5. // | 官方网址:https://www.niucloud.com
  6. // +----------------------------------------------------------------------
  7. // | niucloud团队 版权所有 开源版本可自由商用
  8. // +----------------------------------------------------------------------
  9. // | Author: Niucloud Team
  10. // +----------------------------------------------------------------------
  11. namespace app\job\notice;
  12. use core\base\BaseJob;
  13. use core\exception\NoticeException;
  14. /**
  15. * 消息发送任务
  16. */
  17. class Notice extends BaseJob
  18. {
  19. /**
  20. * 消费
  21. * @param $site_id
  22. * @param $key
  23. * @param $data
  24. * @param $template
  25. * @return true
  26. */
  27. protected function doJob($key, $data, $template)
  28. {
  29. //通过业务获取模板变量属于以及发送对象
  30. $result = event('NoticeData', [ 'key' => $key, 'data' => $data, 'template' => $template ]);
  31. $notice_data = array_values(array_filter($result))[ 0 ] ?? [];
  32. if (empty($notice_data)) throw new NoticeException('NOTICE_TEMPLATE_IS_NOT_EXIST');
  33. event('Notice', [ 'key' => $key, 'to' => $notice_data[ 'to' ], 'vars' => $notice_data[ 'vars' ], 'template' => $template ]);
  34. return true;
  35. }
  36. }