Beispiel #1
0
 public function actionGetAppComment()
 {
     $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();
     }
     $app = AppInfoList::model()->findByPk($appID);
     if (empty($app)) {
         echo new ReturnInfo(RET_ERROR, 'Argument appid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not find a record.');
         Yii::app()->end();
     }
     $replies = AppReviews::model()->with('author_icon')->together()->findAll(array('select' => array('Id', 'Pid', 'Content', 'UpdateTime', 'AuthorName'), 'order' => 't.Id desc', 'condition' => 'AppId = :AppId', 'params' => array(':AppId' => $appID)));
     $appReply = array();
     if (!empty($replies)) {
         foreach ($replies as $reply) {
             if (!isset($appReply[$reply->Id])) {
                 $appReply[$reply->Id] = array('Id' => $reply->Id, 'Content' => $reply->Content, 'Pid' => $reply->Pid, 'AuthorName' => $reply->AuthorName, 'UpdateTime' => $reply->UpdateTime, 'AuthorIcon' => $reply->author_icon->Icon, 'children' => array());
             }
             if ($reply->Pid == 0) {
                 continue;
             } else {
                 if (isset($appReply[$reply->Pid])) {
                     $appReply[$reply->Pid]['children'][] = $appReply[$reply->Id];
                     unset($appReply[$reply->Id]);
                 } else {
                     $parentReply = AppReviews::model()->findByPk($reply->Pid);
                     $appReply[$parentReply->Id] = array('Id' => $parentReply->Id, 'Content' => $parentReply->Content, 'Pid' => $parentReply->Pid, 'AuthorName' => $parentReply->AuthorName, 'UpdateTime' => $parentReply->UpdateTime, 'AuthorIcon' => $parentReply->author_icon->Icon, 'children' => array());
                     $appReply[$parentReply->Id]['children'][] = $appReply[$reply->Id];
                     unset($appReply[$reply->Id]);
                 }
             }
         }
         //foreach
     }
     echo new ReturnInfo(RET_SUC, $appReply);
 }
 public function actionSearchUser()
 {
     $appID = Yii::app()->request->getParam('appID');
     $app = AppInfoList::model()->findByPk($appID);
     if (!$app instanceof AppInfoList) {
         throw new THttpException("操作错误");
     }
     $array = AppReviews::model()->findAll(array('select' => array('AuthorId'), 'distinct' => true, 'condition' => 'AppId = :AppId', 'params' => array(':AppId' => $appID)));
     $userArray = array();
     foreach ($array as $row) {
         $userArray[] = array('encode_name' => htmlspecialchars($row->author_icon->UserName), 'icon' => $row->author_icon->Icon, 'name' => $row->author_icon->UserName);
     }
     echo new ReturnInfo(RET_SUC, $userArray);
 }
Beispiel #3
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();
         }
     }
 }
Beispiel #4
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());
     }
 }
 public function actionGetAppComment()
 {
     $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();
     }
     $app = AppInfoList::model()->findByPk($appID);
     if (empty($app)) {
         echo new ReturnInfo(RET_ERROR, 'Argument appid passed to ' . __CLASS__ . '::' . __FUNCTION__ . '() that can not find a record.');
         Yii::app()->end();
     }
     $aReply = array();
     $replies = AppReviews::model()->with('author_icon')->together()->findAll(array('select' => array('Id', 'Pid', 'Content', 'UpdateTime', 'AuthorId', 'ToAuthorId'), 'order' => 't.Pid asc, t.UpdateTime desc', 'condition' => 'AppId = :AppId', 'params' => array(':AppId' => $appID)));
     if (!empty($replies)) {
         foreach ($replies as $single_reply) {
             $toAuthorNanme = '';
             if ($single_reply->ToAuthorId) {
                 $toAuthorNanme = htmlspecialchars($single_reply->toAuthor->UserName);
             }
             $replay_info = array('Id' => $single_reply->Id, 'Content' => $single_reply->Content, 'Pid' => $single_reply->Pid, 'AuthorName' => htmlspecialchars($single_reply->replyUser->UserName), 'UpdateTime' => AppInfoList::getPeriod($single_reply->UpdateTime), 'AuthorIcon' => $single_reply->author_icon->Icon, 'AuthorId' => $single_reply->AuthorId, 'ToAuthorID' => $single_reply->ToAuthorId, 'ToAuthorName' => $toAuthorNanme);
             if ($single_reply->Pid != 0) {
                 if (!isset($aReply[$single_reply->Pid])) {
                     $aReply[$single_reply->Pid] = array('children' => array($replay_info));
                 } else {
                     if (!isset($aReply[$single_reply->Pid]['children'])) {
                         $aReply[$single_reply->Pid]['children'] = array();
                     }
                     $aReply[$single_reply->Pid]['children'][] = $replay_info;
                 }
             } else {
                 if (!isset($aReply[$single_reply->Id])) {
                     $aReply[$single_reply->Id] = $replay_info;
                     $aReply[$single_reply->Id]['children'] = array();
                 } else {
                     $aReply[$single_reply->Id] = array_merge($aReply[$single_reply->Id], $replay_info);
                 }
             }
         }
     }
     foreach ($aReply as $key => $value) {
         if (!isset($value['Id']) || empty($value['Id'])) {
             unset($aReply[$key]);
         }
     }
     echo new ReturnInfo(RET_SUC, $aReply);
 }
Beispiel #6
0
 static function comment($appID, User $user, $content, $pid = 0, $toAuthorID = 0)
 {
     $userID = $user->ID;
     $reviews = new AppReviews();
     $reviews->Content = $content;
     $reviews->AppId = $appID;
     $reviews->AuthorId = $userID;
     $reviews->Pid = $pid;
     $reviews->ToAuthorId = $toAuthorID;
     $reviews->Status = 0;
     $reviews->UpdateTime = date('Y-m-d H:i:s');
     if ($reviews->save()) {
         return $reviews->Id;
     } else {
         throw new CDbException('系统繁忙,请稍后再试');
     }
 }