예제 #1
0
 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!'));
     }
 }