function _xt_report_fanxian_save($cash, $jifen, $buyer_id, $buyer_name, $sharer_id, $sharer_name, $adser_id, $adser_name, $type, $platform, $trade_id, $commission, $pay_time)
{
    $user_id = 0;
    $user_name = '';
    switch ($type) {
        case 'BUY':
            $user_id = $buyer_id;
            $user_name = $buyer_name;
            break;
        case 'SHARE':
            $user_id = $sharer_id;
            $user_name = $sharer_name;
            break;
        case 'ADS':
            $user_id = $adser_id;
            $user_name = $adser_name;
            break;
    }
    if ($user_id > 0 && ($cash > 0 || $jifen > 0)) {
        if (xt_new_fanxian(array('platform' => $platform, 'trade_id' => $trade_id, 'type' => $type, 'user_id' => $user_id, 'user_name' => $user_name, 'buy_user_id' => $buyer_id, 'buy_user_name' => $buyer_name, 'share_user_id' => $sharer_id, 'share_user_name' => $sharer_name, 'ads_user_id' => $adser_id, 'ads_user_name' => $adser_name, 'commission' => $commission, 'fanxian' => $cash, 'jifen' => $jifen, 'create_time' => current_time('mysql'), 'order_time' => $pay_time))) {
            if (!xt_fanxian_is_pendingtixian() && xt_fanxian_is_autocash()) {
                //处理现金提现,集分宝提现
                $_cash = 0;
                if ($cash > 0) {
                    $_fanxian = xt_user_total_fanxian($user_id);
                    $_tixians = xt_total_tixian($user_id);
                    $_tixian = $_tixians[0] + $_tixians[1];
                    //未审核,已完成
                    $_cash = $_fanxian - $_tixian;
                    //余额
                }
                if ($_cash == 0 && $jifen > 0) {
                    $_fanxian = xt_user_total_jifen($user_id);
                    $_tixians = xt_total_tixian_jifen($user_id);
                    $_tixian = $_tixians[0] + $_tixians[1];
                    //未审核,已完成
                    $_cash = $_fanxian - $_tixian;
                    //余额
                }
                if ($_cash > 0) {
                    xt_new_tixian(array('user_id' => $user_id, 'cash' => $cash, 'jifen' => $jifen));
                }
            }
        }
    }
}
Beispiel #2
0
function xt_ajax_tixian_save()
{
    $result = array('code' => 0, 'msg' => '', 'result' => array());
    if (!xt_is_fanxian()) {
        $result['code'] = 500;
        $result['msg'] = '已关闭返利通道';
        exit(json_encode($result));
    }
    $_amount = $_POST['amount'];
    if (!isset($_POST['type']) || empty($_POST['type'])) {
        $result['code'] = 500;
        $result['msg'] = '未指定要提现的类型';
        exit(json_encode($result));
    }
    $_type = $_POST['type'];
    if (!in_array($_type, array('cash', 'jifenbao'))) {
        $result['code'] = 500;
        $result['msg'] = '指定的提现类型不正确';
        exit(json_encode($result));
    }
    if (empty($_amount)) {
        $result['code'] = 500;
        $result['msg'] = '未填写提现数额';
    }
    if (!is_numeric($_amount)) {
        $result['code'] = 500;
        $result['msg'] = '提现数额格式不正确';
    } else {
        $cashback = (int) xt_fanxian_cashback();
        if ($_type == 'jifenbao') {
            $cashback = $cashback * 100;
        }
        if ($_amount < $cashback) {
            $result['code'] = 500;
            $result['msg'] = '提现数额必须大于:' . $cashback;
        }
    }
    if ($result['code'] == 0) {
        $user = wp_get_current_user();
        if ($user->exists()) {
            $_fanxian = 0;
            $_tixian = 0;
            $_cash = 0;
            if ($_type == 'cash') {
                $_fanxian = xt_user_total_fanxian($user->ID);
                $_tixians = xt_total_tixian($user->ID);
                $_tixian = $_tixians[0] + $_tixians[1];
                //未审核,已完成
                $_cash = $_fanxian - $_tixian;
                //余额
            } else {
                $_fanxian = xt_user_total_jifen($user->ID);
                $_tixians = xt_total_tixian_jifen($user->ID);
                $_tixian = $_tixians[0] + $_tixians[1];
                //未审核,已完成
                $_cash = $_fanxian - $_tixian;
                //余额
            }
            if ($_amount > $_cash) {
                $result['code'] = 500;
                $result['msg'] = '提现数额超过余额';
            } else {
                $__cash = $__jifen = 0;
                if ($_type == 'jifenbao') {
                    $__jifen = $_amount;
                } else {
                    $__cash = $_amount;
                }
                xt_new_tixian(array('user_id' => $user->ID, 'cash' => $__cash, 'jifen' => $__jifen));
            }
        } else {
            $result['code'] = 500;
            $result['msg'] = '未登录';
        }
    }
    exit(json_encode($result));
}