Esempio n. 1
0
/**
 * 满标放款
 * $type 0 普通 1代表 第三方
 * $is_loan 0 不返款, 1 返款
 */
function do_loans($id, $repay_start_time, $type = 0)
{
    $return = array("status" => 0, "info" => "");
    if ($id == 0) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    require_once APP_ROOT_PATH . "app/Lib/deal.php";
    syn_deal_status($id);
    $deal_info = get_deal($id);
    if ($deal['cate_id'] == 6) {
        // 体验金
        $is_ty = 1;
    } else {
        $is_ty = 0;
    }
    if (!$deal_info) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    if (!in_array($deal_info['deal_status'], array(2, 4, 5))) {
        $return['info'] = "放款失败,借款不是满标状态";
        return $return;
    }
    if ($type == 0) {
        $loan_data['repay_start_time'] = $repay_start_time == '' ? 0 : to_timespan(to_date(to_timespan($repay_start_time), "Y-m-d"), "Y-m-d");
    } else {
        $loan_data['repay_start_time'] = $repay_start_time;
    }
    if ($loan_data['repay_start_time'] == 0) {
        $return['info'] = "放款失败,时间没选择";
        return $return;
    }
    if ($type == 0 && $deal_info['ips_bill_no'] != "") {
        $return['status'] = 2;
        $return['info'] = "";
        $return['jump'] = APP_ROOT . "/index.php?ctl=collocation&act=Transfer&pTransferType=1&deal_id=" . $id . "&ref_data=" . $loan_data['repay_start_time'];
        return $return;
    }
    if ($loan_data['repay_start_time'] > 0) {
        $deal_info['next_repay_time'] = $loan_data['next_repay_time'] = next_replay_month($loan_data['repay_start_time']);
    }
    $deal_info['deal_status'] = $loan_data['deal_status'] = 4;
    $deal_info['is_has_loans'] = $loan_data['is_has_loans'] = 1;
    $deal_info['repay_start_time'] = $loan_data['repay_start_time'];
    format_deal_item($deal_info);
    //放款给用户
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $loan_data, "UPDATE", "id=" . $id);
    if ($GLOBALS['db']->affected_rows() > 0) {
        require_once APP_ROOT_PATH . "system/libs/user.php";
        if ($type == 0) {
            modify_account(array("money" => $deal_info['borrow_amount']), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],招标成功", 3, $is_ty);
            //扣除服务费
            $services_fee = $deal_info['borrow_amount'] * floatval(trim($deal_info['services_fee'])) / 100;
            modify_account(array("money" => -$services_fee), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],服务费", 14, $is_ty);
        }
        $load_list = $GLOBALS['db']->getAll("SELECT id,user_id,`money`,`is_old_loan`,`rebate_money`,`rebid_money` FROM " . DB_PREFIX . "deal_load where deal_id=" . $id . " and is_rebate = 0 and is_rebid = 0 ");
        foreach ($load_list as $lk => $lv) {
            //扣除冻结资金
            if ($lv['is_old_loan'] == 0 && $type == 0) {
                modify_account(array("lock_money" => -$lv['money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投标成功", 2, $is_ty);
            }
            //返利给用户
            if (floatval($lv["rebate_money"]) != 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_rebate =1 WHERE id=" . $lv['id'] . " AND is_rebate = 0 AND user_id=" . $lv['user_id'], $is_ty);
                if ($GLOBALS['db']->affected_rows()) {
                    modify_account(array("money" => $lv['rebate_money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],返利", 24, $is_ty);
                }
            }
            //续投奖励
            if (floatval($lv["rebid_money"]) != 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_rebid =1 WHERE id=" . $lv['id'] . " AND is_rebid = 0 AND user_id=" . $lv['user_id']);
                if ($GLOBALS['db']->affected_rows()) {
                    modify_account(array("money" => $lv['rebid_money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],续投奖励", 24, $is_ty);
                }
            }
        }
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load", array("is_has_loans" => 1), "UPDATE", "deal_id=" . $id);
        make_repay_plan($deal_info);
        //发借款成功邮件
        send_deal_success_mail_sms($id, $deal_info);
        //发借款成功站内信
        send_deal_success_site_sms($id, $deal_info);
        $return['status'] = 1;
        $return['info'] = "放款成功";
        return $return;
    } else {
        $return['info'] = "放款失败";
        return $return;
    }
}
Esempio n. 2
0
function getUCInrepayRepayBorrowMoney($id)
{
    $id = intval($id);
    $root = array();
    $root["status"] = 0;
    //0:出错;1:正确;
    if ($id == 0) {
        $root["show_err"] = "操作失败!";
        return $root;
    }
    $deal = get_deal($id);
    if (!$deal) {
        $root["show_err"] = "借款不存在!";
        return $root;
    }
    if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
        $root["show_err"] = "不属于你的借款!";
        return $root;
    }
    if ($deal['deal_status'] != 4) {
        $root["show_err"] = "借款不是还款状态!";
        return $root;
    }
    $time = TIME_UTC;
    $impose_money = 0;
    //是否有部分还款的
    $repay_count_ing = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay=2 and deal_id=" . $id);
    if ($repay_count_ing) {
        $root["show_err"] = "请将部分还款的借款还完才可以进行此操作!";
        return $root;
    }
    //计算罚息
    $loan_list = get_deal_load_list($deal);
    $k_repay_key = -1;
    $k_repay_time = 0;
    foreach ($loan_list as $k => $v) {
        if ($v['has_repay'] == 0) {
            if ($k_repay_key == -1) {
                $k_repay_key = $v['l_key'];
                $k_repay_time = $v['repay_day'];
            }
            $impose_money += $v['impose_all_money'];
        }
    }
    if ($impose_money > 0) {
        $root["show_err"] = "请将逾期未还的借款还完才可以进行此操作!";
        return $root;
    }
    if ($deal['ips_bill_no'] != "") {
        $root["status"] = 2;
        $root["jump"] = APP_ROOT . '/index.php?ctl=collocation&act=RepaymentNewTrade&deal_id=' . $deal['id'] . '&l_key=all&from=' . $GLOBALS['request']['from'];
        $root['jump'] = str_replace("/mapi", "", SITE_DOMAIN . $root['jump']);
        return $root;
    }
    //还了几期了
    $has_repay_count = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay=1 and deal_id=" . $id);
    $loaninfo['deal'] = $deal;
    $loaninfo['loanlist'] = $loan_list;
    //返佣
    $rebate_rs = get_rebate_fee($GLOBALS['user_info']['id'], "borrow");
    $loaninfo['deal']['rebate'] = $rebate_rs['rebate'];
    $inrepay_info = inrepay_repay($loaninfo, $has_repay_count);
    $true_repay_money = (double) $inrepay_info['true_repay_money'];
    $true_self_money = (double) $inrepay_info['true_self_money'];
    $impose_money = (double) $inrepay_info['impose_money'];
    $true_manage_money = (double) $inrepay_info['true_manage_money'];
    $true_manage_money_rebate = (double) $inrepay_info['true_manage_money_rebate'];
    $true_total_repay_money = $true_repay_money + $impose_money + $true_manage_money;
    if ($true_total_repay_money > $GLOBALS['user_info']['money']) {
        $root["show_err"] = "对不起,您的余额不足!";
        return $root;
    }
    //录入到提前还款列表
    $inrepay_data['deal_id'] = $id;
    $inrepay_data['user_id'] = $GLOBALS['user_info']['id'];
    $inrepay_data['repay_money'] = $true_repay_money;
    $inrepay_data['self_money'] = $true_self_money;
    $inrepay_data['impose_money'] = $impose_money;
    $inrepay_data['manage_money'] = $true_manage_money;
    $inrepay_data['repay_time'] = $k_repay_time;
    $inrepay_data['true_repay_time'] = $time;
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_inrepay_repay", $inrepay_data, "INSERT");
    $inrepay_id = $GLOBALS['db']->insert_id();
    if ($inrepay_id == 0) {
        $root["show_err"] = "对不起,数据处理失败,请联系客服!";
        return $root;
    }
    //录入还款列表
    $wait_repay_list = $GLOBALS['db']->getAll("SELECT * FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id . " and has_repay=0 ORDER BY l_key ASC");
    $temp_ids = array();
    foreach ($wait_repay_list as $k => $v) {
        $repay_data = array();
        $repay_data['has_repay'] = 1;
        $repay_data['true_repay_time'] = $time;
        $repay_data['true_repay_date'] = to_date($time);
        $repay_data['status'] = 0;
        if ($k_repay_key == $v['l_key']) {
            $repay_data['true_repay_money'] = $true_repay_money;
            $repay_data['impose_money'] = $impose_money;
            $repay_data['true_manage_money'] = $true_manage_money;
            $repay_data['true_self_money'] = $true_self_money;
            $repay_data['true_interest_money'] = $true_repay_money - $true_self_money;
            $repay_data['true_manage_money_rebate'] = $true_manage_money_rebate;
        }
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", "id=" . $v['id']);
        //假如出错 删除掉原来的以插入的数据
        if ($GLOBALS['db']->affected_rows() == 0) {
            if (count($temp_ids) > 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay SET has_repay=0 WHERE id in " . implode(",", $temp_ids) . "");
                make_repay_plan($deal);
            }
            $root["show_err"] = "对不起,处理数据失败请联系客服!";
            return $root;
        } else {
            $temp_ids[] = $v['id'];
        }
    }
    if (count($temp_ids) == 0) {
        $root["show_err"] = "对不起,处理数据失败请联系客服!";
        return $root;
    }
    //更新用户账户资金记录
    require APP_ROOT_PATH . 'system/libs/user.php';
    modify_account(array("money" => -round($impose_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款违约金", 6);
    modify_account(array("money" => -round($true_manage_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款管理费", 10);
    modify_account(array("money" => -round($true_repay_money, 2)), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前还款本息", 6);
    //用户获得额度
    modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款获得额度", 6);
    //借款者返佣金
    if ($true_manage_money_rebate != 0) {
        /*ok*/
        $reback_memo = '借款“<a href="' . $deal["url"] . '">' . $deal["name"] . '</a>”,借款者' . $deal["user"]["user_name"];
        reback_rebate_money($GLOBALS['user_info']['id'], $true_manage_money_rebate, "borrow", $reback_memo);
    }
    //判断获取的信用是否超过限制
    if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_point_log WHERE `type`=6 AND user_id=" . $GLOBALS['user_info']['id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
        //获取上一次还款时间
        $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(create_time) FROM " . DB_PREFIX . "user_point_log WHERE `type`=6 AND user_id=" . $GLOBALS['user_info']['id']);
        $day = ceil(($time - $befor_repay_time) / 24 / 3600);
        //当天数大于等于间隔时间 获得信用
        if ($day >= (int) trim(app_conf('REPAY_SUCCESS_DAY'))) {
            modify_account(array("point" => trim(app_conf('REPAY_SUCCESS_POINT'))), $GLOBALS['user_info']['id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款", 6);
        }
    }
    //用户回款
    /**
     * 获取某一期的用户还款列表
     * array $deal_info 借款信息 
     * int $user_id 用户ID 为0代表全部
     * int $lkey  第几期 -1 全部
     * int $ukey 第几个投标人 -1 全部
     * int $true_time  真实还款时间
     * int $get_type  0 全部 1代表未还的  2 代表已还的
     * int $r_type = 0; 返回类型; 1:只返回一个数组; $result['item']
     * string $limit; 查询限制数量; 0,20  $result['count']
     */
    $user_loan_list = get_deal_user_load_list($deal, 0, -1, -1, $time, 1, 0, '');
    foreach ($user_loan_list as $lllk => $lllv) {
        //循环用户
        //本金
        $user_self_money = 0;
        //本息
        $user_repay_money = 0;
        //违约金
        $user_impose_money = 0;
        //管理费
        $user_manage_money = 0;
        //利息管理费
        $user_manage_interest_money = 0;
        //返佣金
        $manage_interest_money_rebate = 0;
        //奖励
        $user_reward_money = 0;
        foreach ($lllv as $kk => $vv) {
            //循环期数
            $in_user_id = $vv['user_id'];
            //判断是否转让了债权
            if ((int) $vv['t_user_id'] == 0) {
                $loan_user_info['user_name'] = $vv['user_name'];
                $loan_user_info['email'] = $vv['email'];
                $loan_user_info['mobile'] = $vv['mobile'];
            } else {
                $in_user_id = $vv['t_user_id'];
                $loan_user_info['user_name'] = $vv['t_user_name'];
                $loan_user_info['email'] = $vv['t_email'];
                $loan_user_info['mobile'] = $vv['t_mobile'];
            }
            $user_load_data = array();
            $user_load_data['true_repay_time'] = $time;
            $user_load_data['true_repay_date'] = to_date($time);
            $user_load_data['is_site_repay'] = 0;
            $user_load_data['status'] = 0;
            if ($k_repay_key == $vv['l_key']) {
                $loadinfo['deal']['rate'] = $deal['rate'];
                $loadinfo['deal']['loantype'] = $deal['loantype'];
                $loadinfo['deal']['repay_time'] = $deal['repay_time'];
                $loadinfo['deal']['borrow_amount'] = $vv['money'];
                $loadinfo['deal']['repay_start_time'] = $deal['repay_start_time'];
                $loadinfo['deal']['month_manage_money'] = $vv['manage_money'];
                $loadinfo['deal']['manage_interest_money'] = $vv['manage_interest_money'];
                $deal = get_user_load_fee($in_user_id, 0, $deal);
                $loadinfo['deal']['user_loan_interest_manage_fee'] = $deal['user_loan_interest_manage_fee'];
                $rebate_rs = get_rebate_fee($in_user_id, "invest");
                $loadinfo['deal']['rebate'] = $rebate_rs['rebate'];
                $loadinfo['deal']['manage_interest_money_rebate'] = $vv['manage_interest_money_rebate'];
                $loadinfo['deal']['month_repay_money'] = $vv['month_repay_money'];
                $loadinfo['deal']['compensate_fee'] = $deal['compensate_fee'];
                if ($deal['repay_time_type'] == 1) {
                    $loadinfo['deal']['all_manage_money'] = $vv['manage_money'];
                } else {
                    $loadinfo['deal']['all_manage_money'] = $vv['manage_money'] * $deal['repay_time'];
                }
                $loadinfo['deal']['repay_time_type'] = $deal['repay_time_type'];
                $user_load_rs = inrepay_repay($loadinfo, $has_repay_count);
                $user_load_data['true_repay_money'] = $user_load_rs['true_repay_money'];
                $user_load_data['true_self_money'] = $user_load_rs['true_self_money'];
                $user_load_data['impose_money'] = $user_load_rs['impose_money'];
                $user_load_data['true_interest_money'] = $user_load_rs['true_repay_money'] - $user_load_rs['true_self_money'];
                $user_load_data['true_manage_money'] = $user_load_rs['true_manage_money'];
                $user_load_data['true_manage_interest_money'] = $user_load_rs['true_manage_interest_money'];
                $user_load_data['true_manage_interest_money_rebate'] = $user_load_rs['true_manage_interest_money_rebate'];
                $user_load_data['true_repay_manage_money'] = $true_manage_money / count($user_loan_list);
                $user_load_data['true_reward_money'] = 0;
                if ((int) $vv['is_winning'] == 1 && (int) $vv['income_type'] == 2 && (double) $vv['income_value'] != 0) {
                    $user_load_data['true_reward_money'] = $user_load_data['true_interest_money'] * (double) $vv['income_value'] * 0.01;
                }
                $user_self_money = $user_load_data['true_self_money'];
                $user_repay_money = $user_load_data['true_repay_money'];
                $user_impose_money = $user_load_data['impose_money'];
                $user_manage_money = $user_load_data['true_manage_money'];
                $user_manage_interest_money = $user_load_data['true_manage_interest_money'];
                $manage_interest_money_rebate = $user_load_data['true_manage_interest_money_rebate'];
                $user_reward_money = $user_load_data['true_reward_money'];
            }
            $user_load_data['has_repay'] = 1;
            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "UPDATE", "id=" . $vv['id']);
            //普通会员邀请返利
            get_referrals($vv['id']);
        }
        if ($user_repay_money > 0 || $user_impose_money > 0 || $user_manage_money > 0 || $user_manage_interest_money > 0 || $user_reward_money > 0) {
            $all_repay_money = number_format($GLOBALS['db']->getOne("SELECT (sum(repay_money)-sum(self_money) + sum(impose_money)) as shouyi FROM " . DB_PREFIX . "deal_load_repay WHERE  has_repay = 1 and deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
            $all_impose_money = number_format($GLOBALS['db']->getOne("SELECT sum(impose_money) FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay = 1 and deal_id=" . $v['deal_id'] . " AND user_id=" . $v['user_id']), 2);
            //$content = "您好,您在".app_conf("SHOP_TITLE")."的投标 “<a href=\"".$deal['url']."\">".$deal['name']."</a>”提前还款,";
            //$content .= "本次投标共获得收益:".$all_repay_money."元,其中违约金为:".$all_impose_money."元,本次投标已回款完毕!";
            //更新用户账户资金记录
            modify_account(array("money" => $user_repay_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],回报本息", 5);
            modify_account(array("money" => $user_impose_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],提前回收违约金", 7);
            if ($user_manage_money > 0) {
                modify_account(array("money" => -$user_manage_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],投标管理费", 20);
            }
            if ($user_reward_money > 0) {
                modify_account(array("money" => -$user_reward_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],投标奖励", 28);
            }
            modify_account(array("money" => -$user_manage_interest_money), $in_user_id, "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],投标利息管理费", 20);
            //投资者返佣金
            if ($manage_interest_money_rebate) {
                /*ok*/
                $reback_memo = "借款“<a href'" . $deal['url'] . "'>" . $deal["name"] . "</a>”,投资者" . $loan_user_info["user_name"] . ",第" . (intval($k_repay_key) + 1) . "期,提前还款";
                reback_rebate_money($in_user_id, $manage_interest_money_rebate, "invest", $reback_memo);
            }
            $msg_conf = get_user_msg_conf($in_user_id);
            //短信通知
            if (app_conf("SMS_ON") == 1 && app_conf('SMS_REPAY_TOUSER_ON') == 1) {
                $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_SMS'", false);
                $tmpl_content = $tmpl['content'];
                $notice['user_name'] = $loan_user_info['user_name'];
                $notice['deal_name'] = $deal['sub_name'];
                $notice['deal_url'] = $deal['url'];
                $notice['site_name'] = app_conf("SHOP_TITLE");
                $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                $notice['all_repay_money'] = $all_repay_money;
                $notice['impose_money'] = $all_impose_money;
                $GLOBALS['tmpl']->assign("notice", $notice);
                $sms_content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                $msg_data['dest'] = $loan_user_info['mobile'];
                $msg_data['send_type'] = 0;
                $msg_data['title'] = $msg_data['content'] = addslashes($sms_content);
                $msg_data['send_time'] = 0;
                $msg_data['is_send'] = 0;
                $msg_data['create_time'] = $time;
                $msg_data['user_id'] = $in_user_id;
                $msg_data['is_html'] = 0;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                //插入
            }
            //站内信
            $notices['shop_title'] = app_conf("SHOP_TITLE");
            $notices['url'] = "“<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”";
            $notices['repay_money'] = $all_repay_money;
            $notices['impose_money'] = $all_impose_money;
            $tmpl_contents = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_REPAY_MONEY_TQTB'", false);
            $GLOBALS['tmpl']->assign("notice", $notices);
            $content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_contents['content']);
            if ($msg_conf['sms_bidrepaid'] == 1) {
                send_user_msg("", $content, 0, $in_user_id, $time, 0, true, 9);
            }
            //邮件
            if ($msg_conf['mail_bidrepaid'] == 1 && app_conf('MAIL_ON') == 1) {
                $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'", false);
                $tmpl_content = $tmpl['content'];
                $notice['user_name'] = $loan_user_info['user_name'];
                $notice['deal_name'] = $deal['sub_name'];
                $notice['deal_url'] = $deal['url'];
                $notice['site_name'] = app_conf("SHOP_TITLE");
                $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                $notice['msg_cof_setting_url'] = SITE_DOMAIN . url("index", "uc_msg#setting");
                $notice['repay_money'] = $vv['month_repay_money'] + $vv['impose_money'];
                $notice['all_repay_money'] = $all_repay_money;
                $notice['impose_money'] = $all_impose_money;
                $GLOBALS['tmpl']->assign("notice", $notice);
                $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                $msg_data['dest'] = $loan_user_info['email'];
                $msg_data['send_type'] = 1;
                $msg_data['title'] = "“" . $deal['name'] . "”回款通知";
                $msg_data['content'] = addslashes($msg);
                $msg_data['send_time'] = 0;
                $msg_data['is_send'] = 0;
                $msg_data['create_time'] = $time;
                $msg_data['user_id'] = $in_user_id;
                $msg_data['is_html'] = $tmpl['is_html'];
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                //插入
            }
        }
    }
    /*
    $content = "您好,您在".app_conf("SHOP_TITLE")."的借款 “<a href=\"".$deal['url']."\">".$deal['name']."</a>”成功提前还款".number_format($true_total_repay_money,2)."元,";
    $content .= "其中违约金为:".number_format($impose_money,2)."元,本笔借款已还款完毕!";
    */
    $notices['shop_title'] = app_conf("SHOP_TITLE");
    $notices['url'] = "“<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”";
    $notices['repay_money'] = number_format($true_total_repay_money, 2);
    $notices['impose_money'] = number_format($impose_money, 2);
    $tmpl_contents = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_REPAY_MONEY_TQJK'", false);
    $GLOBALS['tmpl']->assign("notice", $notices);
    $content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_contents['content']);
    //站内信
    send_user_msg("", $content, 0, $GLOBALS['user_info']['id'], $time, 0, true, 8);
    //短信通知
    if (app_conf("SMS_ON") == 1 && app_conf('SMS_SEND_REPAY') == 1) {
        //$sms_content = "尊敬的".app_conf("SHOP_TITLE")."用户".$GLOBALS['user_info']['user_name'].",您成功提前还款".number_format($true_total_repay_money,2)."元,其中违约金为:".number_format($impose_money,2)."元,感谢您的关注和支持。【".app_conf("SHOP_TITLE")."】";
        $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SMS_REPAY_SUCCESS_MSG'", false);
        $tmpl_content = $tmpl['content'];
        $notice['user_name'] = $GLOBALS['user_info']['user_name'];
        $notice['deal_name'] = $deal['sub_name'];
        $notice['site_name'] = app_conf("SHOP_TITLE");
        $notice['index'] = $has_repay_count + 1;
        $notice['status'] = "成功提前";
        $notice['all_money'] = number_format($true_total_repay_money, 2);
        $notice['repay_money'] = number_format($true_repay_money, 2);
        $notice['impose_money'] = number_format($impose_money, 2);
        $notice['manage_money'] = number_format($true_manage_money, 2);
        $notice['manage_impose_money'] = 0;
        $GLOBALS['tmpl']->assign("notice", $notice);
        $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
        $msg_data['dest'] = $GLOBALS['user_info']['mobile'];
        $msg_data['send_type'] = 0;
        $msg_data['title'] = "提前还款短信通知";
        $msg_data['content'] = $msg;
        $msg_data['send_time'] = 0;
        $msg_data['is_send'] = 0;
        $msg_data['create_time'] = $time;
        $msg_data['user_id'] = $GLOBALS['user_info']['id'];
        $msg_data['is_html'] = 0;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "generation_repay_submit SET `memo`='因还款失效',`status`=2 WHERE deal_id=" . $deal['id']);
    //VIP升级 -提前还款
    $type = 1;
    $type_info = 4;
    $resultdate = syn_user_vip($GLOBALS['user_info']['id'], $type, $type_info);
    syn_deal_status($id);
    sys_user_status($GLOBALS['user_info']['id'], false, true);
    syn_transfer_status(0, $id);
    $root["status"] = 1;
    //0:出错;1:正确;
    $root["show_err"] = "操作成功!";
    return $root;
}
Esempio n. 3
0
/**
 * 满标放款
 * $type 0 普通 1代表 第三方
 * $is_loan 0 不返款, 1 返款
 */
function do_loans($id, $repay_start_time, $type = 0)
{
    $return = array("status" => 0, "info" => "");
    if ($id == 0) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    require_once APP_ROOT_PATH . "app/Lib/deal.php";
    $deal_info = get_deal($id);
    if (!$deal_info) {
        $return['info'] = "放款失败,借款不存在";
        return $return;
    }
    if (!in_array($deal_info['deal_status'], array(2, 4, 5))) {
        $return['info'] = "放款失败,借款不是满标状态";
        return $return;
    }
    if ($type == 0) {
        $loan_data['repay_start_time'] = $repay_start_time == '' ? 0 : to_timespan(to_date(to_timespan($repay_start_time), "Y-m-d"), "Y-m-d");
    } else {
        $loan_data['repay_start_time'] = $repay_start_time;
    }
    if ($loan_data['repay_start_time'] == 0) {
        $return['info'] = "放款失败,时间没选择";
        return $return;
    }
    if ($type == 0 && $deal_info['ips_bill_no'] != "") {
        $return['status'] = 2;
        $return['info'] = "";
        $return['jump'] = APP_ROOT . "/index.php?ctl=collocation&act=Transfer&pTransferType=1&deal_id=" . $id . "&ref_data=" . $loan_data['repay_start_time'];
        return $return;
    }
    if ($loan_data['repay_start_time'] > 0) {
        $deal_info['next_repay_time'] = $loan_data['next_repay_time'] = next_replay_month($loan_data['repay_start_time']);
    }
    $deal_info['deal_status'] = $loan_data['deal_status'] = 4;
    $deal_info['is_has_loans'] = $loan_data['is_has_loans'] = 1;
    $loan_data['repay_start_date'] = to_date($loan_data['repay_start_time'], "Y-m-d");
    //放款给用户
    $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $loan_data, "UPDATE", "id=" . $id . " AND is_has_loans=0 ");
    $deal_info['repay_start_time'] = $loan_data['repay_start_time'];
    if ($GLOBALS['db']->affected_rows() > 0) {
        format_deal_item($deal_info);
        require_once APP_ROOT_PATH . "system/libs/user.php";
        if ($type == 0) {
            modify_account(array("money" => $deal_info['borrow_amount']), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],招标成功", 3);
            //扣除服务费
            $services_fee = $deal_info['borrow_amount'] * floatval(trim($deal_info['services_fee'])) / 100;
            modify_account(array("money" => -$services_fee), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],服务费", 14);
        }
        //积分
        if ($deal_info['score'] != 0) {
            modify_account(array("score" => $deal_info['score']), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],招标成功", 3);
        }
        $load_list = $GLOBALS['db']->getAll("SELECT id,user_id,`money`,`is_old_loan`,`rebate_money`,`bid_score`,`is_winning`,`income_type`,`income_value` FROM " . DB_PREFIX . "deal_load where deal_id=" . $id . " and is_rebate = 0 ");
        foreach ($load_list as $lk => $lv) {
            //扣除冻结资金
            if ($type == 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_has_loans =1 WHERE id=" . $lv['id'] . " AND is_has_loans = 0 AND user_id=" . $lv['user_id']);
                if ($GLOBALS['db']->affected_rows()) {
                    if ($lv['is_old_loan'] == 0) {
                        modify_account(array("lock_money" => -$lv['money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投标成功", 2);
                    }
                }
            }
            //返利给用户
            if (floatval($lv["rebate_money"]) != 0 || intval($lv["bid_score"]) != 0) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_load SET is_rebate =1 WHERE id=" . $lv['id'] . " AND is_rebate = 0 AND user_id=" . $lv['user_id']);
                if ($GLOBALS['db']->affected_rows()) {
                    //返利
                    if (floatval($lv["rebate_money"]) != 0) {
                        modify_account(array("money" => $lv['rebate_money']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投资返利", 24);
                    }
                    //积分
                    if (intval($lv["bid_score"]) != 0) {
                        modify_account(array("score" => $lv['bid_score']), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],投资返积分", 2);
                    }
                    //VIP奖励
                    if (((int) $lv['income_type'] == 1 || (int) $lv['income_type'] == 2 || (int) $lv['income_type'] == 3 || (int) $lv['income_type'] == 4) && $lv['is_winning'] == 1) {
                        $user_msg_conf = get_user_msg_conf($lv['user_id']);
                        //发放奖励
                        if ($lv['income_type'] == 1) {
                            //红包记录 增加用户金额与不可提现金额
                            $red_envelope_date['user_id'] = $lv['user_id'];
                            $red_envelope_date['deal_id'] = $id;
                            $red_envelope_date['load_id'] = $lv['id'];
                            $red_envelope_date['reward_name'] = "投标收益奖励";
                            $red_envelope_date['gift_type'] = 1;
                            $redmoney = $GLOBALS['db']->getOne("SELECT money FROM " . DB_PREFIX . "vip_red_envelope WHERE id='" . (int) $lv['income_value'] . "'");
                            $red_envelope_date['gift_value'] = $redmoney;
                            $red_envelope_date['status'] = 1;
                            $red_envelope_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $red_envelope_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $is_send_mail = $user_msg_conf['mail_redenvelope'];
                            $is_send_sms = $user_msg_conf['sms_redenvelope'];
                            $TPL_MAIL_NAME = "TPL_MAIL_RED_ENVELOPE";
                            $TPL_SMS_NAME = "TPL_SMS_RED_ENVELOPE";
                            $gift_value = $redmoney;
                            if ($redmoney != 0 && $redmoney != "") {
                                $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $red_envelope_date);
                                //插入
                                modify_account(array('money' => $redmoney, 'nmc_amount' => $redmoney), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],的投标收益奖励  红包现金", 28);
                            }
                        } elseif ($lv['income_type'] == 2) {
                            //收益率
                            $rate_date['user_id'] = $lv['user_id'];
                            $rate_date['deal_id'] = $id;
                            $rate_date['load_id'] = $lv['id'];
                            $rate_date['reward_name'] = "投标收益奖励";
                            $rate_date['gift_type'] = 2;
                            $loadinfo = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_load_repay WHERE load_id='" . $lv['id'] . "'");
                            $interest_money = $loadinfo['repay_money'] - $loadinfo['self_money'];
                            $gift_value = $interest_money * (double) $lv['income_value'] * 0.01;
                            $rate_date['reward_money'] = $gift_value;
                            $rate_date['gift_value'] = $lv['income_value'];
                            $rate_date['status'] = 1;
                            $rate_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $rate_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $rate_date);
                            //插入
                        } elseif ($lv['income_type'] == 3) {
                            //积分
                            $score = (int) $lv['income_value'];
                            $score_date['user_id'] = $lv['user_id'];
                            $score_date['deal_id'] = $id;
                            $score_date['load_id'] = $lv['id'];
                            $score_date['reward_name'] = "投标收益奖励";
                            $score_date['gift_type'] = 3;
                            $score_date['gift_value'] = (int) $lv['income_value'];
                            $score_date['status'] = 1;
                            $score_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $score_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $score_date);
                            //插入
                            $is_send_mail = $user_msg_conf['mail_integral'];
                            $is_send_sms = $user_msg_conf['sms_integral'];
                            $TPL_MAIL_NAME = "TPL_MAIL_INTEGRAL";
                            $TPL_SMS_NAME = "TPL_SMS_INTEGRAL";
                            $gift_value = (int) $lv['income_value'];
                            if ($score != 0) {
                                modify_account(array("score" => $score), $lv['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],的投标收益奖励 积分", 28);
                            }
                        } elseif ($lv['income_type'] == 4) {
                            //礼品记录
                            $gift_date['user_id'] = $lv['user_id'];
                            $gift_date['deal_id'] = $id;
                            $gift_date['load_id'] = $lv['id'];
                            $gift_date['reward_name'] = "投标收益奖励";
                            $gift_date['gift_type'] = 4;
                            $gift_date['gift_value'] = (int) $lv['income_value'];
                            $gift_date['status'] = 1;
                            $gift_date['generation_date'] = to_date(TIME_UTC, "Y-m-d");
                            $gift_date['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "gift_record", $gift_date);
                            //插入
                            $is_send_mail = $user_msg_conf['mail_gift'];
                            $is_send_sms = $user_msg_conf['sms_gift'];
                            $TPL_MAIL_NAME = "TPL_MAIL_GIFT";
                            $TPL_SMS_NAME = "TPL_SMS_GIFT";
                            $gift_value = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "vip_gift where id = " . $gift_date['gift_value']);
                        }
                        $user_info = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where id = " . $lv['user_id']);
                        $deal_name = $GLOBALS['db']->getOne("select name from " . DB_PREFIX . "deal where id = " . $id);
                        //邮件
                        if ($is_send_mail == 1 && app_conf("MAIL_ON") == 1) {
                            $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = '" . $TPL_MAIL_NAME . "'");
                            $tmpl_content = $tmpl['content'];
                            $notice['user_name'] = $user_info['user_name'];
                            $notice['deal_name'] = $deal_name;
                            $notice['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $notice['site_name'] = app_conf("SHOP_TITLE");
                            $notice['gift_value'] = $gift_value;
                            $GLOBALS['tmpl']->assign("notice", $notice);
                            $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                            $msg_data['dest'] = $user_info['email'];
                            $msg_data['send_type'] = 1;
                            $msg_data['title'] = "投标奖励邮件通知";
                            $msg_data['content'] = addslashes($msg);
                            $msg_data['send_time'] = 0;
                            $msg_data['is_send'] = 0;
                            $msg_data['create_time'] = TIME_UTC;
                            $msg_data['user_id'] = $user_info['id'];
                            $msg_data['is_html'] = $tmpl['is_html'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                            //插入
                        }
                        //短信
                        if ($is_send_sms == 1 && app_conf("SMS_ON") == 1) {
                            $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = '" . $TPL_SMS_NAME . "'");
                            $tmpl_content = $tmpl['content'];
                            $notice['user_name'] = $user_info['user_name'];
                            $notice['deal_name'] = $deal_name;
                            $notice['release_date'] = to_date(TIME_UTC, "Y-m-d");
                            $notice['site_name'] = app_conf("SHOP_TITLE");
                            $notice['gift_value'] = $gift_value;
                            $GLOBALS['tmpl']->assign("notice", $notice);
                            $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                            $msg_data['dest'] = $user_info['mobile'];
                            $msg_data['send_type'] = 0;
                            $msg_data['title'] = "投标奖励短信通知";
                            $msg_data['content'] = addslashes($msg);
                            $msg_data['send_time'] = 0;
                            $msg_data['is_send'] = 0;
                            $msg_data['create_time'] = TIME_UTC;
                            $msg_data['user_id'] = $user_info['id'];
                            $msg_data['is_html'] = $tmpl['is_html'];
                            $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                            //插入
                        }
                    }
                }
            }
        }
        //$GLOBALS['db']->autoExecute(DB_PREFIX."deal_load",array("is_has_loans"=>1),"UPDATE","deal_id=".$id);
        make_repay_plan($deal_info);
        //发借款成功邮件
        send_deal_success_mail_sms($id, $deal_info);
        //发借款成功站内信
        send_deal_success_site_sms($id, $deal_info);
        $return['status'] = 1;
        $return['info'] = "放款成功";
        return $return;
    } else {
        $return['info'] = "放款失败";
        return $return;
    }
}
Esempio n. 4
0
<?php

require '../system/common.php';
require '../app/Lib/deal.php';
require '../app/Lib/common.php';
//获取还款中的标
$page = intval($_REQUEST['p']);
if ($page == 0) {
    $page = 1;
}
$limit = ($page - 1) * app_conf("DEAL_PAGE_SIZE") . "," . app_conf("DEAL_PAGE_SIZE");
$id = intval($_REQUEST['id']);
if ($id > 0) {
    $extW = " id=" . $id;
} else {
    $extW = " deal_status = 4 ";
}
$result = get_deal_list($limit, 0, $extW);
foreach ($result['list'] as $k => $v) {
    make_repay_plan($v);
}
$pages_all = ceil($result['count'] / app_conf("DEAL_PAGE_SIZE"));
if ($page < $pages_all) {
    app_redirect("update.php?p=" . ($page + 1));
} else {
    echo "数据更新完成";
}