You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.3 KiB

<?php
namespace app\api\controller;
use app\common\controller\Api;
/**
* 首页接口
*/
class News extends Api
{
protected $noNeedLogin = ['*'];
protected $noNeedRight = ['*'];
protected $news = null;
public function _initialize()
{
parent::_initialize();
$this->news = new \app\admin\model\News;
}
/**
* get news list
*
*/
public function getNews()
{
$page = (int)$this->request->request('page');
$limit = (int)$this->request->request('limit',10);
$where = [];
$where['status'] = 'Live';
$page = max(1, $page);
$exp = new \think\db\Expression("sort!=0 desc,sort,publishedtime desc");
$list = $this->news->where($where)->order($exp)->paginate($limit);
$this->success('Request succeeded',$list);
}
/**
* view research
*
*/
public function clickNews()
{
$news_id = (int)$this->request->request('news_id',0);
if(!$news_id){
$this->error('Parameter error');
}
$where = [];
$where['id'] = $news_id;
$info = $this->news->where($where)->find();
if(!$info){
$this->error('News does not exist');
}
$this->news->where($where)->setInc('clicks',1);
$this->success('Request succeeded',$info);
}
}