/**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Judge::find()->join('INNER JOIN', 'user', 'judge.userid=user.id');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if ($params != false && !empty($params['JudgeSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['JudgeSearch'] as $name => $value1) {
             if ($name === 'userid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['JudgeSearch']['userid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
         }
     }
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'userid' => $this->value, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'message', $this->message]);
     if (isset($params['JudgeSearch']) && isset($params['JudgeSearch']['usernickname'])) {
         $query->andFilterWhere(['like', 'user.nickname', $params['JudgeSearch']['usernickname']]);
     }
     return $dataProvider;
 }
 /**
  * Finds the Judge model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Judge the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Judge::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionJudge()
 {
     $data = Yii::$app->request->post();
     $phone = User::findOne(['phone' => $data['phone']]);
     $model = new Judge();
     if ($data != false) {
         $model->userid = $phone->id;
         $model->message = $data['message'];
         $model->created_at = time();
         if ($model->save()) {
             echo json_encode(array('flag' => 1, 'msg' => 'Judge success!'));
         } else {
             echo json_encode(array('flag' => 0, 'msg' => 'Judge failed!'));
         }
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'Judge failed!'));
     }
 }