private function getlist($mode = "index")
 {
     $result = getInvestList($mode, intval($GLOBALS['user_info']['id']), intval($_REQUEST['p']));
     $list = $result['list'];
     foreach ($list as $k => $v) {
         //当为天的时候
         if ($v['repay_time_type'] == 0) {
             $true_repay_time = 1;
         } else {
             $true_repay_time = $v['repay_time'];
         }
         //本息还款金额
         if ($v['loantype'] == 0) {
             $v['interest_amount'] = pl_it_formula($v['u_load_money'], $v['rate'] / 12 / 100, $true_repay_time) * $true_repay_time - $v['u_load_money'];
         } elseif ($v['loantype'] == 1) {
             $v['interest_amount'] = av_it_formula($v['u_load_money'], $v['rate'] / 12 / 100) * $true_repay_time - $v['u_load_money'];
         } elseif ($v['loantype'] == 2) {
             $v['interest_amount'] = $v['u_load_money'] * $v['rate'] / 12 / 100 * $true_repay_time - $v['u_load_money'];
         }
         $list[$k] = $v;
     }
     $count = $result['count'];
     $GLOBALS['tmpl']->assign("list", $list);
     $page = new Page($count, app_conf("PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_INVEST']);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_invest.html");
     $GLOBALS['tmpl']->display("page/uc.html");
 }
Example #2
0
 function savedeal()
 {
     $is_ajax = intval($_REQUEST['is_ajax']);
     if (!$GLOBALS['user_info']) {
         showErr($GLOBALS['lang']['PLEASE_LOGIN_FIRST'], $is_ajax);
     }
     $t = trim($_REQUEST['t']);
     if (!in_array($t, array("save", "publish"))) {
         showErr($GLOBALS['lang']['ERROR_TITLE'], $is_ajax);
     }
     if ($t == "save") {
         $data['is_delete'] = 2;
     } else {
         $data['is_delete'] = 0;
     }
     $data['name'] = strim($_REQUEST['borrowtitle']);
     if (empty($data['name'])) {
         showErr("请输入借款标题", $is_ajax);
     }
     $data['publish_wait'] = 1;
     $icon_type = strim($_REQUEST['imgtype']);
     if ($icon_type == "") {
         showErr("请选择借款图片类型", $is_ajax);
     }
     $icon_type_arr = array('upload' => 1, 'userImg' => 2, 'systemImg' => 3);
     $data['icon_type'] = $icon_type_arr[$icon_type];
     if (intval($data['icon_type']) == 0) {
         showErr("请选择借款图片类型", $is_ajax);
     }
     switch ($data['icon_type']) {
         case 1:
             if (strim($_REQUEST['icon']) == '') {
                 showErr("请上传图片", $is_ajax);
             } else {
                 $data['icon'] = replace_public(strim($_REQUEST['icon']));
             }
             break;
         case 2:
             $data['icon'] = replace_public(get_user_avatar($GLOBALS['user_info']['id'], 'big'));
             break;
         case 3:
             if (intval($_REQUEST['systemimgpath']) == 0) {
                 showErr("请选择系统图片", $is_ajax);
             } else {
                 $data['icon'] = $GLOBALS['db']->getOne("SELECT icon FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . intval($_REQUEST['systemimgpath']));
             }
             break;
     }
     $data['type_id'] = intval($_REQUEST['borrowtype']);
     if ($data['type_id'] == 0) {
         showErr("请选择借款用途", $is_ajax);
     }
     $data['borrow_amount'] = floatval($_REQUEST['borrowamount']);
     if ($data['borrow_amount'] < (int) trim(app_conf('MIN_BORROW_QUOTA')) || $data['borrow_amount'] > (int) trim(app_conf('MAX_BORROW_QUOTA')) || $data['borrow_amount'] % 50 != 0) {
         showErr("请正确输入借款金额", $is_ajax);
     }
     //判断是否需要额度
     if ($GLOBALS['db']->getOne("SELECT is_quota FROM " . DB_PREFIX . "deal_loan_type WHERE id=" . $data['type_id']) == 1) {
         if (intval($GLOBALS['user_info']['quota']) != 0) {
             $can_use_quota = get_can_use_quota($GLOBALS['user_info']['id']);
             if ($data['borrow_amount'] > intval($can_use_quota)) {
                 showErr("输入借款的借款金额超过您的可用额度<br>您当前可用额度为:" . $can_use_quota, $is_ajax);
             }
         }
     }
     $data['repay_time'] = intval($_REQUEST['repaytime']);
     if ($data['repay_time'] == 0) {
         showErr("借款期限", $is_ajax);
     }
     $data['rate'] = floatval($_REQUEST['apr']);
     $data['repay_time_type'] = intval($_REQUEST['repaytime_type']);
     $level_list = load_auto_cache("level");
     $min_rate = 0;
     $max_rate = 0;
     $is_rate_lock = false;
     foreach ($level_list['repaytime_list'][$GLOBALS['user_info']['level_id']] as $kkk => $vvv) {
         if ($data['repay_time_type'] == 1) {
             if ($data['repay_time'] == intval($vvv[0]) && $vvv[1] == $data['repay_time_type']) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
             }
         } else {
             if ($data['repay_time'] <= intval($vvv[0]) && intval($vvv[1]) == $data['repay_time_type'] && $is_rate_lock == false) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
                 $is_rate_lock = true;
             } elseif ($data['repay_time'] > intval($vvv[0]) && intval($vvv[1]) == $data['repay_time_type']) {
                 $min_rate = $vvv[2];
                 $max_rate = $vvv[3];
             }
         }
     }
     if (floatval($data['rate']) <= 0 || floatval($data['rate']) > $max_rate || floatval($data['rate']) < $min_rate) {
         showErr("请正确输入借款利率", $is_ajax);
     }
     $data['enddate'] = intval($_REQUEST['enddate']);
     $data['description'] = replace_public(btrim($_REQUEST['borrowdesc']));
     $data['description'] = valid_tag($data['description']);
     if (trim($data['description']) == '') {
         showErr("请输入项目描述", $is_ajax);
     }
     $user_view_info = $GLOBALS['user_info']['view_info'];
     $user_view_info = unserialize($user_view_info);
     $new_view_info_arr = array();
     for ($i = 1; $i <= intval($_REQUEST['file_upload_count']); $i++) {
         $img_info = array();
         $img = replace_public(strim($_REQUEST['file_' . $i]));
         if ($img != "") {
             $img_info['name'] = strim($_REQUEST['file_name_' . $i]);
             $img_info['img'] = $img;
             $img_info['is_user'] = 1;
             $user_view_info[] = $img_info;
             $ss = $user_view_info;
             end($ss);
             $key = key($ss);
             $new_view_info_arr[$key] = $img_info;
         }
     }
     $datas['view_info'] = serialize($user_view_info);
     $GLOBALS['db']->autoExecute(DB_PREFIX . "user", $datas, "UPDATE", "id=" . $GLOBALS['user_info']['id']);
     $data['view_info'] = array();
     foreach ($_REQUEST['file_key'] as $k => $v) {
         if (isset($user_view_info[$v])) {
             $data['view_info'][$v] = $user_view_info[$v];
         }
     }
     foreach ($new_view_info_arr as $k => $v) {
         $data['view_info'][$k] = $v;
     }
     $data['view_info'] = serialize($data['view_info']);
     //资金运转
     $data['remark_1'] = strim(replace_public($_REQUEST['remark_1']));
     $data['remark_1'] = valid_tag($data['remark_1']);
     //风险控制措施
     $data['remark_2'] = strim(replace_public($_REQUEST['remark_2']));
     $data['remark_2'] = valid_tag($data['remark_2']);
     //政策及市场分析
     $data['remark_3'] = strim(replace_public($_REQUEST['remark_3']));
     $data['remark_3'] = valid_tag($data['remark_3']);
     //企业背景
     $data['remark_4'] = strim(replace_public($_REQUEST['remark_4']));
     $data['remark_4'] = valid_tag($data['remark_4']);
     //企业信息
     $data['remark_5'] = strim(replace_public($_REQUEST['remark_5']));
     $data['remark_5'] = valid_tag($data['remark_5']);
     //项目相关资料
     $data['remark_6'] = strim(replace_public($_REQUEST['remark_6']));
     $data['remark_6'] = valid_tag($data['remark_6']);
     //$data['voffice'] = intval($_REQUEST['voffice']);
     //$data['vposition'] = intval($_REQUEST['vposition']);
     $data['voffice'] = 1;
     $data['vposition'] = 1;
     $data['is_effect'] = 1;
     $data['deal_status'] = 0;
     $data['agency_id'] = intval($_REQUEST['agency_id']);
     $data['agency_status'] = 1;
     $data['warrant'] = intval($_REQUEST['warrant']);
     $data['guarantor_margin_amt'] = floatval($_REQUEST['guarantor_margin_amt']);
     $data['guarantor_pro_fit_amt'] = floatval($_REQUEST['guarantor_pro_fit_amt']);
     $data['user_id'] = intval($GLOBALS['user_info']['id']);
     $data['loantype'] = intval($_REQUEST['loantype']);
     if ($data['repay_time_type'] == 0) {
         $data['loantype'] = 2;
     }
     //当为天的时候
     if ($data['repay_time_type'] == 0) {
         $true_repay_time = 1;
     } else {
         $true_repay_time = $data['repay_time'];
     }
     //本金担保
     if ($data['warrant'] == 1) {
         $data['guarantor_amt'] = $data['borrow_amount'];
     } elseif ($data['warrant'] == 2) {
         //等额本息
         if ($data['loantype'] == 0) {
             $data['guarantor_amt'] = pl_it_formula($data['borrow_amount'], $data['rate'] / 12 / 100, $true_repay_time) * $true_repay_time;
         } elseif ($data['loantype'] == 1) {
             $data['guarantor_amt'] = av_it_formula($data['borrow_amount'], $data['rate'] / 12 / 100) * $true_repay_time + $data['borrow_amount'];
         } elseif ($data['loantype'] == 2) {
             $data['guarantor_amt'] = $data['borrow_amount'] * $data['rate'] / 12 / 100 * $true_repay_time + $data['borrow_amount'];
         }
     }
     $data['create_time'] = TIME_UTC;
     $module = "INSERT";
     $jumpurl = url("index", "borrow#steptwo");
     $condition = "";
     $deal_id = $GLOBALS['db']->getOne("SELECT id FROM " . DB_PREFIX . "deal WHERE ((is_delete=2 or is_delete=3) or (is_delete=0 and publish_wait=1)) AND user_id=" . $GLOBALS['user_info']['id']);
     if ($deal_id > 0) {
         $module = "UPDATE";
         if ($t == "save") {
             $jumpurl = url("index", "borrow#stepone");
         }
         $condition = "id = {$deal_id}";
     } else {
         if ($t == "save") {
             $jumpurl = url("index", "borrow#stepone");
         }
     }
     $GLOBALS['db']->autoExecute(DB_PREFIX . "deal", $data, $module, $condition);
     if ($module == "INSERT") {
         $deal_id = $GLOBALS['db']->insert_id();
     }
     require_once APP_ROOT_PATH . 'app/Lib/deal.php';
     $deal = get_deal($deal_id);
     //发送验证通知
     if ($t != "save" && trim(app_conf('CUSTOM_SERVICE')) != '' && ($GLOBALS['user_info']['idcardpassed'] == 0 || $GLOBALS['user_info']['incomepassed'] == 0 || $GLOBALS['user_info']['creditpassed'] == 0 || $GLOBALS['user_info']['workpassed'] == 0)) {
         $ulist = explode(",", trim(app_conf('CUSTOM_SERVICE')));
         $ulist = array_filter($ulist);
         if ($ulist) {
             $uuid = $ulist[array_rand($ulist)];
             if ($uuid > 0) {
                 $content = app_conf("SHOP_TITLE") . "用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话 " . app_conf('SHOP_TEL') . " 或给客服邮箱发邮件 " . app_conf("REPLY_ADDRESS") . " 我们会及时给您回复。";
                 require_once APP_ROOT_PATH . 'app/Lib/message.php';
                 //添加留言
                 $message['title'] = $content;
                 $message['content'] = htmlspecialchars(addslashes(valid_str($content)));
                 $message['title'] = valid_str($message['title']);
                 $message['create_time'] = TIME_UTC;
                 $message['rel_table'] = "deal";
                 $message['rel_id'] = $deal_id;
                 $message['user_id'] = $uuid;
                 $message['is_effect'] = 1;
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "message", $message);
                 //添加到动态
                 insert_topic("message", $message['rel_id'], $message['user_id'], get_user_name($message['user_id'], false), $GLOBALS['user_info']['id']);
                 //自己给自己留言不执行操作
                 if ($deal['user_id'] != $message['user_id']) {
                     $msg_conf = get_user_msg_conf($deal['user_id']);
                     //站内信
                     if ($msg_conf['sms_asked'] == 1) {
                         $notices['shop_title'] = app_conf("SHOP_TITLE");
                         $notices['shop_tel'] = app_conf('SHOP_TEL');
                         $notices['shop_address'] = app_conf("REPLY_ADDRESS");
                         /*{$notice.shop_title}用户您好,请尽快上传必要信用认证材料(包括身份证认证、工作认证、收入认证、信用报告认证)。另外,多上传一些可选信用认证,有助于您提高借款额度,也有利于出借人更多的了解您的情况,以便让您更快的筹集到所需的资金。请您点击'我要贷款',之后点击相应的审核项目,进入后,可先阅读该项信用认证所需材料及要求,然后按要求上传资料即可。 如果您有任何问题请您拨打客服电话{$notice.shop_tel}或给客服邮箱发邮件{$notice.shop_address}我们会及时给您回复。*/
                         $notices['url'] = "“<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”";
                         $notices['user_name'] = get_user_name($message['user_id']);
                         $notices['money'] = $user_load_data['true_repay_money'] + $user_load_data['impose_money'];
                         $tmpl_content = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_WORDS_MSG'", false);
                         $GLOBALS['tmpl']->assign("notice", $notices);
                         $contents = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content['content']);
                         send_user_msg("", $contents, 0, $deal['user_id'], TIME_UTC, 0, true, 13, $message['rel_id']);
                     }
                     //邮件
                     if ($msg_conf['mail_asked'] == 1 && app_conf('MAIL_ON') == 1) {
                         $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_MAIL_DEAL_MSG'");
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $GLOBALS['user_info']['user_name'];
                         $notice['msg_user_name'] = get_user_name($message['user_id'], false);
                         $notice['deal_name'] = $deal['name'];
                         $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $deal['id']));
                         $notice['message'] = $message['content'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['site_url'] = SITE_DOMAIN . APP_ROOT;
                         $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
                         $GLOBALS['tmpl']->assign("notice", $notice);
                         $msg = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content);
                         $msg_data['dest'] = $GLOBALS['user_info']['email'];
                         $msg_data['send_type'] = 1;
                         $msg_data['title'] = get_user_name($message['user_id'], false) . "给您的标留言!";
                         $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'] = $GLOBALS['user_info']['id'];
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($is_ajax == 1) {
         showSuccess($GLOBALS['lang']['SUCCESS_TITLE'], $is_ajax, $jumpurl);
     } else {
         app_redirect($jumpurl);
     }
 }
Example #3
0
 public function dcontract()
 {
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         showErr("操作失败!");
     }
     $deal = get_deal($id);
     if (!$deal) {
         showErr("操作失败!");
     }
     $load_user_id = $GLOBALS['db']->getOne("select user_id FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $id . " and user_id=" . $GLOBALS['user_info']['id'] . " ORDER BY create_time ASC");
     if ($load_user_id == 0 && $deal['user_id'] != $GLOBALS['user_info']['id']) {
         showErr("操作失败!");
     }
     if ($deal['agency_id'] > 0) {
         $agency = $GLOBALS['db']->getRow("select * FROM " . DB_PREFIX . "deal_agency WHERE id=" . $deal['agency_id'] . " ");
         $deal['agency_name'] = $agency['name'];
         $deal['agency_address'] = $agency['address'];
     }
     $GLOBALS['tmpl']->assign('deal', $deal);
     $loan_list = $GLOBALS['db']->getAll("select * FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $id . " ORDER BY create_time ASC");
     foreach ($loan_list as $k => $v) {
         if ($deal['loantype'] == 0) {
             $loan_list[$k]['get_repay_money'] = pl_it_formula($v['money'], $deal['rate'] / 12 / 100, $deal['repay_time']);
         } elseif ($deal['loantype'] == 1) {
             $loan_list[$k]['get_repay_money'] = av_it_formula($v['money'], $deal['rate'] / 12 / 100);
         } elseif ($deal['loantype'] == 2) {
             $loan_list[$k]['get_repay_money'] = $v['money'] * $deal['rate'] / 12 / 100 * $deal['repay_time'] + $v['money'];
         }
         if ($deal['repay_time_type'] == 0) {
             $loan_list[$k]['get_repay_money'] = $v['money'] * $deal['rate'] / 12 / 100 + $v['money'];
         }
     }
     $GLOBALS['tmpl']->assign('loan_list', $loan_list);
     $u_info = get_user("*", $deal['user_id']);
     $GLOBALS['tmpl']->assign('user_info', $u_info);
     if ($u_info['sealpassed'] == 1) {
         $credit_file = get_user_credit_file($deal['user_id']);
         $GLOBALS['tmpl']->assign('user_seal_url', $credit_file['credit_seal']['file_list'][0]);
     }
     if ($deal['agency_id'] > 0) {
         $contract = $GLOBALS['tmpl']->fetch("str:" . app_conf("CONTRACT_1"));
     } else {
         $contract = $GLOBALS['tmpl']->fetch("str:" . app_conf("CONTRACT_0"));
     }
     $GLOBALS['tmpl']->assign('contract', $contract);
     header("Content-type:text/html;charset=utf-8");
     header("Content-Disposition: attachment; filename=借款协议.html");
     echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>";
     echo '<html>';
     echo '<head>';
     echo '<title>借款协议</title>';
     echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8">';
     echo '<meta http-equiv="X-UA-Compatible" content="IE=7" />';
     echo $GLOBALS['tmpl']->fetch("inc/uc/uc_deal_contract.html");
     echo '</body>';
     echo '</html>';
 }
Example #4
0
function getUcTransferBuys($page, $status)
{
    if ($page == 0) {
        $page = 1;
    }
    $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
    $page_args = array();
    $condition = ' and d.is_effect=1 and d.is_delete=0  and d.repay_time_type =1 and  d.publish_wait=0 and dlt.t_user_id=' . $GLOBALS['user_info']['id'] . "  ";
    $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id  and dlt.load_id=dl.id ";
    switch ($status) {
        case 1:
            //回收中
            $condition .= " AND d.deal_status = 4 ";
            break;
        case 2:
            //已回收
            $condition .= " AND d.deal_status = 5 ";
            break;
        default:
            //默认
            $condition .= " AND d.deal_status >= 4 ";
            break;
    }
    $count_sql = 'SELECT count(dl.id) FROM ' . DB_PREFIX . 'deal_load dl LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id = dl.deal_id ' . $union_sql . ' WHERE 1=1 ' . $condition;
    $rs_count = $GLOBALS['db']->getOne($count_sql . " LIMIT {$limit} ");
    $list = array();
    if ($rs_count > 0) {
        $list_sql = 'SELECT dl.id as dlid,d.*,dl.money as load_money,dlt.id as dltid,dlt.status as tras_status,dlt.t_user_id,dlt.transfer_amount,dlt.create_time as tras_create_time,dlt.transfer_time FROM ' . DB_PREFIX . 'deal_load dl LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id = dl.deal_id ' . $union_sql . ' WHERE 1=1 ' . $condition;
        $list = $GLOBALS['db']->getAll($list_sql);
        foreach ($list as $k => $v) {
            //最后还款日
            $list[$k]['final_repay_time'] = next_replay_month($v['repay_start_time'], $v['repay_time']);
            $list[$k]['final_repay_time_format'] = to_date($list[$k]['final_repay_time'], "Y-m-d");
            //剩余期数
            if ($v['deal_status'] == 4) {
                if (intval($v['last_repay_time']) > 0) {
                    $list[$k]['how_much_month'] = how_much_month($v['last_repay_time'], $list[$k]['final_repay_time']);
                } else {
                    $list[$k]['how_much_month'] = how_much_month($v['repay_start_time'], $list[$k]['final_repay_time']);
                }
            } else {
                $list[$k]['how_much_month'] = 0;
            }
            if ($v['loantype'] == 0) {
                $list[$k]['month_repay_money'] = pl_it_formula($v['load_money'], $v['rate'] / 12 / 100, $v['repay_time']);
            } elseif ($v['loantype'] == 1) {
                $list[$k]['month_repay_money'] = av_it_formula($v['load_money'], $v['rate'] / 12 / 100);
            } elseif ($v['loantype'] == 2) {
                $list[$k]['month_repay_money'] = 0;
            }
            if ($v['deal_status'] == 4) {
                if ($v['loantype'] == 0) {
                    //剩余多少钱未回
                    $list[$k]['all_must_repay_money'] = $list[$k]['month_repay_money'] * $list[$k]['how_much_month'];
                    //剩余多少本金未回
                    $list[$k]['left_benjin'] = get_benjin($v['repay_time'] - $list[$k]['how_much_month'] - 1, $v['repay_time'], $v['load_money'], $list[$k]['month_repay_money'], $v['rate']);
                } elseif ($v['loantype'] == 1) {
                    //剩余多少钱未回
                    $list[$k]['all_must_repay_money'] = $list[$k]['month_repay_money'] * $list[$k]['how_much_month'] + $v['load_money'];
                    //剩余多少本金未回
                    $list[$k]['left_benjin'] = $v['load_money'];
                } elseif ($v['loantype'] == 2) {
                    //剩余多少钱未回
                    $list[$k]['all_must_repay_money'] = $v['load_money'] * $v['rate'] / 12 / 100 * $v['repay_time'] + $v['load_money'];
                    //剩余多少本金未回
                    $list[$k]['left_benjin'] = $v['load_money'];
                }
                $list[$k]['left_benjin_format'] = format_price($list[$k]['left_benjin'] / 10000) . "万";
                //剩多少利息
                $list[$k]['left_lixi'] = $list[$k]['all_must_repay_money'] - $list[$k]['left_benjin'];
                $list[$k]['left_lixi_format'] = format_price($list[$k]['left_lixi']);
            } else {
                $list[$k]['left_benjin_format'] = format_price(0);
                $list[$k]['left_lixi_format'] = format_price(0);
            }
            //转让价格
            $list[$k]['transfer_amount_format'] = format_price($v['transfer_amount'] / 10000) . "万";
            if ($v['tras_create_time'] != "") {
                $list[$k]['tras_create_time_format'] = to_date($v['tras_create_time'], "Y-m-d");
            }
            if (intval($v['transfer_time']) > 0) {
                $list[$k]['transfer_time_format'] = to_date($v['transfer_time'], "Y-m-d");
            }
            $list[$k]['tras_status_op'] = 5;
            if ($v['deal_status'] == 4) {
                $list[$k]['tras_status_format'] = '回收中';
            } elseif ($v['deal_status'] == 5) {
                $list[$k]['tras_status_format'] = '已回收';
            }
            $durl = "/index.php?ctl=deal&act=mobile&id=" . $v['id'];
            $list[$k]['app_url'] = str_replace("/mapi", "", SITE_DOMAIN . $durl);
        }
        return array('list' => $list, 'count' => $rs_count);
    } else {
        return array('list' => null, 'count' => 0);
    }
}
 /**
  * 债券转让计算
  */
 function transfer($transfer)
 {
     $return['month_repay_money'] = av_it_formula($transfer['load_money'], $transfer['rate'] / 12 / 100);
     //剩余多少钱未回
     $return['all_must_repay_money'] = $return['month_repay_money'] * $transfer['how_much_month'] + $transfer['load_money'];
     //剩余多少本金未回
     $return['left_benjin'] = $transfer['load_money'];
     return $return;
 }
Example #6
0
function get_transfer_list($limit, $condition = '', $extfield, $union_sql, $orderby = '')
{
    //获取转让列表
    $count_sql = 'SELECT count(dlt.id) FROM ' . DB_PREFIX . 'deal_load_transfer dlt LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id =dlt.deal_id WHERE dlt.status=1 and d.is_effect=1 AND d.is_delete = 0 ' . $condition;
    $rs_count = $GLOBALS['db']->getOne($count_sql);
    if ($rs_count > 0) {
        $list_sql = 'SELECT dlt.*,d.loantype,d.name,d.icon,d.cate_id,d.user_id as duser_id,d.rate,d.repay_time,d.repay_time_type ' . $extfield . '  FROM ' . DB_PREFIX . 'deal_load_transfer dlt LEFT JOIN ' . DB_PREFIX . 'deal d ON d.id =dlt.deal_id ' . $union_sql . ' WHERE dlt.status=1 and d.is_effect=1 AND d.is_delete = 0 ' . $condition;
        $list_sql .= ' ORDER BY ' . $orderby;
        $list_sql .= ' LIMIT ' . $limit;
        $list = $GLOBALS['db']->getAll($list_sql);
        foreach ($list as $k => $v) {
            $list[$k]['duser'] = get_user("user_name,level_id,province_id,city_id", $v['duser_id']);
            $list[$k]['user'] = get_user("user_name,level_id,province_id,city_id", $v['user_id']);
            if ($v['t_user_id'] > 0) {
                $list[$k]['tuser'] = get_user("user_name,level_id,province_id,city_id", $v['t_user_id']);
            } else {
                $list[$k]['tuser'] = null;
            }
            if ($list[$k]['tuser'] === false) {
                $list[$k]['tuser'] = null;
            }
            if ($list[$k]['duser'] === false) {
                $list[$k]['duser'] = null;
            }
            if ($list[$k]['user'] === false) {
                $list[$k]['user'] = null;
                //new ArrayObject(); {}
            }
            $list[$k]['url'] = url("index", "transfer#detail", array("id" => $v['id']));
            //$deal['url'] = $durl;
            //x	$durl = "/index.php?ctl=deal&act=mobile&id=".$v['deal_id'];
            $durl = APP_ROOT . "/wap/index.php?ctl=transfer_mobile&is_sj=1&id=" . $v['deal_id'];
            $list[$k]['app_url'] = str_replace("/mapi", "", SITE_DOMAIN . $durl);
            //剩余期数
            $list[$k]['how_much_month'] = how_much_month($v['near_repay_time'], $v['last_repay_time']) + 1;
            if ($v['cate_id'] > 0) {
                $list[$k]['cate_info'] = $GLOBALS['db']->getRowCached("select id,name,brief,uname,icon from " . DB_PREFIX . "deal_cate where id = " . $v['cate_id'] . " and is_effect = 1 and is_delete = 0");
            }
            //本息还款金额
            if ($v['loantype'] == 0) {
                $list[$k]['month_repay_money'] = pl_it_formula($v['load_money'], $v['rate'] / 12 / 100, $v['repay_time']);
                //剩余多少钱未回
                $list[$k]['all_must_repay_money'] = $list[$k]['month_repay_money'] * $list[$k]['how_much_month'];
                //剩余多少本金未回
                $list[$k]['left_benjin'] = get_benjin($v['repay_time'] - $list[$k]['how_much_month'] - 1, $v['repay_time'], $v['load_money'], $list[$k]['month_repay_money'], $v['rate']);
            } elseif ($v['loantype'] == 1) {
                $list[$k]['month_repay_money'] = av_it_formula($v['load_money'], $v['rate'] / 12 / 100);
                //剩余多少钱未回
                $list[$k]['all_must_repay_money'] = $list[$k]['month_repay_money'] * $list[$k]['how_much_month'] + $v['load_money'];
                //剩余多少本金未回
                $list[$k]['left_benjin'] = $v['load_money'];
            } elseif ($v['loantype'] == 2) {
                $list[$k]['month_repay_money'] = 0;
                //剩余多少钱未回
                $list[$k]['all_must_repay_money'] = $v['load_money'] * $v['rate'] / 12 / 100 * $v['repay_time'] + $v['load_money'];
                //剩余多少本金未回
                $list[$k]['left_benjin'] = $v['load_money'];
            }
            $list[$k]['left_benjin_format'] = format_price($list[$k]['left_benjin'] / 10000) . "万";
            //剩多少利息
            $list[$k]['left_lixi'] = $list[$k]['all_must_repay_money'] - $list[$k]['left_benjin'];
            $list[$k]['left_lixi_format'] = format_price($list[$k]['left_lixi']);
            $list[$k]['remain_time'] = $v['near_repay_time'] - TIME_UTC + 24 * 3600 - 1;
            $list[$k]['remain_time_format'] = remain_time($list[$k]['remain_time']);
            $list[$k]['near_repay_time_format'] = to_date($v['near_repay_time'], "Y-m-d");
            $list[$k]['transfer_amount_format'] = format_price($v['transfer_amount'] / 10000) . "万";
            //转让收益
            $list[$k]['transfer_income'] = $list[$k]['all_must_repay_money'] - $list[$k]['transfer_amount'];
            $list[$k]['transfer_income_format'] = format_price($list[$k]['transfer_income']);
            //
            $list[$k]['transfer_time_format'] = to_date($v['transfer_time'], "Y-m-d");
        }
        $result["list"] = $list;
    }
    $result["rs_count"] = $rs_count;
    return $result;
}
Example #7
0
 public function three_msg()
 {
     $map['is_delete'] = 0;
     if (trim($_REQUEST['name']) != '') {
         $map['name'] = array('like', '%' . trim($_REQUEST['name']) . '%');
     }
     if (intval($_REQUEST['cate_id']) > 0) {
         require_once APP_ROOT_PATH . "system/utils/child.php";
         $child = new Child("deal_cate");
         $cate_ids = $child->getChildIds(intval($_REQUEST['cate_id']));
         $cate_ids[] = intval($_REQUEST['cate_id']);
         $map['cate_id'] = array("in", $cate_ids);
     }
     if (trim($_REQUEST['user_name']) != '') {
         $sql = "select group_concat(id) from " . DB_PREFIX . "user where user_name like '%" . trim($_REQUEST['user_name']) . "%'";
         $ids = $GLOBALS['db']->getOne($sql);
         $map['user_id'] = array("in", $ids);
     }
     $map['publish_wait'] = 0;
     $map['is_effect'] = 1;
     //获取到期还本息的贷款
     $temp_ids = M("Deal")->where("publish_wait = 0  and is_delete=0 AND deal_status = 4 AND  ((next_repay_time - " . TIME_UTC . " +  24*3600 -1)/24/3600 between 0 AND 3)")->Field('id')->findAll();
     $deal_ids[] = 0;
     foreach ($temp_ids as $k => $v) {
         $deal_ids[] = $v['id'];
     }
     $map['id'] = array("in", implode(",", $deal_ids));
     $list = D("Deal")->where($map)->findAll();
     //发送信息
     foreach ($list as $k => $v) {
         $next_repay_time = 0;
         $true_repay_time = $v['repay_time'];
         if ($v['next_repay_time'] > 0) {
             $next_repay_time = $v['next_repay_time'];
         } else {
             if ($v['repay_time_type'] == 0) {
                 $r_y = to_date($v['repay_start_time'], "Y");
                 $r_m = to_date($v['repay_start_time'], "m");
                 $r_d = to_date($v['repay_start_time'], "d");
                 if ($r_m - 1 <= 0) {
                     $r_m = 12;
                     $r_y = $r_y - 1;
                 } else {
                     $r_m = $r_m - 1;
                 }
                 $true_repay_time = 1;
                 $v['repay_start_time'] = to_timespan($r_y . "-" . $r_m . "-" . $r_d, "Y-m-d") + $v['repay_time'] * 24 * 3600;
             }
             //到期还本息
             if ($v['loantype'] == 2) {
                 $y = to_date($v['repay_start_time'], "Y");
                 $m = to_date($v['repay_start_time'], "m");
                 $d = to_date($v['repay_start_time'], "d");
                 $y = $y + intval(($m + $true_repay_time) / 12);
                 $m = ($m + $true_repay_time) % 12;
                 $next_repay_time = to_timespan($y . "-" . $m . "-" . $d, "Y-m-d");
             } else {
                 $next_repay_time = next_replay_month($v['repay_start_time']);
             }
         }
         //计算最近一期该还多少
         if ($v["loantype"] == 0) {
             $repay_money = pl_it_formula($v['borrow_amount'], $v['rate'] / 12 / 100, $true_repay_time);
         } elseif ($v['loantype'] == 1) {
             $repay_money = av_it_formula($v['borrow_amount'], $v['rate'] / 12 / 100);
         } elseif ($v['loantype'] == 2) {
             $repay_money = $v['borrow_amount'] * $v['rate'] / 12 / 100 * $true_repay_time;
         }
         if ($v['repay_time_type'] == 1) {
             $idx = ((int) to_date(TIME_UTC, "Y") - (int) to_date($v['repay_start_time'], "Y")) * 12 + ((int) to_date(TIME_UTC, "m") - (int) to_date($v['repay_start_time'], "m"));
             if ($true_repay_time == $idx) {
                 if ($v['loantype'] == 0) {
                     $repay_money = $repay_money * 12 - ($idx - 1) * round($repay_money, 2);
                 } elseif ($v['loantype'] == 1) {
                     $repay_money = $repay_money + $v['borrow_amount'];
                 } elseif ($v['loantype'] == 2) {
                     $repay_money = $repay_money + $v['borrow_amount'];
                 }
             }
         }
         //站内信
         $content = "您在" . app_conf("SHOP_TITLE") . "的借款 “<a href=\"" . url("index", "deal", array("id" => $v['id'])) . "\">" . $v['name'] . "</a>”," . "最近一期还款将于" . to_date($next_repay_time, "d") . "日到期,需还金额" . round($repay_money, 2) . "元。";
         $group_arr = array(0, $v['user_id']);
         sort($group_arr);
         $group_arr[] = 4;
         $msg_data['content'] = $content;
         $msg_data['to_user_id'] = $v['user_id'];
         $msg_data['create_time'] = TIME_UTC;
         $msg_data['type'] = 0;
         $msg_data['group_key'] = implode("_", $group_arr);
         $msg_data['is_notice'] = 12;
         $msg_data['fav_id'] = $v['id'];
         $GLOBALS['db']->autoExecute(DB_PREFIX . "msg_box", $msg_data);
         $id = $GLOBALS['db']->insert_id();
         $GLOBALS['db']->query("update " . DB_PREFIX . "msg_box set group_key = '" . $msg_data['group_key'] . "_" . $id . "' where id = " . $id);
         $user_info = D("User")->where("id=" . $v['user_id'])->find();
         //邮件
         if (app_conf("MAIL_ON") == 1) {
             $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_THREE_EMAIL'");
             $tmpl_content = $tmpl['content'];
             $notice['user_name'] = $user_info['user_name'];
             $notice['deal_name'] = $v['name'];
             $notice['deal_url'] = SITE_DOMAIN . url("index", "deal", array("id" => $v['id']));
             $notice['repay_url'] = SITE_DOMAIN . url("index", "uc_deal#refund");
             $notice['repay_time_y'] = to_date($next_repay_time, "Y");
             $notice['repay_time_m'] = to_date($next_repay_time, "m");
             $notice['repay_time_d'] = to_date($next_repay_time, "d");
             $notice['site_name'] = app_conf("SHOP_TITLE");
             $notice['repay_money'] = round($repay_money, 2);
             $notice['help_url'] = SITE_DOMAIN . url("index", "helpcenter");
             $notice['msg_cof_setting_url'] = SITE_DOMAIN . url("index", "uc_msg#setting");
             $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 (app_conf("SMS_ON") == 1) {
             $tmpl = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_THREE_SMS'");
             $tmpl_content = $tmpl['content'];
             $notice['user_name'] = $user_info["user_name"];
             $notice['deal_name'] = $v['name'];
             $notice['repay_time_y'] = to_date($next_repay_time, "Y");
             $notice['repay_time_m'] = to_date($next_repay_time, "m");
             $notice['repay_time_d'] = to_date($next_repay_time, "d");
             $notice['site_name'] = app_conf("SHOP_TITLE");
             $notice['repay_money'] = round($repay_money, 2);
             $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", array("send_three_msg_time" => $next_repay_time), "UPDATE", "id=" . $v['id']);
     }
     //成功提示
     if ($deal_ids) {
         save_log(implode(",", $deal_ids) . "发送三日内还款提示", 1);
     }
     $this->success("发送成功");
 }
Example #8
0
 function ajax_calculate()
 {
     $rate = $_REQUEST['apr'] / 12;
     $borrowpay = intval($_REQUEST['borrowpay']);
     $borrowamount = intval($_REQUEST['borrowamount']);
     $repaytime = intval($_REQUEST['repaytime']);
     $apr = trim($_REQUEST['apr']);
     $GLOBALS['tmpl']->assign("borrowpay", $borrowpay);
     $lixi = 0;
     //等额本息
     if ($borrowpay == 0) {
         $repayamount = pl_it_formula($borrowamount, $rate / 100, $repaytime);
     } elseif ($borrowpay == 1) {
         $lixi = av_it_formula($borrowamount, $rate / 100);
         $lixi = round($lixi, 2);
         $repayamount = 0;
         $GLOBALS['tmpl']->assign("lixi", $lixi);
     } elseif ($borrowpay == 2) {
         $lixi = $borrowamount * $rate / 100 * $repaytime;
         $lixi = round($lixi, 2);
         $repayamount = $lixi + $borrowamount;
         $GLOBALS['tmpl']->assign("lixi", $lixi);
     }
     $GLOBALS['tmpl']->assign("borrowamount", $borrowamount);
     $GLOBALS['tmpl']->assign("apr", $apr);
     $GLOBALS['tmpl']->assign("rate", $rate);
     $GLOBALS['tmpl']->assign("repaytime", $repaytime);
     $GLOBALS['tmpl']->assign("repayamount", $repayamount);
     //等额本息
     if ($borrowpay == 0) {
         $repayallamount = $repayamount * $repaytime;
     } elseif ($borrowpay == 1) {
         $repayallamount = $borrowamount + $lixi * $repaytime;
     } elseif ($borrowpay == 2) {
         $repayallamount = $borrowamount + $lixi;
     }
     $GLOBALS['tmpl']->assign("repayallamount", $repayallamount);
     if (isset($_REQUEST['isshow']) && intval($_REQUEST['isshow']) == 1) {
         //=======================================本息还款计算开始=================================
         if ($borrowpay == 0) {
             //月还本金
             $r_smoney = 0;
             //月还本息
             $r_rmoney = 0;
             //借款管理费
             $r_mmoney = $borrowamount * trim(app_conf('MANAGE_FEE')) / 100;
             //本金余额
             $l_money = $borrowamount;
             //本息余额
             $r_money = $repayallamount;
             $list = null;
             //$had_repay_money = 0;
             for ($i = 1; $i <= $repaytime; $i++) {
                 $l_money = $l_money - $r_smoney;
                 //月还利息
                 $list[$i]['r_rmoney'] = $l_money * $rate / 100;
                 //本息余额
                 if ($i == $repaytime) {
                     $after_money = round($repayamount, 2);
                     $after_month = $i - 1;
                     $list[$i]['repayamount'] = $repayallamount - $after_month * $after_money;
                     //月还本金
                     $list[$i]['r_smoney'] = $list[$i]['repayamount'] - $list[$i]['r_rmoney'];
                     $list[$i]['r_money'] = 0;
                 } else {
                     //月还本息
                     $list[$i]['repayamount'] = $repayamount;
                     //月还本金
                     $r_smoney = $list[$i]['r_smoney'] = $repayamount - $list[$i]['r_rmoney'];
                     //本息余额
                     if ($i + 1 == $repaytime) {
                         $r_money = $r_money - $list[$i]['r_rmoney'] - $list[$i]['r_smoney'];
                         $after_money = round($repayamount, 2);
                         $after_month = $i;
                         $list[$i]['r_money'] = $repayallamount - $after_month * $after_money;
                     } else {
                         $r_money = $list[$i]['r_money'] = $r_money - $list[$i]['r_rmoney'] - $list[$i]['r_smoney'];
                     }
                 }
             }
             $GLOBALS['tmpl']->assign("list", $list);
             $GLOBALS['tmpl']->assign("r_mmoney", $r_mmoney);
         } elseif ($borrowpay == 1) {
             //借款管理费
             $r_mmoney = $borrowamount * trim(app_conf('MANAGE_FEE')) / 100;
             //本金余额
             $l_money = $borrowamount;
             //本息余额
             $r_money = $repayallamount;
             $list = null;
             $r_smoney = 0;
             for ($i = 1; $i <= $repaytime; $i++) {
                 //月还利息
                 $list[$i]['r_rmoney'] = $lixi;
                 if ($i == $repaytime) {
                     $list[$i]['repayamount'] = $l_money + $lixi;
                     //月还本金
                     $list[$i]['r_smoney'] = $borrowamount;
                     $list[$i]['r_money'] = 0;
                 } else {
                     $list[$i]['repayamount'] = $lixi;
                     //月还本金
                     $r_smoney = $list[$i]['r_smoney'] = 0;
                     //本息余额
                     $r_money = $list[$i]['r_money'] = $r_money - $list[$i]['r_rmoney'] - $list[$i]['r_smoney'];
                 }
             }
             $GLOBALS['tmpl']->assign("list", $list);
             $GLOBALS['tmpl']->assign("r_mmoney", $r_mmoney);
         } elseif ($borrowpay == 2) {
             //借款管理费
             $r_mmoney = $borrowamount * trim(app_conf('MANAGE_FEE')) / 100 * $repaytime;
             //本金余额
             $l_money = $borrowamount;
             //本息余额
             $r_money = $repayallamount;
             $list = null;
             $list[1]['r_rmoney'] = $lixi;
             $list[1]['repayamount'] = $l_money + $lixi;
             //月还本金
             $list[1]['r_smoney'] = $borrowamount;
             $list[1]['r_money'] = 0;
             $GLOBALS['tmpl']->assign("list", $list);
             $GLOBALS['tmpl']->assign("r_mmoney", $r_mmoney);
         }
         //=================================到期还本息结束=================================
     }
     $GLOBALS['tmpl']->display("inc/tool/calculate_result.html");
 }
Example #9
0
function format_deal_item(&$deal)
{
    //判断是否已经开始
    $deal['is_wait'] = 0;
    if ($deal['start_time'] > TIME_UTC) {
        $deal['is_wait'] = 1;
        $deal['remain_time'] = $deal['start_time'] - TIME_UTC;
    } else {
        $deal['remain_time'] = $deal['start_time'] + $deal['enddate'] * 24 * 3600 - TIME_UTC;
    }
    //当为天的时候
    if ($deal['repay_time_type'] == 0) {
        $true_repay_time = 1;
    } else {
        $true_repay_time = $deal['repay_time'];
    }
    if (trim($deal['titlecolor']) != '') {
        $deal['color_name'] = "<span style='color:#" . $deal['titlecolor'] . "'>" . $deal['name'] . "</span>";
    } else {
        $deal['color_name'] = $deal['name'];
    }
    //格式化数据
    $deal['borrow_amount_format'] = format_price($deal['borrow_amount'] / 10000) . "万";
    format_price($deal['borrow_amount']);
    $deal['rate_foramt'] = number_format($deal['rate'], 2);
    //$deal['borrow_amount_format_w'] = format_price($deal['borrow_amount']/10000)."万";
    $deal['rate_foramt_w'] = number_format($deal['rate'], 2) . "%";
    //本息还款金额
    if ($deal['loantype'] == 0) {
        $deal['month_repay_money'] = pl_it_formula($deal['borrow_amount'], $deal['rate'] / 12 / 100, $true_repay_time);
    } elseif ($deal['loantype'] == 1) {
        $deal['month_repay_money'] = av_it_formula($deal['borrow_amount'], $deal['rate'] / 12 / 100);
    } elseif ($deal['loantype'] == 2) {
        $deal['month_repay_money'] = $deal['borrow_amount'] * $deal['rate'] / 12 / 100 * $true_repay_time;
    }
    $deal['month_repay_money_format'] = format_price($deal['month_repay_money']);
    //到期还本息管理费
    $deal['month_manage_money'] = $deal['borrow_amount'] * app_conf('MANAGE_FEE') / 100;
    $deal['month_manage_money_format'] = format_price($deal['month_manage_money']);
    $deal['all_manage_money'] = $deal['month_manage_money'] * $deal["repay_time"];
    $deal['true_month_repay_money'] = $deal['month_repay_money'] + $deal['month_manage_money'];
    //还需多少钱
    $deal['need_money'] = format_price($deal['borrow_amount'] - $deal['load_money']);
    //百分比
    $deal['progress_point'] = $deal['load_money'] / $deal['borrow_amount'] * 100;
    $deal['user'] = get_user("user_name,level_id,province_id,city_id", $deal['user_id']);
    if ($deal['cate_id'] > 0) {
        $deal['cate_info'] = $GLOBALS['db']->getRowCached("select id,name,brief,uname,icon from " . DB_PREFIX . "deal_cate where id = " . $deal['cate_id'] . " and is_effect = 1 and is_delete = 0");
    }
    if ($deal['type_id'] > 0) {
        $deal['type_info'] = $GLOBALS['db']->getRowCached("select id,name,brief,uname,icon from " . DB_PREFIX . "deal_loan_type where id = " . $deal['type_id'] . " and is_effect = 1 and is_delete = 0");
    }
    if ($deal['deal_status'] != 1 || $deal['remain_time'] <= 0) {
        $deal['remain_time_format'] = "0" . $GLOBALS['lang']['DAY'] . "0" . $GLOBALS['lang']['HOUR'] . "0" . $GLOBALS['lang']['MIN'];
    } else {
        $deal['remain_time_format'] = remain_time($deal['remain_time']);
    }
    $deal['min_loan_money_format'] = format_price($deal['min_loan_money']);
    if ($deal['deal_status'] == 4) {
        if ($deal['repay_time_type'] == 0) {
            /*
             $r_y = to_date($deal['repay_start_time'],"Y");
            $r_m = to_date($deal['repay_start_time'],"m");
            $r_d = to_date($deal['repay_start_time'],"d");
            if($r_m-1 <=0){
            $r_m = 12;
            $r_y = $r_y-1;
            }
            else{
            $r_m = $r_m - 1;
            }
            $deal["type_repay_start_time"]  = to_timespan($r_y."-".$r_m."-".$r_d,"Y-m-d") + $deal['repay_time']*24*3600;
            */
            $deal["type_repay_start_time"] = next_replay_month($deal['repay_start_time'], "-1") + $deal['repay_time'] * 24 * 3600;
            $deal["type_next_repay_time"] = next_replay_month($deal['type_repay_start_time']);
        }
        if ($deal['last_repay_time'] > 0) {
            $deal["next_repay_time"] = next_replay_month($deal['last_repay_time']);
        } else {
            $deal["next_repay_time"] = next_replay_month($deal['repay_start_time']);
        }
        $deal["next_repay_time_format"] = to_date($deal['next_repay_time'], 'Y-m-d');
        //总的必须还多少本息
        //
        if ($deal['loantype'] == 0) {
            $deal['remain_repay_money'] = $deal['month_repay_money'] * $true_repay_time;
        } elseif ($deal['loantype'] == 1) {
            //每月还息,到期还本
            $deal['remain_repay_money'] = $deal['borrow_amount'] + $deal['month_repay_money'] * $true_repay_time;
        } elseif ($deal['loantype'] == 2) {
            $deal['remain_repay_money'] = $deal['borrow_amount'] + $deal['month_repay_money'];
        }
        //还有多少需要还
        $deal['need_remain_repay_money'] = $deal['remain_repay_money'] - $deal['repay_money'];
        //还款进度条
        if ($deal['remain_repay_money'] > 0) {
            $deal['repay_progress_point'] = $deal['repay_money'] / $deal['remain_repay_money'] * 100;
        } else {
            $deal['repay_progress_point'] = 0;
        }
        //最后一期还款
        if ($deal['loantype'] == 2) {
            $deal['last_month_repay_money'] = $deal['remain_repay_money'];
        } else {
            $deal['last_month_repay_money'] = $deal['remain_repay_money'] - $deal['month_repay_money'] * ($true_repay_time - 1);
        }
        //最后的还款日期
        /*$y=to_date($deal['repay_start_time'],"Y");
        			$m=to_date($deal['repay_start_time'],"m");
        		$d=to_date($deal['repay_start_time'],"d");
        		$y = $y + intval(($m+$true_repay_time)/12);
        		$m = ($m+$true_repay_time)%12;
        
        		$deal["end_repay_time"] = to_timespan($y."-".$m."-".$d,"Y-m-d");
        		*/
        $deal["end_repay_time"] = next_replay_month($deal['repay_start_time'], $true_repay_time);
        if (to_date($deal["end_repay_time"], "Ymd") < to_date(TIME_UTC, "Ymd")) {
            $deal['exceed_the_time'] = true;
        }
        //罚息
        $is_check_impose = true;
        //到期还本息 只有最后一个月后才算罚息
        if ($deal['loantype'] == 2) {
            //算出到期还本息的最后一个月是否小于今天
            if ($deal['exceed_the_time']) {
                $is_check_impose = true;
            } else {
                $is_check_impose = false;
            }
        }
        if ($deal["next_repay_time"] - TIME_UTC < 0 && $is_check_impose) {
            //晚多少天
            $time_span = to_timespan(to_date(TIME_UTC, "Y-m-d"), "Y-m-d");
            $next_time_span = to_timespan(to_date($deal['next_repay_time'], "Y-m-d"), "Y-m-d");
            $day = ceil(($time_span - $next_time_span) / 24 / 3600);
            $impose_fee = trim($deal['impose_fee_day1']);
            $manage_impose_fee = trim($deal['manage_impose_fee_day1']);
            //判断是否严重逾期
            if ($day >= app_conf('YZ_IMPSE_DAY')) {
                $impose_fee = trim($deal['impose_fee_day2']);
                $manage_impose_fee = trim($deal['manage_impose_fee_day2']);
            }
            $impose_fee = floatval($impose_fee);
            $manage_impose_fee = floatval($manage_impose_fee);
            //罚息
            $deal['impose_money'] = $deal['month_repay_money'] * $impose_fee * $day / 100;
            //罚管理费
            $deal['manage_impose_money'] = $deal['month_repay_money'] * $manage_impose_fee * $day / 100;
            $deal['impose_money'] += $deal['manage_impose_money'];
        }
    }
    if ($deal['publis_wait'] == 1 || $deal['publis_wait'] == 0) {
        $deal['publis_time_format'] = to_date($deal['create_time'], 'Y-m-d H:i');
    } else {
        $deal['publis_time_format'] = to_date($deal['start_time'], 'Y-m-d H:i');
    }
    $durl = url("index", "deal", array("id" => $deal['id']));
    $deal['share_url'] = SITE_DOMAIN . $durl;
    if ($GLOBALS['user_info']) {
        if (app_conf("URL_MODEL") == 0) {
            $deal['share_url'] .= "&r=" . base64_encode(intval($GLOBALS['user_info']['id']));
        } else {
            $deal['share_url'] .= "?r=" . base64_encode(intval($GLOBALS['user_info']['id']));
        }
    }
    $deal['url'] = $durl;
    if (!empty($user_name) && !empty($user_pwd)) {
        $durl = "/index.php?ctl=uc_deal&act=mrefdetail&id=" . $deal['id'] . "&user_name=" . $user_name . "&user_pwd=" . $user_pwd;
    } else {
        $durl = "/index.php?ctl=deal&act=mobile&id=" . $deal['id'];
    }
    $deal['app_url'] = str_replace("/mapi", "", SITE_DOMAIN . $durl);
}