控制层
public function activityList(Request $request) { // 接收检索条件 $title = $request->param('title'); $status = $request->param('status'); $startTime = $request->param('start_time'); $endTime = $request->param('end_time', time()); $where = array(); if($title) { $where[] = array('title', 'like', "%$title%"); } if(isset($status)) { $where[] = array('status', '=', $status); } if($startTime) { $where[] = array('create_time', '>=', $startTime); } if($endTime) { $where[] = array('create_time', '<=', $endTime); } $stdData = array(); $activity = new Activity(); $list = $activity->getList($where); $stdData = $list; return success('200', 'success', $stdData); }
模型层
public function getList($where) { if($where) { return self::where($where)->order('sort', 'desc')->select()->toArray(); } return self::order('sort', 'desc')->select()->toArray(); }
或者调用模型也可以
控制器层
模型层