Esempio n. 1
0
 public function actionFakeComment()
 {
     $this->_log->setLogFile('comment.log');
     if ($this->_isFake(self::COMMENT_NUM_MIN, self::COMMENT_NUM_MAX)) {
         $commentApp = $this->_getRandomApp();
         if (!$commentApp) {
             return;
         }
         $commentedFakeUser = $this->_getCommentedUser($commentApp->Id);
         $userId = $this->_getRandomUserId($commentedFakeUser);
         $user = User::model()->findByPk($userId);
         $comment = $this->_getRandomComment($commentApp->PushId);
         if (!$comment) {
             return;
         }
         $transaction = Yii::app()->db->beginTransaction();
         try {
             $date = date('Y-m-d H:i:s');
             $result = AppReviews::comment($commentApp->Id, $user, $comment->Content);
             $comment->Used = 1;
             if (!$comment->save() || !$result) {
                 throw new Exception();
             }
             $this->_log->log('userId#' . $userId . '#于#' . $date . '#评论App PushId#' . $commentApp->PushId . '#,评论ID为#' . $comment->Id . '#评论内容为#' . $comment->Content . '#');
             $transaction->commit();
         } catch (Exception $e) {
             $transaction->rollBack();
         }
     }
 }
Esempio n. 2
0
 public function actionComment()
 {
     $appID = Yii::app()->request->getParam('appID');
     $content = Yii::app()->request->getParam('content');
     $replayId = Yii::app()->request->getParam('replayId', 0);
     if (!Yii::app()->request->isPostRequest || empty($content) || empty($appID)) {
         throw new THttpException('评论失败');
     }
     $app = AppInfoList::model()->findByPk($appID);
     if (!$app instanceof AppInfoList) {
         throw new THttpException('评论失败');
     }
     //被回复的评论
     $pid = 0;
     $toAuthorID = 0;
     if ($replayId) {
         $replay = AppReviews::model()->findByPk($replayId);
         if (!$replay instanceof AppReviews) {
             throw new THttpException('评论失败');
         }
         if ($replay->Pid) {
             $pid = $replay->Pid;
         } else {
             $pid = $replay->Id;
         }
         if ($replay->AuthorId) {
             $toAuthorID = $replay->AuthorId;
         }
     }
     if ($toAuthorID) {
         $toAuthor = User::model()->findByPk($toAuthorID);
         if (!$toAuthor instanceof User) {
             throw new THttpException('评论失败');
         }
     }
     $userID = Yii::app()->user->id;
     $user = User::model()->findByPk($userID);
     if (!$user instanceof User || $userID == $toAuthorID) {
         throw new THttpException('评论失败');
     }
     $content = AppReviews::filterComment($content);
     $id = AppReviews::comment($app->Id, $user, $content, $pid, $toAuthorID);
     if ($id) {
         $return = array();
         $return['id'] = $id;
         $return['pid'] = $pid;
         $return['authorID'] = $userID;
         $return['content'] = $content;
         $return['username'] = htmlspecialchars($user->UserName);
         $return['authorIcon'] = $user->Icon;
         $return['toAuthorID'] = $toAuthorID;
         $return['toAuthorUserName'] = $toAuthorID ? htmlspecialchars($toAuthor->UserName) : '';
         echo new ReturnInfo(RET_SUC, $return);
     }
 }
Esempio n. 3
0
 public function actionReplyComment()
 {
     if (!Yii::app()->request->isPostRequest) {
         echo new ReturnInfo(RET_ERROR, 'Data request error,post please.');
         Yii::app()->end();
     }
     $content = Yii::app()->getRequest()->getQuery('content');
     if (empty($content)) {
         echo new ReturnInfo(RET_ERROR, 'Argument content passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not be empty.');
         Yii::app()->end();
     }
     $appID = Yii::app()->getRequest()->getQuery('appID');
     if (empty($appID)) {
         echo new ReturnInfo(RET_ERROR, 'Argument appID passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not be empty.');
         Yii::app()->end();
     }
     $pid = Yii::app()->getRequest()->getQuery('pid');
     if (empty($pid)) {
         echo new ReturnInfo(RET_ERROR, 'Argument pid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not be empty.');
         Yii::app()->end();
     }
     $app = AppInfoList::model()->findByPk($appID);
     if (!$app instanceof AppInfoList) {
         echo new ReturnInfo(RET_ERROR, 'Argument appID passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not find a record.');
         Yii::app()->end();
     }
     $reply = AppReviews::model()->findByPk($pid);
     if (!$reply instanceof AppReviews) {
         echo new ReturnInfo(RET_ERROR, 'Argument pid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not find a record.');
         Yii::app()->end();
     }
     try {
         AppReviews::comment($app->Id, $this->apiUser, $content, $pid);
         $return = array();
         $return['content'] = $content;
         $return['username'] = $this->apiUser->UserName;
         echo new ReturnInfo(RET_SUC, $return);
     } catch (Exception $e) {
         echo new ReturnInfo(RET_ERROR, $e->getMessage());
     }
 }