AdminAction::setPost PHP Method

setPost() public method

设置帖子状态
public setPost ( ) : array
return array 操作成功状态和提示信息
    public function setPost()
    {
        if (empty($_POST['post_id'])) {
            $return['status'] = 0;
            $return['data'] = '';
            echo json_encode($return);
            exit;
        }
        $post_detail = D('weiba_post')->where('post_id=' . $post_id)->find();
        switch ($_POST['type']) {
            case '1':
                //推荐
                $field = 'recommend';
                if (intval($_POST['curValue']) == 1) {
                    $value = 0;
                } else {
                    $value = 1;
                }
                break;
            case '2':
                //精华
                $field = 'digest';
                if (intval($_POST['curValue']) == 1) {
                    $value = 0;
                } else {
                    $value = 1;
                }
                break;
            case '3':
                //置顶
                $field = 'top';
                if (intval($_POST['curValue']) == intval($_POST['topValue'])) {
                    $value = 0;
                } else {
                    $value = intval($_POST['topValue']);
                }
                break;
        }
        $post_id = intval($_POST['post_id']);
        $result = D('weiba_post')->where('post_id=' . $post_id)->setField($field, $value);
        if ($field == 'top' && $value == 2) {
            D('weiba_post')->where('post_id=' . $post_id)->setField('top_time', time());
        }
        if (!$result) {
            $return['status'] = 0;
            $return['data'] = L('PUBLIC_ADMIN_OPRETING_ERROR');
        } else {
            $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>';
            switch ($_POST['type']) {
                case '1':
                    //推荐
                    //添加积分
                    if ($value == 1) {
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'recommend_topic');
                    }
                    break;
                case '2':
                    //精华
                    if ($value == 1) {
                        $config['typename'] = '精华';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'dist_topic');
                    }
                    break;
                case '3':
                    //置顶
                    if ($value == 1) {
                        $config['typename'] = '吧内置顶';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_weiba');
                    } elseif ($value == 2) {
                        $config['typename'] = '全局置顶';
                        model('Notify')->sendNotify($post_detail['post_uid'], 'weiba_post_set', $config);
                        //添加积分
                        model('Credit')->setUserCredit($post_detail['post_uid'], 'top_topic_all');
                    }
                    break;
            }
            $return['status'] = 1;
            $return['data'] = L('PUBLIC_ADMIN_OPRETING_SUCCESS');
        }
        echo json_encode($return);
        exit;
    }