コード例 #1
0
ファイル: Comments.php プロジェクト: fu-tao/meelier_c2.0
 public function run()
 {
     if (!$this->verifyUserAuth()) {
         return false;
     }
     $id = intval($this->getDataItem('id', 0));
     $user_id = intval($this->getDataItem('user_id', 0));
     $content = $this->getDataItem('content', '');
     if ($id == 0 || $user_id == 0) {
         $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'URL参数不全');
         return false;
     }
     $contentLenth = $this->utf8_strlen($content);
     if ($contentLenth < 1 || $contentLenth > 100) {
         $this->errorLog(ResultStatus::POST_BODY_FORMAT_ERROR, '评论字符应在1~100之间.');
         return false;
     }
     $ActivityComment = new ActivityComment();
     $date = date('Y-m-d H:i:s');
     $data = ['comment_user_id' => $user_id, 'comment_content' => $content, 'addtime' => $date, 'activity_id' => $id];
     if ($ActivityComment->save($data)) {
         $ActivityComment->getReadConnection()->query("UPDATE activity SET comments = comments + 1 WHERE activity_id = {$id}");
         $userInfo = UserBase::getOne($user_id);
         $this->setResult(['comment_id' => $ActivityComment->comment_id, 'user_id' => $user_id, 'comment_content' => $content, 'addtime' => $date, 'user_gender' => $userInfo['user_gender'], 'user_cover' => PicUrl::ActivityCover($userInfo['user_cover'], $this->getDi())]);
     } else {
         $this->errorLog(ResultStatus::ERROR, '评论失败.');
     }
 }
コード例 #2
0
ファイル: GetComments.php プロジェクト: fu-tao/meelier_c2.0
 public function run()
 {
     $id = intval($this->getDataItem('id', 0));
     $page = intval($this->getDataItem('page', 1));
     $limit = $this->getConfig()->limit;
     if ($id == 0) {
         return $this->errorLog(ResultStatus::URL_PARAM_CANNOT_EMPTY, 'URL参数不全');
     }
     $list = ActivityComment::query()->columns(['comment_id', 'comment_content', 'addtime', 'comment_user_id user_id', 'u.user_nickname', 'u.user_gender', 'u.user_cover'])->leftJoin('\\Apps\\Common\\Models\\UserBase', 'u.user_id = \\Apps\\Common\\Models\\ActivityComment.comment_user_id', 'u')->where('activity_id = ' . $id)->orderBy('addtime DESC')->limit($limit, ($page - 1) * $limit)->execute()->toArray();
     foreach ($list as $k => $val) {
         $list[$k]['user_cover'] = PicUrl::ActivityCover($val['user_cover'], $this->getDi());
     }
     $this->setResult($list);
 }
コード例 #3
0
 /**
  * 活动预览
  * @date: 2016年1月12日 
  * @author: chenxiaolin
  */
 public function activityPreviewAction()
 {
     $id = $this->request->getQuery('id');
     if (empty($id)) {
         echo '活动不存在!';
         $this->view->disable();
         return;
     }
     //活动内容
     $date = date('Y-m-d H:i:s');
     $activity = Activity::query()->columns(['Apps\\Common\\Models\\Activity.activity_id', 'activity_title', 'activity_cover', 'activity_intro', 'out_link', 'activity_addtime', 'views', 'comments'])->where("activity_id = {$id} and activity_state in (0,1)")->execute()->getFirst();
     if (!$activity) {
         echo '活动不存在!';
         $this->view->disable();
         return;
     } else {
         $activity = $activity->toArray();
     }
     $activity['activity_cover'] = PicUrl::ActivityCover($activity['activity_cover'], $this->getDI());
     //活动回复
     $comment = ActivityComment::query()->columns(['comment_content', 'user.user_nickname', 'user.user_cover', 'user.user_gender'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\ActivityComment.comment_user_id = user.user_id', 'user')->where("Apps\\Common\\Models\\ActivityComment.activity_id = {$id} and Apps\\Common\\Models\\ActivityComment.state = 1")->order('addtime desc')->execute()->toArray();
     foreach ($comment as $k => $v) {
         $comment[$k]['user_cover'] = PicUrl::UserCover($comment[$k]['user_cover'], $this->getDI());
     }
     $lastTime = ActivityComment::maximum(array("activity_id = {$id} and state = 1", 'column' => 'addtime'));
     //美人儿已阅处显示的头像
     $covers = ActivityComment::query()->columns(['distinct comment_user_id', 'user.user_cover'])->leftJoin('Apps\\Common\\Models\\UserBase', 'Apps\\Common\\Models\\ActivityComment.comment_user_id = user.user_id', 'user')->where("Apps\\Common\\Models\\ActivityComment.activity_id = {$id} and Apps\\Common\\Models\\ActivityComment.state = 1")->order('addtime desc')->limit(7)->execute()->toArray();
     foreach ($covers as $k => $v) {
         $covers[$k]['user_cover'] = PicUrl::UserCover($covers[$k]['user_cover'], $this->getDI());
     }
     $this->view->setVar('activity', $activity);
     $this->view->setVar('comment', $comment);
     $this->view->setVar('lastTime', $lastTime);
     $this->view->setVar('covers', $covers);
     $this->tag->setTitle($activity->activity_title);
 }
コード例 #4
0
 /**
  * 删除活动回复
  * @date: 2016年1月6日 
  * @author: chenxiaolin
  */
 public function setCommentStateAction()
 {
     $req = $this->request;
     if ($req->isPost()) {
         $id = intval($req->getPost('id', null, 0));
         $activity_id = $req->getPost('activity_id');
         $state = intval($req->getPost('state', null, -10000));
         $info = ActivityComment::findFirst('comment_id = ' . $id);
         $activity = Activity::findFirst("activity_id = {$activity_id}");
         if ($info && $activity) {
             try {
                 $this->db->begin();
                 $info->update(['state' => $state]);
                 $comments = $activity->comments - 1;
                 $activity->update(['comments' => $comments]);
                 $this->db->commit();
             } catch (Exception $e) {
                 $this->db->rollback();
             }
         }
         return (new ResponseResult())->sendResult('ok');
     } else {
         return (new ResponseResult())->sendError(ResponseResultStatus::PARAM_CANNOT_EMPTY, '请求异常');
     }
 }