order('id desc')->paginate($limit); $items = $records->items(); foreach ($items as $k => $v) { $read_staff_ids = explode(',', $v['read_staff_ids']); $v['is_show'] = in_array($this->auth->id, $read_staff_ids); $items[$k] = $v; } $this->success('请求成功', $records); } //获取公告详情 public function getDetail() { $id = input('id', '', 'intval'); $notice = NoticeModel::where(['id' => $id,])->find(); if (empty($notice)) { $this->error('公告不存在'); } preg_match_all('//i',$notice['content'],$match); foreach ($match[1] as $v){ $notice['content']=str_replace($v,cdnurl($v,true),$notice['content']); } $read_staff_ids = explode(',', $notice['read_staff_ids']); if (!in_array($this->auth->id, $read_staff_ids)) { $read_staff_ids[] = $this->auth->id; NoticeModel::where(['id' => $notice['id']])->update(['read_staff_ids' => implode(',', $read_staff_ids).',']); } $this->success('请求成功', $notice); } }