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.
71 lines
1.8 KiB
71 lines
1.8 KiB
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
|
|
/**
|
|
* 首页接口
|
|
*/
|
|
class Hackathon extends Api
|
|
{
|
|
protected $noNeedLogin = ['*'];
|
|
protected $noNeedRight = ['*'];
|
|
protected $hackathon = null;
|
|
|
|
public function _initialize()
|
|
{
|
|
parent::_initialize();
|
|
$this->hackathon = new \app\admin\model\Hackathon;
|
|
}
|
|
|
|
|
|
/**
|
|
* get news list
|
|
*
|
|
*/
|
|
public function getHackathon()
|
|
{
|
|
$status= (string)$this->request->request('status',0);
|
|
$page = (int)$this->request->request('page');
|
|
$limit = (int)$this->request->request('limit',10);
|
|
|
|
$where = [];
|
|
$page = max(1, $page);
|
|
|
|
if($status){
|
|
$where['status'] = $status;
|
|
$exp = new \think\db\Expression("sort!=0 desc,sort,endtime desc");
|
|
$list = $this->hackathon->where($where)->order($exp)->paginate($limit);
|
|
}else{
|
|
//sort Ongoing>Upcoming>Past
|
|
$exp = new \think\db\Expression("field(status,'Ongoing','Upcoming','Past') asc,sort!=0 desc,sort,endtime desc");
|
|
$list = $this->hackathon->where($where)->order($exp)->paginate($limit);
|
|
}
|
|
$this->success('Request succeeded',$list);
|
|
}
|
|
|
|
/**
|
|
* view research
|
|
*
|
|
*/
|
|
public function clickHackathon()
|
|
{
|
|
$hackathon_id = (int)$this->request->request('hackathon_id',0);
|
|
if(!$hackathon_id){
|
|
$this->error('Parameter error');
|
|
}
|
|
|
|
$where = [];
|
|
$where['id'] = $hackathon_id;
|
|
$info = $this->hackathon->where($where)->find();
|
|
if(!$info){
|
|
$this->error('News does not exist');
|
|
}
|
|
|
|
$this->hackathon->where($where)->setInc('clicks',1);
|
|
|
|
$this->success('Request succeeded');
|
|
}
|
|
}
|