SystemMsgJob.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\jobs\notice;
  12. use app\services\message\SystemMessageServices;
  13. use crmeb\basic\BaseJobs;
  14. use crmeb\traits\QueueTrait;
  15. use think\facade\Log;
  16. /**
  17. * 站内信
  18. * Class SystemMsgJob
  19. * @package app\jobs\notice
  20. */
  21. class SystemMsgJob extends BaseJobs
  22. {
  23. use QueueTrait;
  24. /**
  25. * 发送站内信
  26. * @param $uid
  27. * @param $noticeInfo
  28. * @param $data
  29. * @param $type
  30. * @return bool
  31. */
  32. public function doJob($uid, $noticeInfo, $data, $type = 1)
  33. {
  34. if (!$uid || !$noticeInfo) {
  35. return true;
  36. }
  37. try {
  38. $title = $noticeInfo['system_title'];
  39. $str = $noticeInfo['system_text'];
  40. foreach ($data as $key => $item) {
  41. $str = str_replace('{' . $key . '}', $item, $str);
  42. $title = str_replace('{' . $key . '}', $item, $title);
  43. }
  44. $sdata = [];
  45. $sdata['mark'] = $noticeInfo['mark'];
  46. $sdata['uid'] = $uid;
  47. $sdata['content'] = $str;
  48. $sdata['title'] = $title;
  49. $sdata['type'] = $type;
  50. $sdata['add_time'] = time();
  51. /** @var SystemMessageServices $systemMessageServices */
  52. $systemMessageServices = app()->make(SystemMessageServices::class);
  53. $systemMessageServices->save($sdata);
  54. } catch (\Throwable $e) {
  55. Log::error('发送站内信失败,原因:' . $e->getMessage());
  56. }
  57. return true;
  58. }
  59. }