public function actionSearch()
 {
     Url::remember();
     //记录当前页,为更新数据后还是跳转到当前页做记录
     $request = Yii::$app->request;
     $query = Yii::$app->session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = $request->post('content');
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'testLibraryId':
                 $query = TestLibrary::find()->where(['testLibraryId' => $content]);
                 break;
             case 'testType':
                 $table_a = TestLibrary::tableName();
                 $table_b = TestType::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.testTypeId={$table_b}.testTypeId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'province':
                 $table_a = TestLibrary::tableName();
                 $table_b = Province::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.provinceId={$table_b}.provinceId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'majorJob':
                 $table_a = TestLibrary::tableName();
                 $table_b = MajorJob::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.majorJobId={$table_b}.majorJobId")->where(['like', $table_b . ".name", $content]);
                 break;
             case 'testChapter':
                 $table_a = TestLibrary::tableName();
                 $table_b = TestChapter::tableName();
                 $query = TestLibrary::find()->leftJoin($table_b, "{$table_a}.testChapterId={$table_b}.testChapterId")->where(['like', $table_b . ".name", $content]);
                 break;
             case 'question':
             case 'problem':
             case 'options':
                 $query = TestLibrary::find()->where(['like', $type, $content]);
                 break;
             default:
                 $query = TestLibrary::find();
                 break;
         }
     }
     Yii::$app->session->setFlash('query', $query);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $model = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['models' => $model, 'pages' => $pagination]);
 }
 public function actionSearch()
 {
     $request = Yii::$app->request;
     $query = Yii::$app->session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = trim($request->post('content'));
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'province':
                 $table_a = Users::tableName();
                 $table_b = Province::tableName();
                 $query = Users::find()->leftJoin($table_b, "{$table_a}.provinceId={$table_b}.provinceId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'majorJob':
                 $table_a = Users::tableName();
                 $table_b = MajorJob::tableName();
                 $query = Users::find()->leftJoin($table_b, "{$table_a}.majorJobId={$table_b}.majorJobId")->where(['like', $table_b . ".name", $content]);
                 break;
             case 'nickname':
             case 'cellphone':
                 $query = Users::find()->where(['like', $type, $content]);
                 break;
             default:
                 $query = Users::find();
                 break;
         }
         $query = $query->andWhere('weixin is not null');
         //添加微信用户条件,位置不可改
     }
     Yii::$app->session->setFlash('query', $query);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $user = $query->offset($pagination->offset)->limit($pagination->limit)->orderBy(['registerDate' => SORT_DESC])->all();
     return $this->render('index', ['users' => $user, 'pages' => $pagination]);
 }
 public function actionSearch()
 {
     $request = Yii::$app->request;
     $query = Yii::$app->session->getFlash('query');
     if ($request->isPost) {
         $type = $request->post('type');
         $content = trim($request->post('content'));
     } else {
         $type = $request->get('type');
         $content = trim($request->get('content'));
     }
     if ($type || !$query) {
         switch ($type) {
             case 'province':
                 $table_a = ExamTemplate::tableName();
                 $table_b = Province::tableName();
                 $query = ExamTemplate::find()->leftJoin($table_b, "{$table_a}.provinceId={$table_b}.provinceId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'majorJob':
                 $table_a = ExamTemplate::tableName();
                 $table_b = MajorJob::tableName();
                 $query = ExamTemplate::find()->leftJoin($table_b, "{$table_a}.majorJobId={$table_b}.majorJobId")->where(['like', "{$table_b}.name", $content]);
                 break;
             case 'name':
             case 'state':
                 $query = ExamTemplate::find()->where(['like', $type, $content]);
                 break;
             default:
                 $query = ExamTemplate::find();
                 break;
         }
     }
     Yii::$app->session->setFlash('query', $query);
     $pagination = new Pagination(['defaultPageSize' => Yii::$app->params['pageSize'], 'totalCount' => $query->count()]);
     $examTemplates = $query->offset($pagination->offset)->limit($pagination->limit)->all();
     return $this->render('index', ['examTemplates' => $examTemplates, 'pages' => $pagination]);
 }