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.

62 lines
1.3 KiB

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