News.php
980 Bytes
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
<?php
namespace addons\exam\controller;
use addons\exam\enum\CommonStatus;
use addons\exam\model\NewsModel;
/**
* 资讯接口
*/
class News extends Base
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $user;
/**
* 列表
*/
public function index()
{
$list = NewsModel::where('status', CommonStatus::NORMAL)
->field('id, cover_image, images, name, createtime')
->order('weigh desc')
->paginate(15, true);
$this->success('', ['list' => $list]);
}
/**
* 详情
*/
public function detail()
{
if (!$id = input('id/d', '0')) {
$this->error('缺少资讯ID');
}
if (!$news = NewsModel::where('id', $id)->where('status', CommonStatus::NORMAL)->find()) {
$this->error('资讯信息不存在');
}
$this->success('', $news);
}
}