auth->getUserInfo(); $list = \app\admin\model\notice\Notice::where('to_id', $user['id']) ->where('platform', 'admin') ->where('type','msg') ->order('id', 'desc') ->paginate(20); $config = get_addon_config('notice'); // 是否有未读的 $haveUnread = false; // 判断是否需要自动标记为已读 $auto_read = $config['auto_read'] ?? false; if ($auto_read) { \app\admin\model\notice\Notice::where('id', 'in',array_column($list->items(), 'id')) ->update(['readtime' => time()]); } else { foreach ($list->items() as $item) { if ($item['readtime'] === null) { $haveUnread = true; break; } } } $this->assign('haveUnread', $haveUnread); $this->assign('list', $list); $this->assign('title', '我的消息'); return $this->view->fetch(); } // 标记为已读 public function mark() { $user = $this->auth->getUserInfo(); $where = []; if (input('id')) { $where['id'] = input('id'); } $count = \app\admin\model\notice\Notice::where('to_id', $user['id']) ->where('platform', 'admin') ->where('type','msg') ->where($where) ->order('id', 'desc') ->whereNull('readtime') ->update(['readtime' => time()]); $this->success('', $count); } // 统计 public function statistical() { AdminLog::setIgnoreRegex('/./'); $user = $this->auth->getUserInfo(); $statisticalTime = Cache::get('notice_admin_statistical_time_'.$user['id'], 0); $new = \app\admin\model\notice\Notice::where('to_id', $user['id']) ->where('platform', 'admin') ->where('type','msg') ->order('id', 'desc') ->where('createtime','>', $statisticalTime) ->whereNull('readtime') ->find(); if ($new) { Cache::set('notice_admin_statistical_time_'.$user['id'], time()); } $noticeData = Service::getNoticeData(); $waitData = Service::getWaitData(); $data = [ 'num' => \app\admin\model\notice\Notice::where('to_id', $user['id']) ->where('platform', 'admin') ->where('type','msg') ->order('id', 'desc') ->whereNull('readtime') ->count() , 'new' => $new, 'notice_data' => $noticeData, 'wait_data' => $waitData, ]; $this->success('', '', $data); } }