Beispiel #1
0
 /**
  * 问题的赞成反对及其他点赞
  */
 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('naodong'))) {
         //Forbidden::updateTimes();
         $this->jsonOutPut(0, Yii::t('default', 'forbiddenaction'));
     }
     if (zmf::actionLimit('favor-' . $type, $keyid)) {
         $this->jsonOutPut(0, '操作太频繁,请稍后再试');
     }
     if ($type == 'naodong') {
         $classify = 'favorNaodong';
         $model = new Naodong();
         $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 (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) {
                 if ($model->updateCounters(array($field => 1), 'id=:id', array(':id' => $keyid))) {
                     if ($type == 'naodong') {
                         $_url = CHtml::link('查看详情', array('index/view', 'id' => $keyid));
                         $_content = '您的作品有了新的赞,' . $_url;
                         $toNotice = true;
                     }
                     if ($toNotice) {
                         $_noticedata = array('uid' => $info['uid'], 'authorid' => $this->uid, 'content' => $_content, 'new' => 1, 'type' => 'favor', 'cTime' => zmf::now(), 'from_id' => $keyid, 'from_num' => 1);
                         Notification::add($_noticedata);
                     }
                 }
             }
             $this->jsonOutPut(1, '添加赞成功');
         } else {
             $this->jsonOutPut(0, '添加赞失败');
         }
     }
 }