Пример #1
0
function investMoney($uid, $borrow_id, $money, $_is_auto = 0, $auto_no = null)
{
    $pre = C('DB_PREFIX');
    $done = false;
    $datag = get_global_setting();
    //$fee_invest_manage = explode("|",$datag['fee_invest_manage']);
    //lock(true)防并发
    $investMoney = D('borrow_investor');
    $investMoney->startTrans();
    $binfo = M("borrow_info")->lock(true)->field("borrow_uid,borrow_money,borrow_interest_rate,borrow_type,borrow_duration,repayment_type,has_borrow,reward_money,borrow_min")->find($borrow_id);
    //新加入了奖金reward_money到资金总额里
    $vminfo = getMinfo($uid, 'm.user_leve,m.time_limit,mm.account_money');
    if ($vminfo['account_money'] + $binfo['reward_money'] < $money) {
        $investMoney->commit();
        return "您当前的可用金额为:" . $vminfo['account_money'] . ",您的投标金额为{$money}, 对不起,可用余额不足,不能投标";
    }
    //不同会员级别的费率
    //($vminfo['user_leve']==1 && $vminfo['time_limit']>time())?$fee_rate=($fee_invest_manage[1]/100):$fee_rate=($fee_invest_manage[0]/100);
    $fee_rate = $datag['fee_invest_manage'] / 100;
    //投入的钱
    //$havemoney = $binfo['has_borrow'];
    //if(($binfo['borrow_money'] - $havemoney -$money)<0 )
    //{   $investMoney->commit() ;
    //	return "对不起,此标还差".($binfo['borrow_money'] - $havemoney)."元满标,您最多投标".($binfo['borrow_money'] - $havemoney)."元";
    //}
    $havemoney = M("borrow_investor")->where(array("borrow_id" => $borrow_id))->sum("investor_capital");
    $leftMoney = $binfo['borrow_money'] - $havemoney;
    if ($leftMoney - $money < 0) {
        $investMoney->commit();
        return "对不起,此标还差" . $leftMoney . "元满标,您最多投标" . $leftMoney . "元";
    }
    if ($leftMoney - $money > 0 && $leftMoney - $money < $binfo['borrow_min']) {
        $investMoney->commit();
        return "对不起,您的投标金额将导致标剩余金额不足最低投标限制{$binfo['borrow_min']}元,请修改金额";
    }
    //自动投标总限额校验
    if ($_is_auto == 1) {
        $autoTotalMax = floor($binfo['borrow_money'] * 0.5);
        $autoLeftMoney = $autoTotalMax - $havemoney;
        if ($autoLeftMoney == 0) {
            $investMoney->commit();
            return "对不起,自动投标总限额{$binfo['auto_totalnum']}%,目前已投资{$autoTotalMax}元,您无法再自动投此标";
        }
        if ($autoLeftMoney - $money < 0) {
            $investMoney->commit();
            return "automaxajust|" . $autoLeftMoney;
        }
        if ($autoLeftMoney - $money > 0 && $autoLeftMoney - $money < $binfo['borrow_min']) {
            $investMoney->commit();
            return "autominajust|" . ($autoLeftMoney - $binfo['borrow_min']);
        }
    }
    $investMoney = D('borrow_investor');
    $investMoney->startTrans();
    //还款概要公共信息START
    $investinfo['status'] = 1;
    //等待复审
    $investinfo['borrow_id'] = $borrow_id;
    $investinfo['investor_uid'] = $uid;
    $investinfo['borrow_uid'] = $binfo['borrow_uid'];
    $investinfo['investor_capital'] = $money;
    $investinfo['is_auto'] = $_is_auto;
    $investinfo['add_time'] = time();
    if ($_is_auto == 1) {
        $investinfo['auto_no'] = $auto_no;
    }
    //还款详细公共信息START
    $savedetail = array();
    switch ($binfo['repayment_type']) {
        case 1:
            //按天到期还款
            //还款概要START
            $investinfo['investor_interest'] = getFloatValue($binfo['borrow_interest_rate'] * $investinfo['investor_capital'] * $binfo['borrow_duration'] / 100, 4);
            //$investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest']/100,2);
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //修改投资人的天标管理费2013-03-19 fan
            $invest_info_id = M('borrow_investor')->add($investinfo);
            //还款概要END
            $i = 1;
            $investdetail['borrow_id'] = $borrow_id;
            $investdetail['invest_id'] = $invest_info_id;
            $investdetail['investor_uid'] = $uid;
            $investdetail['borrow_uid'] = $binfo['borrow_uid'];
            $investdetail['capital'] = $investinfo['investor_capital'];
            $investdetail['interest'] = $investinfo['investor_interest'];
            $investdetail['interest_fee'] = $investinfo['invest_fee'];
            $investdetail['status'] = 0;
            $investdetail['sort_order'] = $i;
            $investdetail['total'] = $binfo['borrow_duration'];
            $savedetail[] = $investdetail;
            break;
        case 2:
            //每月还款
            //还款概要START
            $monthData['type'] = "all";
            $monthData['money'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['duration'] = $binfo['borrow_duration'];
            $repay_detail = EqualMonth($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_money'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            $invest_info_id = M('borrow_investor')->add($investinfo);
            //还款概要END
            $monthDataDetail['money'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $monthDataDetail['duration'] = $binfo['borrow_duration'];
            $repay_list = EqualMonth($monthDataDetail);
            $i = 1;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            break;
        case 3:
            //按季分期还款
            //还款概要START
            $monthData['month_times'] = $binfo['borrow_duration'];
            $monthData['account'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['type'] = "all";
            $repay_detail = EqualSeason($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_money'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            $invest_info_id = M('borrow_investor')->add($investinfo);
            //还款概要END
            $monthDataDetail['month_times'] = $binfo['borrow_duration'];
            $monthDataDetail['account'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $repay_list = EqualSeason($monthDataDetail);
            $i = 1;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            break;
        case 4:
            //按季分期还款
            $monthData['month_times'] = $binfo['borrow_duration'];
            $monthData['account'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['type'] = "all";
            $repay_detail = EqualEndMonth($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_account'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            $invest_info_id = M('borrow_investor')->add($investinfo);
            //还款概要END
            $monthDataDetail['month_times'] = $binfo['borrow_duration'];
            $monthDataDetail['account'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $repay_list = EqualEndMonth($monthDataDetail);
            $i = 1;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            break;
    }
    $invest_defail_id = M('investor_detail')->addAll($savedetail);
    //保存还款详情
    //更新投标进度
    $last_have_money = M("borrow_info")->getFieldById($borrow_id, "has_borrow");
    $upborrowsql = "update `{$pre}borrow_info` set ";
    //if($binfo['borrow_type']==3) $upborrowsql .="`transfer_out` = `transfer_out` + $num,";//流转标还要更新流转数量
    $upborrowsql .= "`has_borrow`=" . ($last_have_money + $money) . ",`borrow_times`=`borrow_times`+1";
    $upborrowsql .= " WHERE `id`={$borrow_id}";
    $upborrow_res = M()->execute($upborrowsql);
    //更新投标进度
    if ($invest_defail_id && $invest_info_id && $upborrow_res) {
        //还款概要和详情投标进度都保存成功
        $investMoney->commit();
        $res = memberMoneyLog($uid, 6, -$money, "对{$borrow_id}号标进行投标", $binfo['borrow_uid']);
        if ($havemoney + $money == $binfo['borrow_money']) {
            borrowFull($borrow_id, $binfo['borrow_type']);
            //满标,标记为还款中,更新相关数据
            MTip("chk10", $binfo['borrow_uid'], $borrow_id);
        }
        if (!$res) {
            //没有正常记录和扣除帐户余额的话手动回滚
            M('investor_detail')->where("invest_id={$invest_info_id}")->delete();
            M('borrow_investor')->where("id={$invest_info_id}")->delete();
            //更新投标进度
            $upborrowsql = "update `{$pre}borrow_info` set ";
            $upborrowsql .= "`has_borrow`=" . $havemoney . ",`borrow_times`=`borrow_times`-1";
            $upborrowsql .= " WHERE `id`={$borrow_id}";
            $upborrow_res = M()->execute($upborrowsql);
            //更新投标进度
            $done = false;
        } else {
            $done = true;
        }
    } else {
        $investMoney->rollback();
    }
    return $done;
}
Пример #2
0
function investMoney($uid, $borrow_id, $money, $_is_auto = 0, $invest_info_id, $reqext = 0)
{
    //2015-09-30 lj 红包最后一笔扣不了钱
    // require_once('config/config.db.php');
    $pre = DB_PREFIX;
    $done = false;
    $datag = get_global_setting();
    //$fee_invest_manage = explode("|",$datag['fee_invest_manage']);
    /////////////////////////////锁表  zhang 2015-5-5////////////////////////////////////////////////
    $bdb = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PWD);
    $bdb->beginTransaction();
    $bId = $borrow_id;
    $sql = "SELECT suo FROM lzh_borrow_info_lock WHERE id = ? FOR UPDATE";
    $stmt1 = $bdb->prepare($sql);
    $stmt1->bindParam(1, $bId);
    //绑定第一个参数值
    $stmt1->execute();
    /////////////////////////////锁表   zhang 2015-5-5////////////////////////////////////////////////
    $sqlbi = 'SELECT borrow_uid,borrow_money,borrow_interest_rate,borrow_type,borrow_duration,repayment_type,has_borrow,reward_money,money_collect,manage_rate,danbao FROM lzh_borrow_info WHERE id = ? limit 1';
    $stmt2 = $bdb->prepare($sqlbi);
    $stmt2->bindParam(1, $borrow_id);
    $stmt2->execute();
    while ($rowbi = $stmt2->fetch(PDO::FETCH_ASSOC)) {
        $binfo = $rowbi;
    }
    //新加入了奖金reward_money到资金总额里
    $sql = "SELECT m.user_leve,m.time_limit,mm.account_money,mm.back_money,mm.money_collect FROM {$pre}members AS m LEFT JOIN {$pre}member_money mm ON mm.uid=m.id WHERE m.id= ? limit 1";
    $stmt = $bdb->prepare($sql);
    $stmt->bindParam(1, $uid);
    //绑定第一个参数值
    $stmt->execute();
    //        var_dump($stmt2->queryString);
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $vminfo = $row;
    }
    //	$vminfo = getMinfo($uid,'m.user_leve,m.time_limit,mm.account_money,mm.back_money,mm.money_collect');
    //	if(($vminfo['account_money']+$vminfo['back_money']+$binfo['reward_money'])<$money) {
    //		return "您当前的可用金额为:".($vminfo['account_money']+$vminfo['back_money']+$binfo['reward_money'])." 对不起,可用余额不足,不能投标";
    //	}
    //
    //	////////////新增投标时检测会员的待收金额是否大于标的设置的代收金额限制,大于就可投标,小于就不让投标 2013-08-26 fan//////////////
    //
    //	if($binfo['money_collect']>0){//判断是否设置了投标待收金额限制
    //		if($vminfo['money_collect']<$binfo['money_collect']){
    //			return "对不起,此标设置有投标待收金额限制,您当前的待收金额为".$vminfo['money_collect']."元,小于该标设置的待收金额限制".$binfo['money_collect']."元。";
    //		}
    //	}
    ////////////新增投标时检测会员的待收金额是否大于标的设置的代收金额限制,大于就可投标,小于就不让投标 2013-08-26 fan//////////////
    //不同会员级别的费率
    //($vminfo['user_leve']==1 && $vminfo['time_limit']>time())?$fee_rate=($fee_invest_manage[1]/100):$fee_rate=($fee_invest_manage[0]/100);
    $fee_rate = $datag['fee_invest_manage'] / 100;
    //投入的钱
    $havemoney = $binfo['has_borrow'];
    //	if(($binfo['borrow_money'] - $havemoney -$money)<0)
    //	{
    //		return "对不起,此标还差".($binfo['borrow_money'] - $havemoney)."元满标,您最多投标".($binfo['borrow_money'] - $havemoney)."元";
    //	}
    $sql = "SELECT SUM(investor_capital) AS investor_capital FROM {$pre}borrow_investor WHERE borrow_id = ? LIMIT 1";
    $stmt = $bdb->prepare($sql);
    $stmt->bindParam(1, $borrow_id);
    $stmt->execute();
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $borrow_invest = $row;
    }
    //	$borrow_invest = M("borrow_investor")->where('borrow_id = {$borrow_id}')->sum('investor_capital');//新加投资金额检测
    /***获取积分比率****/
    //        $fee = M('members')->where("id=".$uid)->getField('integral');
    $sql = "SELECT integral FROM {$pre}members WHERE id=? limit 1";
    $stmt = $bdb->prepare($sql);
    $stmt->bindParam(1, $uid);
    $stmt->execute();
    //
    //        file_put_contents('/tmp/444',date('m-d H:i:s')."monthDataDetail".print_r($sql,true)."\n",FILE_APPEND);
    //
    while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
        $fee = $row;
    }
    $fs = $fs = (require_once 'config/config.leveinvestconfig.php');
    foreach ($fs as $val) {
        if ($fee > $val['start'] && $fee < $val['end']) {
            $rate = floatval($val['rate']) / 100;
            break;
        }
    }
    /***获取积分比率结束****/
    $investinfo['status'] = 1;
    //等待复审
    $investinfo['borrow_id'] = $borrow_id;
    $investinfo['investor_uid'] = $uid;
    //投资者
    $investinfo['borrow_uid'] = $binfo['borrow_uid'];
    //借款者
    $investinfo['investor_fee'] = $binfo['manage_rate'] * $money;
    //管理费
    if ($binfo['danbao'] != 0) {
        //			$guarrate=M("member_guarrate")->field("guarrate")->where("uid={$binfo['danbao']}")->find();//担保费率
        $sql = "SELECT guarrate FROM {$pre}member_guarrate WHERE uid=? limit 1";
        $stmt = $bdb->prepare($sql);
        $stmt->bindParam(1, $binfo['danbao']);
        $stmt->execute();
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            $fee = $row;
        }
        $investinfo['guar_fee'] = $guarrate['guarrate'] * $money / 100;
    }
    /////////////////////////////////////新加投资金额检测/////////////////////////////////////////////
    if ($borrow_invest['investor_capital'] > $binfo['borrow_money']) {
        $investinfo['investor_capital'] = $binfo['borrow_money'] - $binfo['has_borrow'];
    } else {
        $investinfo['investor_capital'] = $money;
    }
    /////////////////////////////////////新加投资金额检测/////////////////////////////////////////////
    $investinfo['is_auto'] = $_is_auto;
    $investinfo['add_time'] = time();
    //还款详细公共信息START
    $handler = mysql_connect(DB_HOST, DB_USER, DB_PWD);
    mysql_select_db(DB_NAME);
    mysql_query("SET AUTOCOMMIT=0");
    //设置为不自动提交,因为MYSQL默认立即执行
    mysql_query("START TRANSACTION");
    //开始事务定义
    //还款概要公共信息START
    $savedetail = array();
    switch ($binfo['repayment_type']) {
        case 1:
            //按天到期还款
            //还款概要START
            $investinfo['investor_interest'] = getFloatValue($binfo['borrow_interest_rate'] / 360 * $investinfo['investor_capital'] * $binfo['borrow_duration'] / 100, 4);
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'] * (1 - $rate), 4);
            //修改投资人的天标利息管理费2013-03-19 fan
            $investinfo['invest_fee_yh'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //修改投资人的天标利息管理费2013-03-19 fan
            //$invest_info_id = M('borrow_investor')->add($investinfo);
            //				M('borrow_investor')->where("id=".$invest_info_id)->save($investinfo);
            foreach ($investinfo as $key => $val) {
                $upSql .= "{$key}={$val},";
            }
            $upSql = rtrim($upSql, ",");
            $sql = sprintf("UPDATE %s SET {$upSql} where id=%s", "{$pre}borrow_investor", $invest_info_id);
            $rtype = mysql_query($sql);
            //还款概要END
            $investdetail['borrow_id'] = $borrow_id;
            $investdetail['invest_id'] = $invest_info_id;
            $investdetail['investor_uid'] = $uid;
            $investdetail['borrow_uid'] = $binfo['borrow_uid'];
            $investdetail['capital'] = $investinfo['investor_capital'];
            $investdetail['interest'] = $investinfo['investor_interest'];
            $investdetail['interest_fee'] = $fee_rate * $investinfo['invest_fee'] * (1 - $rate);
            $investdetail['interest_fee_yh'] = $fee_rate * $investinfo['invest_fee'];
            $investdetail['status'] = 0;
            $investdetail['sort_order'] = 1;
            $investdetail['total'] = 1;
            $savedetail[] = $investdetail;
            break;
        case 2:
            //每月还款
            //还款概要START
            $monthData['type'] = "all";
            $monthData['money'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['duration'] = $binfo['borrow_duration'];
            $repay_detail = EqualMonth($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_money'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'] * (1 - $rate), 4);
            $investinfo['invest_fee_yh'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //$invest_info_id = M('borrow_investor')->add($investinfo);
            //				M('borrow_investor')->where("id=".$invest_info_id)->save($investinfo);
            foreach ($investinfo as $key => $val) {
                $upSql .= "{$key}={$val},";
            }
            $upSql = rtrim($upSql, ",");
            $sql = sprintf("UPDATE %s SET {$upSql} where id=%s", "{$pre}borrow_investor", $invest_info_id);
            $rtype = mysql_query($sql);
            //还款概要END
            $monthDataDetail['money'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $monthDataDetail['duration'] = $binfo['borrow_duration'];
            $repay_list = EqualMonth($monthDataDetail);
            $i = 1;
            //file_put_contents(C('WEB_ROOT').'a.txt', json_encode($repay_list));exit;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'] * (1 - $rate), 4);
                $investdetail['interest_fee_yh'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            break;
        case 3:
            //按季分期还款
            //还款概要START
            $monthData['month_times'] = $binfo['borrow_duration'];
            $monthData['account'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['type'] = "all";
            $repay_detail = EqualSeason($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_money'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'] * (1 - $rate), 4);
            $investinfo['invest_fee_yh'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //$invest_info_id = M('borrow_investor')->add($investinfo);
            //				M('borrow_investor')->where("id=".$invest_info_id)->save($investinfo);
            foreach ($investinfo as $key => $val) {
                $upSql .= "{$key}={$val},";
            }
            $upSql = rtrim($upSql, ",");
            $sql = sprintf("UPDATE %s SET {$upSql} where id=%s", "{$pre}borrow_investor", $invest_info_id);
            $rtype = mysql_query($sql);
            //还款概要END
            $monthDataDetail['month_times'] = $binfo['borrow_duration'];
            $monthDataDetail['account'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $repay_list = EqualSeason($monthDataDetail);
            $i = 1;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'] * (1 - $rate), 4);
                $investdetail['interest_fee_yh'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            break;
        case 4:
            //每月还息到期还本
            $monthData['month_times'] = $binfo['borrow_duration'];
            $monthData['account'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['type'] = "all";
            $repay_detail = EqualEndMonth($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_account'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'] * (1 - $rate), 4);
            $investinfo['invest_fee_yh'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //$invest_info_id = M('borrow_investor')->add($investinfo);
            foreach ($investinfo as $key => $val) {
                $upSql .= "{$key}={$val},";
            }
            $upSql = rtrim($upSql, ",");
            $sql = sprintf("UPDATE %s SET {$upSql} where id=%s", "{$pre}borrow_investor", $invest_info_id);
            $rtype = mysql_query($sql);
            //				M('borrow_investor')->where("id=".$invest_info_id)->save($investinfo);
            //还款概要END
            $monthDataDetail['month_times'] = $binfo['borrow_duration'];
            $monthDataDetail['account'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            //file_put_contents('/tmp/abc',date('m-d H:i:s')."monthDataDetail".print_r($monthDataDetail,true)."\n",FILE_APPEND);
            $repay_list = EqualEndMonthBYWHH($monthDataDetail);
            //file_put_contents('/tmp/abc',date('m-d H:i:s')."repay_list".print_r($repay_list,true)."\n",FILE_APPEND);
            $i = 1;
            foreach ($repay_list as $key => $v) {
                $investdetail['borrow_id'] = $borrow_id;
                $investdetail['invest_id'] = $invest_info_id;
                $investdetail['investor_uid'] = $uid;
                $investdetail['borrow_uid'] = $binfo['borrow_uid'];
                $investdetail['capital'] = $v['capital'];
                $investdetail['interest'] = $v['interest'];
                $investdetail['interest_fee'] = getFloatValue($fee_rate * $v['interest'] * (1 - $rate), 4);
                $investdetail['interest_fee_yh'] = getFloatValue($fee_rate * $v['interest'], 4);
                $investdetail['status'] = 0;
                $investdetail['sort_order'] = $i;
                $investdetail['total'] = $binfo['borrow_duration'];
                $i++;
                $savedetail[] = $investdetail;
            }
            //	file_put_contents('/tmp/abc',date('m-d H:i:s')."savedetail".print_r($savedetail,true)."\n",FILE_APPEND);
            break;
        case 5:
            //一次性还款
            $monthData['month_times'] = $binfo['borrow_duration'];
            $monthData['account'] = $investinfo['investor_capital'];
            $monthData['year_apr'] = $binfo['borrow_interest_rate'];
            $monthData['type'] = "all";
            $repay_detail = EqualEndMonthOnly($monthData);
            $investinfo['investor_interest'] = $repay_detail['repayment_account'] - $investinfo['investor_capital'];
            $investinfo['invest_fee'] = getFloatValue($fee_rate * $investinfo['investor_interest'] * (1 - $rate), 4);
            $investinfo['invest_fee_yh'] = getFloatValue($fee_rate * $investinfo['investor_interest'], 4);
            //$invest_info_id = M('borrow_investor')->add($investinfo);
            $sql = sprintf("UPDATE %s SET investor_interest =%s,invest_fee =%s,invest_fee_yh=%s where id=%s", "{$pre}borrow_investor", $investinfo['investor_interest'], $investinfo['invest_fee'], $investinfo['invest_fee_yh'], $invest_info_id);
            $rtype = mysql_query($sql);
            //				M('borrow_investor')->where("id=".$invest_info_id)->save($investinfo);
            //还款概要END
            $monthDataDetail['month_times'] = $binfo['borrow_duration'];
            $monthDataDetail['account'] = $investinfo['investor_capital'];
            $monthDataDetail['year_apr'] = $binfo['borrow_interest_rate'];
            $monthDataDetail['type'] = "all";
            $repay_list = EqualEndMonthOnly($monthDataDetail);
            $investdetail['borrow_id'] = $borrow_id;
            $investdetail['invest_id'] = $invest_info_id;
            $investdetail['investor_uid'] = $uid;
            $investdetail['borrow_uid'] = $binfo['borrow_uid'];
            $investdetail['capital'] = $repay_list['capital'];
            $investdetail['interest'] = $repay_list['interest'];
            $investdetail['interest_fee'] = getFloatValue($fee_rate * $repay_list['interest'] * (1 - $rate), 4);
            $investdetail['interest_fee_yh'] = getFloatValue($fee_rate * $repay_list['interest'], 4);
            $investdetail['status'] = 0;
            $investdetail['sort_order'] = 1;
            $investdetail['total'] = 1;
            $savedetail[] = $investdetail;
            break;
    }
    foreach ($savedetail as $key => $val) {
        //			$invest_defail_id = M('investor_detail')->add($val);//保存还款详情
        $vol = ' (' . implode(',', array_keys($val)) . ')';
        $vlaue = ' (' . implode(',', $val) . ')';
        $invest_defail_id = mysql_query("INSERT INTO {$pre}investor_detail {$vol} VALUES {$vlaue}");
    }
    //		$last_have_money = M("borrow_info")->getFieldById($borrow_id,"has_borrow");
    $result = mysql_query("SELECT has_borrow FROM {$pre}borrow_info WHERE id = {$borrow_id}  LIMIT 1");
    while ($row = mysql_fetch_assoc($result)) {
        $last_have_money = $row['has_borrow'];
    }
    //                $last_have_money = $last_have_money['has_borrow'];
    $lasthavemoney = $last_have_money + $money;
    $sql = "update {$pre}borrow_info set `has_borrow`= {$lasthavemoney},borrow_times=borrow_times+1 WHERE `id`={$borrow_id}";
    $upborrow_res = mysql_query($sql);
    //更新投标进度
    if ($invest_defail_id && $rtype && $upborrow_res) {
        //还款概要和详情投标进度都保存成功
        $bdb->commit();
        mysql_query("COMMIT");
        //执行事务
        //		$investMoney->commit();
        file_put_contents('/tmp/4.txt', date('m-d H:i:s') . " comminvest::" . print_r($reqext, true) . "\n", FILE_APPEND);
        $res = memberMoneyLog($uid, 6, -($money - $reqext), "对{$borrow_id}号标进行投标", $binfo['borrow_uid']);
        //($uid,$type,$amoney,$info="",$target_uid="",$target_uname="",$fee=0,$reqext=0){
        $today_reward = explode("|", $datag['today_reward']);
        if ($binfo['repayment_type'] == '1') {
            //如果是天标,则执行1个月的续投奖励利率
            $reward_rate = floatval($today_reward[0]);
        } else {
            if ($binfo['borrow_duration'] == 1) {
                $reward_rate = floatval($today_reward[0]);
            } else {
                if ($binfo['borrow_duration'] == 2) {
                    $reward_rate = floatval($today_reward[1]);
                } else {
                    $reward_rate = floatval($today_reward[2]);
                }
            }
        }
        ////////////////////////////////////////回款续投奖励规则 fan 2013-07-20////////////////////////////
        //$reward_rate = floatval($datag['today_reward']);//floatval($datag['today_reward']);//当日回款续投奖励利率
        if ($binfo['borrow_type'] != 3) {
            //如果是秒标(borrow_type==3),则没有续投奖励这一说
            $vd['add_time'] = array("lt", time());
            $vd['investor_uid'] = $uid;
            //$borrow_invest_count = M("borrow_investor")->where($vd)->count('id');//检测是否投过标且大于一次
            $sqlbic = sprintf("SELECT count(id) AS total FROM %s WHERE investor_uid=%s AND add_time<%s", "{$pre}borrow_investor", $uid, time());
            //                        $borrow_invest_count = mysql_query("SELECT count(id) FROM {$pre}borrow_investor WHERE investor_uid")
            $resultbic = mysql_query($sqlbic);
            while ($rowbic = mysql_fetch_assoc($resultbic)) {
                $borrow_invest_count = $rowbic['total'];
            }
            if ($reward_rate > 0 && $vminfo['back_money'] > 0 && $borrow_invest_count > 0) {
                //首次投标不给续投奖励
                if ($money > $vminfo['back_money']) {
                    //如果投标金额大于回款资金池金额,有效续投奖励以回款金额资金池总额为标准,否则以投标金额为准
                    $reward_money_s = $vminfo['back_money'];
                } else {
                    $reward_money_s = $money;
                }
                $save_reward['borrow_id'] = $borrow_id;
                $save_reward['reward_uid'] = $uid;
                $save_reward['invest_money'] = $reward_money_s;
                //如果投标金额大于回款资金池金额,有效续投奖励以回款金额资金池总额为标准,否则以投标金额为准
                $save_reward['reward_money'] = $reward_money_s * $reward_rate / 1000;
                //续投奖励
                $save_reward['reward_status'] = 0;
                $save_reward['add_time'] = time();
                $save_reward['add_ip'] = get_client_ip();
                //$newidxt = M("today_reward")->add($save_reward);
                $vol = ' (' . implode(',', array_keys($save_reward)) . ')';
                $vlaue = ' (' . implode(',', $save_reward) . ')';
                $invest_defail_id = mysql_query("INSERT INTO {$pre}today_reward {$vol} VALUES {$vlaue}");
            } else {
                $result = true;
            }
        }
        /////////////////////////回款续投奖励结束 2013-05-10 Dqsy///////////////////////////////
        //////////////////////邀请奖励开始////////////////////////////////////////
        $sqlm = sprintf("SELECT user_name,recommend_id,usrid FROM %s WHERE id = %s LIMIT 1", "{$pre}members", $uid);
        $result = mysql_query($sqlm);
        $vo = mysql_fetch_assoc($result);
        //			$vo = M('members')->field('user_name,recommend_id,usrid')->find($uid);
        $sql = sprintf("SELECT usrid FROM %s WHERE id = %s LIMIT 1 ", "{$pre}members", $vo['recommend_id']);
        $result = mysql_query($sql);
        $recommend_usrid = mysql_fetch_assoc($result);
        //			$recommend_usrid = M('members')->field("usrid")->where("id = {$vo['recommend_id']}")->find();
        $_rate = $datag['award_invest'] / 1000;
        //推广奖励
        $jiangli = getFloatValue($_rate * $investinfo['investor_capital'], 2);
        if ($vo['recommend_id'] != 0) {
            $obj = core::Singleton('huifu.huifu');
            $obj->transfer($jiangli, $recommend_usrid['usrid']);
            memberMoneyLog($vo['recommend_id'], 13, $jiangli, $vo['user_name'] . "对{$borrow_id}号标投资成功,你获得推广奖励" . $jiangli . "元。", $uid);
        }
        /////////////////////邀请奖励结束/////////////////////////////////////////
        //$aaa = M('investor_detail')->where('invest_id =2629')->count();
        //if($aaa !=3 ){
        //	exit('aaaaa');
        //}
        if ($lasthavemoney == $binfo['borrow_money']) {
            borrowFull($borrow_id, $binfo['borrow_type']);
            //满标,标记为还款中,更新相关数据
        }
        if (!$res) {
            //没有正常记录和扣除帐户余额的话手动回滚
            //	M('investor_detail')->where("invest_id={$invest_info_id}")->delete();
            //	M('borrow_investor')->where("id={$invest_info_id}")->delete();
            //更新投标进度
            //	$upborrowsql = "update `{$pre}borrow_info` set ";
            //	$upborrowsql .= "`has_borrow`=".$havemoney.",`borrow_times`=`borrow_times`-1";
            //	$upborrowsql .= " WHERE `id`={$borrow_id}";
            //	$upborrow_res = M()->execute($upborrowsql);
            //更新投标进度
            $done = false;
        } else {
            $done = true;
        }
    } else {
        mysql_query("ROOLBACK");
    }
    mysql_query("SET AUTOCOMMIT=1");
    mysql_close($handler);
    return $done;
}