IndexAction::postSet PHP Method

postSet() public method

设置帖子类型(置顶或精华)
public postSet ( )
    public function postSet()
    {
        $post_id = intval($_POST['post_id']);
        $type = intval($_POST['type']);
        if ($type == 1) {
            $field = 'top';
        }
        if ($type == 2) {
            $field = 'digest';
        }
        if ($type == 3) {
            $field = 'recommend';
        }
        $currentValue = intval($_POST['currentValue']);
        $targetValue = intval($_POST['targetValue']);
        if ($targetValue == '1' && $type == 1) {
            $action = 'weiba_top';
        } elseif ($targetValue == '2' && $type == 1) {
            $action = 'weiba_global_top';
        } elseif ($type == 2) {
            $action = 'weiba_marrow';
        } elseif ($type == 3) {
            $action = 'weiba_recommend';
        }
        $weiba_id = D('weiba_post')->where('post_id=' . $post_id)->getField('weiba_id');
        if ($targetValue == '0' && $type == 1) {
            if (!CheckWeibaPermission('', $weiba_id, 'weiba_top') && !CheckWeibaPermission('', $weiba_id, 'weiba_global_top')) {
                $this->error('对不起,您没有权限进行该操作!');
            }
        } else {
            if (!CheckWeibaPermission('', $weiba_id, $action)) {
                $this->error('对不起,您没有权限进行该操作!');
            }
        }
        if (D('weiba_post')->where('post_id=' . $post_id)->setField($field, $targetValue)) {
            $post_detail = D('weiba_post')->where('post_id=' . $post_id)->find();
            $config['post_name'] = $post_detail['title'];
            $config['post_url'] = '<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>';
            if ($type == 1) {
                switch ($targetValue) {
                    case '0':
                        //取消置顶
                        if ($currentValue == 1) {
                            D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了吧内置顶', 'posts');
                        } else {
                            D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了全局置顶', 'posts');
                        }
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'untop_topic_all');
                        break;
                    case '1':
                        //设为吧内置顶
                        $config['typename'] = '吧内置顶';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了吧内置顶', 'posts');
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_weiba');
                        break;
                    case '2':
                        //设为全局置顶
                        $config['typename'] = '全局置顶';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了全局置顶', 'posts');
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_all');
                        break;
                }
            }
            if ($type == 2) {
                switch ($targetValue) {
                    case '0':
                        //取消精华
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了精华', 'posts');
                        break;
                    case '1':
                        //设为精华
                        $config['typename'] = '精华';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了精华', 'posts');
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'dist_topic');
                        break;
                }
            }
            if ($type == 3) {
                switch ($targetValue) {
                    case '0':
                        //取消推荐
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”取消了推荐', 'posts');
                        break;
                    case '1':
                        //设为推荐
                        $config['typename'] = '推荐';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        D('log')->writeLog($post_detail['weiba_id'], $this->mid, '将帖子“<a href="' . U('weiba/Index/postDetail', array('post_id' => $post_id)) . '" target="_blank">' . $post_detail['title'] . '</a>”设为了推荐', 'posts');
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'recommend_topic');
                        break;
                }
            }
            echo 1;
        } else {
            echo 0;
        }
    }