Notice.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace app\index\controller;
  3. use app\common\controller\Frontend;
  4. /**
  5. * 消息通知
  6. * Class Notice
  7. */
  8. class Notice extends Frontend
  9. {
  10. protected $layout = 'default';
  11. protected $noNeedRight = ['*'];
  12. public function index()
  13. {
  14. $user = $this->auth->getUser();
  15. $list = \app\admin\model\notice\Notice::where('to_id', $user['id'])
  16. ->where('platform', 'user')
  17. ->where('type','msg')
  18. ->order('id', 'desc')
  19. ->paginate(20);
  20. $config = get_addon_config('notice');
  21. // 是否有未读的
  22. $haveUnread = false;
  23. // 判断是否需要自动标记为已读
  24. $auto_read = $config['auto_read'] ?? false;
  25. if ($auto_read) {
  26. \app\admin\model\notice\Notice::where('id', 'in',array_column($list->items(), 'id'))
  27. ->update(['readtime' => time()]);
  28. } else {
  29. foreach ($list->items() as $item) {
  30. if ($item['readtime'] === null) {
  31. $haveUnread = true;
  32. break;
  33. }
  34. }
  35. }
  36. $this->assign('haveUnread', $haveUnread);
  37. $this->assign('list', $list);
  38. $this->assign('title', '我的消息');
  39. return $this->fetch();
  40. }
  41. }