Notice.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace addons\qingdong\controller;
  3. use addons\qingdong\model\Notice as NoticeModel;
  4. /**
  5. * 公告接口
  6. */
  7. class Notice extends StaffApi {
  8. protected $noNeedLogin = [];
  9. protected $noNeedRight = [];
  10. //公告列表
  11. public function getList() {
  12. $limit = input("limit/d", 10);
  13. $records = NoticeModel::where([])->order('id desc')->paginate($limit);
  14. $items = $records->items();
  15. foreach ($items as $k => $v) {
  16. $read_staff_ids = explode(',', $v['read_staff_ids']);
  17. $v['is_show'] = in_array($this->auth->id, $read_staff_ids);
  18. $items[$k] = $v;
  19. }
  20. $this->success('请求成功', $records);
  21. }
  22. //获取公告详情
  23. public function getDetail() {
  24. $id = input('id', '', 'intval');
  25. $notice = NoticeModel::where(['id' => $id,])->find();
  26. if (empty($notice)) {
  27. $this->error('公告不存在');
  28. }
  29. preg_match_all('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/i',$notice['content'],$match);
  30. foreach ($match[1] as $v){
  31. $notice['content']=str_replace($v,cdnurl($v,true),$notice['content']);
  32. }
  33. $read_staff_ids = explode(',', $notice['read_staff_ids']);
  34. if (!in_array($this->auth->id, $read_staff_ids)) {
  35. $read_staff_ids[] = $this->auth->id;
  36. NoticeModel::where(['id' => $notice['id']])->update(['read_staff_ids' => implode(',', $read_staff_ids).',']);
  37. }
  38. $this->success('请求成功', $notice);
  39. }
  40. }