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'); } }