Exemplo n.º 1
0
 public function getSchools()
 {
     $key = Input::get('key', '');
     $province = Input::get('province', '');
     $city = Input::get('city', '');
     try {
         $query = \DicSchool::where('t_type', '=', '1');
         if ($key) {
             $query = $query->where('t_name', 'LIKE', '%' . $key . '%');
         }
         if ($province) {
             $query = $query->where('t_province', '=', $province);
         }
         if ($city) {
             $query = $query->where('t_city', '=', $city);
         }
         $list = $query->orderBy('t_name')->get();
         $data = [];
         foreach ($list as $key => $school) {
             $data[] = $school->showInList();
         }
         $paginate = ['total_record' => $list->count(), 'total_page' => 1, 'per_page' => $list->count(), 'current_page' => 1];
         $re = ['result' => 2000, 'data' => $data, 'info' => '获取学校成功', 'pagination' => $paginate];
     } catch (Exception $e) {
         $re = ['result' => 2001, 'data' => [], 'info' => '获取学校失败:' . $e->getMessage()];
     }
     return Response::json($re);
 }