Blame view

addons/antis/controller/Notice.php 1.41 KB
2db47680   hexiaodong   chore: 初始提交 php 遗...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
  <?php

  

  namespace addons\antis\controller;

  

  use addons\antis\model\Notice as NoticeModel;

  

  /**

   * 公告接口

   */

  class Notice extends StaffApi {

  	protected $noNeedLogin = [];

  	protected $noNeedRight = [];

  

  

  	//公告列表

  	public function getList() {

  		$limit = input("limit/d", 10);

  

  

  		$records = NoticeModel::where([])->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('/<img.+src=\"?(.+\.(jpg|gif|bmp|bnp|png))\"?.+>/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);

  	}

  

  

  }