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 a new Appcomments model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * 
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Appcomments();
     $data = Yii::$app->request->post();
     if ($data != false) {
         $userinfo = User::findOne(['phone' => $data['Appcomments']['userid']]);
         $appinfo = app::findOne(['name' => $data['Appcomments']['appid']]);
         $model->appid = (string) $appinfo['id'];
         $model->userid = $userinfo['id'];
         $model->usernickname = $userinfo['nickname'];
         $model->userthumb = $userinfo['thumb'];
         $model->created_at = (string) time();
         $model->title = $data['Appcomments']['title'];
         $model->commentstars = $data['Appcomments']['commentstars'];
         $model->comments = $data['Appcomments']['comments'];
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }