/** * 为帖子投票 * Enter description here ... * @param unknown_type $postid * @param unknown_type $value */ public function actionPost($postid = 0, $value = 0) { if ($postid) { //$vote = new PostVote; $vote = PostVote::model()->findByAttributes(array('userId' => Yii::app()->user->id, 'postid' => $postid)); if ($vote && $vote->value == $value) { $result = $vote->delete(); } else { $vote or $vote = new PostVote(); $vote->postid = $postid; $vote->value = $value; $vote->userId = Yii::app()->user->id; $vote->addTime = time(); $result = $vote->save(); } if ($result) { $post = Post::model()->with('voteupCount', 'votedownCount')->findByPk($vote->postid); $post->updateVoteCount(); $score = $post->voteupCount - $post->votedownCount; $this->renderPartial('result', array('score' => $score, 'voteupers' => $post->voteupers)); } } }