コード例 #1
0
ファイル: AjaxController.php プロジェクト: ph7pal/wedding
 /**
  * 问题的赞成反对及其他点赞
  */
 public function actionFavor()
 {
     Users::checkPower('favor');
     $type = zmf::filterInput($_POST['type'], 't', 1);
     $keyid = zmf::filterInput($_POST['keyid']);
     if (!$keyid) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     }
     if (!isset($type) or empty($type) or !in_array($type, array('post', 'image', 'poipost', 'poitips', 'answer', 'dislike-answer', 'goods'))) {
         //Forbidden::updateTimes();
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (zmf::actionLimit('favor-' . $type, $keyid)) {
         $this->jsonOutPut(0, '操作太频繁,请稍后再试');
     }
     if ($type == 'image') {
         $classify = 'favorImg';
         $model = new Attachments();
         $field = 'favor';
     } elseif ($type == 'post') {
         $classify = 'favorPost';
         $model = new Posts();
         $field = 'favors';
     } elseif ($type == 'poipost') {
         $classify = 'favorPoiPost';
         $model = new PoiPost();
         $field = 'favor';
     } elseif ($type == 'poitips') {
         $classify = 'favorPoiTips';
         $model = new PoiTips();
         $field = 'favor';
     } elseif ($type == 'answer') {
         $classify = 'favorAnswer';
         $model = new Answer();
         $field = 'favor';
     } elseif ($type == 'dislike-answer') {
         $classify = 'dislikeAnswer';
         $model = new Answer();
         $field = 'nouse';
     } elseif ($type == 'goods') {
         $classify = 'goods';
         $model = new Goods();
         $field = 'favors';
     }
     if (!$model) {
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     $info = $model->findByPk($keyid);
     if (!$info) {
         $this->jsonOutPut(0, Yii::t('default', 'pagenotexists'));
     } elseif ($info['status'] != Posts::STATUS_PASSED) {
         $this->jsonOutPut(0, '您操作的内容正在审核或已删除');
     } elseif ($info['uid'] == zmf::uid()) {
         $this->jsonOutPut(0, '不能操作自己的哦~');
     }
     if ($type == 'answer' || $type == 'dislike-answer') {
         if ($type == 'answer') {
             if (UserAction::checkAction($keyid, 'dislikeAnswer')) {
                 UserAction::delAction($keyid, 'dislikeAnswer');
                 $model->updateCounters(array('nouse' => -1), 'id=:id', array(':id' => $keyid));
             }
         } else {
             if (UserAction::checkAction($keyid, 'favorAnswer')) {
                 UserAction::delAction($keyid, 'favorAnswer');
                 $model->updateCounters(array('favor' => -1), 'id=:id', array(':id' => $keyid));
             }
         }
     }
     if (UserAction::checkAction($keyid, $classify)) {
         if (UserAction::delAction($keyid, $classify)) {
             if ($field) {
                 $model->updateCounters(array($field => -1), 'id=:id', array(':id' => $keyid));
             }
             $this->jsonOutPut(3, '取消赞成功');
         } else {
             $this->jsonOutPut(0, '取消赞失败');
         }
     } else {
         if (UserAction::recordAction($keyid, $classify, $info['uid'])) {
             if ($field) {
                 $model->updateCounters(array($field => 1), 'id=:id', array(':id' => $keyid));
             }
             $this->jsonOutPut(1, '添加赞成功');
         } else {
             $this->jsonOutPut(0, '添加赞失败');
         }
     }
 }