public function actionSubmitcomment()
 {
     $data = Yii::$app->request->post();
     $model = new User();
     $aa = $model->findBySql("select * from user where phone=" . $data['phone'])->all();
     $appcomment = new Appcomments();
     $appcomment->userid = $aa[0]['id'];
     $appcomment->userthumb = $aa[0]['thumb'];
     $appcomment->usernickname = $aa[0]['nickname'];
     $appcomment->commentstars = $data['commentstars'];
     $appcomment->comments = $data['comments'];
     $appcomment->title = $data['title'];
     $appcomment->created_at = time();
     $appcomment->appid = $data['appid'];
     //var_dump($appcomment);
     if ($appcomment->save()) {
         // 		$appl = new Appl ();
         // 		$appinfo = $appl->find ()->where ( [
         // 				'id' => $data ['appid']
         // 		] )->one ();
         $appinfo = Appl::findOne(['id' => $data['appid']]);
         $appinfo->stars = ($appinfo->stars * $appinfo->commentscount + $data['commentstars']) / ($appinfo->commentscount + 1);
         $appinfo['commentscount'] += 1;
         $appinfo->save();
         echo json_encode(array('flag' => 1, 'msg' => 'summit success!'));
     } else {
         echo json_encode(array('flag' => 0, 'msg' => 'summit failed!'));
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Appcomments::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     //$value = 0;
     if ($params != false && !empty($params['AppcommentsSearch'])) {
         //$b=$a;
         //=app::find()->where("name= :name",[':name'=>'QQ'])->one();
         //if()
         foreach ($params['AppcommentsSearch'] as $name => $value1) {
             if ($name === 'appid' && $value1 != null) {
                 $appinfo = app::findOne(['name' => $params['AppcommentsSearch']['appid']]);
                 $this->value = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->value = 0;
                 }
             }
             if ($name === 'userid' && $value1 != null) {
                 $appinfo = User::findOne(['phone' => $params['AppcommentsSearch']['userid']]);
                 $this->userinc = $appinfo['id'];
                 if ($appinfo == null) {
                     $this->userinc = 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(['appid' => $this->value, 'userid' => $this->userinc, 'commentstars' => $this->commentstars, 'created_at' => $this->created_at]);
     $query->andFilterWhere(['like', 'userthumb', $this->userthumb])->andFilterWhere(['like', 'usernickname', $this->usernickname])->andFilterWhere(['like', 'comments', $this->comments])->andFilterWhere(['like', 'title', $this->title]);
     return $dataProvider;
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAppcomments()
 {
     return $this->hasMany(Appcomments::className(), ['userid' => 'id']);
 }
 public function actionTestl()
 {
     echo "sss";
     $dataProvider = new ActiveDataProvider(['query' => Appcomments::find()]);
     //$dataProvider->keys;
     //$dataProvider->models;
     /*$dataProvider->setPagination(false);
     		$mymodel=$dataProvider->models;
     		foreach ($mymodel as $model){
     			echo $model['appid'];
     			
     		}*/
     $pagination = $dataProvider->getPagination();
     var_dump($pagination->page);
     $count = 0;
     while ($categories = $dataProvider->models) {
         /*foreach ($categories as $model) {
         			$model['appid']=0;
         		}*/
         //echo $pagination->page=1+$count;
         $count++;
         $dataProvider->setPagination($count);
     }
     //$mymodel[4]['kind']="bbbbbb";
     //$dataProvider->setModels($mymodel);
     //var_dump($dataProvider->models[4]['kind']);
     //echo $dataProvider->models;
 }
 /**
  * Finds the Appcomments model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * 
  * @param integer $id        	
  * @return Appcomments the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Appcomments::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }