public function index()
 {
     $root = array();
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     $deal_id = intval($GLOBALS['request']['id']);
     $l_key = intval($GLOBALS['request']['l_key']);
     //$l_key = 2;
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     $user_id = intval($user['id']);
     if ($user_id > 0) {
         require APP_ROOT_PATH . 'app/Lib/deal.php';
         $root['user_login_status'] = 1;
         $deal = get_deal($deal_id, 0);
         $root['deal'] = $deal;
         $page = intval($GLOBALS['request']['page']);
         if ($page == 0) {
             $page = 1;
         }
         $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
         $count = $GLOBALS['db']->getOne(" SELECT count(*) FROM " . DB_PREFIX . "deal_load_repay dlr where dlr.deal_id ='{$deal_id}' and dlr.l_key='{$l_key}' ");
         //				$load_user = $GLOBALS['db']->getAll("SELECT dlr.*,u.user_name FROM ".DB_PREFIX."deal_load_repay dlr left join  ".DB_PREFIX."user u on dlr.user_id = u.id  where dlr.deal_id ='$deal_id' and dlr.l_key='$l_key' order by dlr.id limit $limit ");
         //				$root['page'] = array("page"=>$page,"page_total"=>ceil($count/app_conf("PAGE_SIZE")),"page_size"=>app_conf("PAGE_SIZE"));
         //				foreach ($load_user as $k=>$v)
         //				{
         //					//$load_user[$k]['month_repay_money']=$v['self_money']+$v['interest_money'];
         //					$load_user[$k]['month_repay_money']=$v['repay_money'];
         //				}
         //
         //				$root['load_user'] = $load_user;
         $load_user = get_deal_user_load_list($deal, 0, $l_key, -1, 0, 0, 1, $limit);
         $root['page'] = array("page" => $page, "page_total" => ceil($count / app_conf("PAGE_SIZE")), "page_size" => app_conf("PAGE_SIZE"));
         $root['load_user'] = $load_user['item'];
         $root['response_code'] = 1;
         $root['show_err'] = '';
     } else {
         $root['response_code'] = 0;
         $root['show_err'] = "未登录";
         $root['user_login_status'] = 0;
     }
     $root['program_title'] = "查看明细";
     output($root);
 }
 /**
  * 还款
  * @param int $deal_id  标的id	 
  * @param int $l_key  还款期号
  * @return string
  */
 function RepaymentNewTrade()
 {
     $deal_id = intval(strim($_REQUEST['deal_id']));
     //$deal_repay_id = intval(strim($_REQUEST['deal_repay_id']));
     $l_key = intval(strim($_REQUEST['l_key']));
     require_once APP_ROOT_PATH . "app/Lib/deal_func.php";
     $deal = get_deal($deal_id);
     //
     if (!empty($deal)) {
         if (!empty($deal['ips_bill_no'])) {
             /*
             //$deal = get_deal($deal_id);
             if(!$deal || $deal['user_id']!=$GLOBALS['user_info']['id'] || $deal['deal_status']!=4){
             	$root["show_err"] = "操作失败!";
             	return $root;
             }
             */
             //$ids = explode(",",$ids);
             //has_repay 0未还,1已还 2部分还款
             //判断上期是否已经还完
             $pl_key = $l_key - 1;
             $sql = "select id from " . DB_PREFIX . "deal_repay where has_repay in(0,2) and l_key = " . $pl_key . " and deal_id =" . $deal_id;
             $deal_repay_id = intval($GLOBALS['db']->getOne($sql));
             if (intval($deal_repay_id) == 0) {
                 $sql = "select id from " . DB_PREFIX . "deal_repay where has_repay in(0,2) and l_key = " . $l_key . " and deal_id =" . $deal_id;
                 $deal_repay_id = intval($GLOBALS['db']->getOne($sql));
                 if ($deal_repay_id > 0) {
                     //echo $deal_repay_id;exit;
                     $class_name = 'Ips';
                     require_once APP_ROOT_PATH . "system/collocation/" . $class_name . "_collocation.php";
                     $collocation_class = $class_name . "_collocation";
                     $collocation_object = new $collocation_class();
                     $page = 0;
                     $page_num = 4;
                     do {
                         $page = $page + 1;
                         $limit = ($page - 1) * $page_num . "," . $page_num;
                         $result = get_deal_user_load_list($deal, 0, $l_key, -1, 0, 1, 1, $limit);
                         if (count($result['item']) > 0) {
                             $collocation_code = $collocation_object->RepaymentNewTrade($deal, $result['item'], $deal_repay_id);
                             print_r($collocation_code);
                         }
                     } while (count($result['item']) >= $page_num);
                 } else {
                     showErr("未找到还款计划或该期({$l_key})已还清", 0);
                 }
             } else {
                 showErr("上期({$pl_key})还未还清:" . $deal_repay_id, 0);
             }
         } else {
             showErr('该标已经发布登记:' . $deal['ips_bill_no'], 0);
         }
     } else {
         showErr('标的ID不存在:' . $deal_id, 0);
     }
 }
Exemple #3
0
 function get_user_load_item()
 {
     $deal_id = intval($_REQUEST['deal_id']);
     $l_key = intval($_REQUEST['l_key']);
     $obj = strim($_REQUEST['obj']);
     if ($deal_id == 0) {
         showErr("数据错误", 1);
     }
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $deal_info = get_deal($deal_id);
     if (!$deal_info) {
         showErr("借款不存在", 1);
     }
     //输出投标列表
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
     $result = get_deal_user_load_list($deal_info, 0, $l_key, -1, 0, 0, 1, $limit);
     $rs_count = $result['count'];
     $page_all = ceil($rs_count / app_conf("PAGE_SIZE"));
     $GLOBALS['tmpl']->assign("load_user", $result['item']);
     $GLOBALS['tmpl']->assign("l_key", $l_key);
     $GLOBALS['tmpl']->assign("page_all", $page_all);
     $GLOBALS['tmpl']->assign("rs_count", $rs_count);
     $GLOBALS['tmpl']->assign("page", $page);
     $GLOBALS['tmpl']->assign("deal_id", $deal_id);
     $GLOBALS['tmpl']->assign("obj", $obj);
     $GLOBALS['tmpl']->assign("page_prev", $page - 1);
     $GLOBALS['tmpl']->assign("page_next", $page + 1);
     $html = $GLOBALS['tmpl']->fetch("inc/uc/ajax_load_user.html");
     showSuccess($html, 1);
 }
 function repay_plan_a()
 {
     $deal_id = intval($_REQUEST['deal_id']);
     $l_key = intval($_REQUEST['l_key']);
     $obj = strim($_REQUEST['obj']);
     if ($deal_id == 0) {
         $this->error("数据错误");
     }
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $deal_info = get_deal($deal_id);
     if (!$deal_info) {
         $this->error("借款不存在");
     }
     //输出投标列表
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $page_size = 10;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $result = get_deal_user_load_list($deal_info, 0, $l_key, -1, 0, 0, 1, $limit);
     foreach ($result['item'] as $k => $v) {
         $result['item'][$k]['interest_money'] = format_price($v['interest_money']);
     }
     $rs_count = $result['count'];
     $page_all = ceil($rs_count / $page_size);
     $this->assign("load_user", $result['item']);
     $this->assign("l_key", $l_key);
     $this->assign("page_all", $page_all);
     $this->assign("rs_count", $rs_count);
     $this->assign("page", $page);
     $this->assign("deal_id", $deal_id);
     $this->assign("obj", $obj);
     $this->assign("page_prev", $page - 1);
     $this->assign("page_next", $page + 1);
     $html = $this->fetch();
     $this->success($html);
 }
 public function export_csv($page = 1)
 {
     set_time_limit(0);
     $limit = ($page - 1) * intval(app_conf("BATCH_PAGE_SIZE")) . "," . intval(app_conf("BATCH_PAGE_SIZE"));
     $id = intval($_REQUEST['id']);
     $deal = get_deal($id);
     //定义条件
     if ($id == 0) {
         showErr("操作失败!");
     }
     if (!$deal) {
         showErr("借款不存在!");
     }
     if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
         showErr("不属于你的借款!");
     }
     if ($deal['deal_status'] != 4) {
         showErr("借款不是还款状态!");
     }
     $list = get_deal_load_list($deal);
     foreach ($list as $k => $v) {
         $result_min = get_deal_user_load_list($deal, 0, $list[$k]['l_key'], -1, 0, 0, 1, $limit);
         $list[$k]['item'] = $result_min['item'];
     }
     if ($list) {
         register_shutdown_function(array(&$this, 'export_csv_repay'), $page + 1);
         $repay_value = array('l_key_index' => '""', 'repay_day_format' => '""', 'month_has_repay_money_all_format' => '""', 'month_need_all_repay_money_format' => '""', 'month_repay_money_format' => '""', 'month_manage_money_format' => '""', 'impose_all_money_format' => '""', 'status_format' => '""');
         //if($page == 1)
         $content = "";
         foreach ($list as $k => $v) {
             $contentss = iconv("utf-8", "gbk", "还款期数,还款日,已还总额,待还总额,待还本息,管理费,逾期/违约金,状态");
             $content .= $contentss . "\n";
             $repay_value = array();
             $repay_value['l_key_index'] = iconv('utf-8', 'gbk', '" 第' . $v['l_key_index'] . '期"');
             $repay_value['repay_day_format'] = iconv('utf-8', 'gbk', '"' . $v['repay_day_format'] . '"');
             $repay_value['month_has_repay_money_all_format'] = iconv('utf-8', 'gbk', '"' . $v['month_has_repay_money_all_format'] . '"');
             $repay_value['month_need_all_repay_money_format'] = iconv('utf-8', 'gbk', '"' . $v['month_need_all_repay_money_format'] . '"');
             $repay_value['month_repay_money_format'] = iconv('utf-8', 'gbk', '"' . $v['month_repay_money_format'] . '"');
             $repay_value['month_manage_money_format'] = iconv('utf-8', 'gbk', '"' . $v['month_manage_money_format'] . '"');
             $repay_value['impose_all_money_format'] = iconv('utf-8', 'gbk', '"' . $v['impose_all_money_format'] . '"');
             $repay_value['status_format'] = iconv('utf-8', 'gbk', '"' . $v['status_format'] . '"');
             $content .= implode(",", $repay_value) . "\n";
             foreach ($list[$k]['item'] as $kk => $vv) {
                 $repay_value_item = array('id' => '""', 't_user_name' => '""', 'month_repay_money_formats' => '""', 'impose_money_format' => '""', 'status_formats' => '""');
                 $contents = iconv("utf-8", "gbk", "借款单号,会员,还款本息 ,逾期/违约金,状态");
                 $content .= $contents . "\n";
                 $repay_value_item['id'] = iconv('utf-8', 'gbk', '"' . $list[$k]['item'][$kk]['id'] . '"');
                 $repay_value_item['t_user_name'] = iconv('utf-8', 'gbk', '"' . $list[$k]['item'][$kk]['t_user_name'] . '"');
                 $repay_value_item['month_repay_money_formats'] = iconv('utf-8', 'gbk', '"' . $list[$k]['item'][$kk]['month_repay_money_format'] . '"');
                 $repay_value_item['impose_money_format'] = iconv('utf-8', 'gbk', '"' . $list[$k]['item'][$kk]['impose_money_format'] . '"');
                 $repay_value_item['status_formats'] = iconv('utf-8', 'gbk', '"' . $list[$k]['item'][$kk]['status_format'] . '"');
                 $content .= implode(",", $repay_value_item) . "\n";
             }
         }
         header("Content-Disposition: attachment; filename=repay_list.csv");
         echo $content;
     } else {
         if ($page == 1) {
             $this->error(L("NO_RESULT"));
         }
     }
 }
 public function index()
 {
     $root = array();
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     $id = intval($GLOBALS['request']['id']);
     $load_id = intval($GLOBALS['request']['load_id']);
     //检查用户,用户密码
     $user = user_check($email, $pwd);
     //$user_id  = intval($user['id']);
     $user_id = $GLOBALS['user_info']['id'];
     if ($user_id > 0) {
         require APP_ROOT_PATH . 'app/Lib/deal.php';
         $root['user_login_status'] = 1;
         $deal = get_deal($id);
         $root['deal'] = $deal;
         if (!$deal || $deal['deal_status'] < 4) {
             $root['show_err'] = "操作失败!";
             $root['response_code'] = 0;
         } else {
             $temp_user_load = $GLOBALS['db']->getRow("SELECT dl.id,dl.deal_id,dl.user_id,dl.money,dlt.t_user_id FROM " . DB_PREFIX . "deal_load dl left join " . DB_PREFIX . "deal_load_transfer dlt on dlt.load_id = dl.id WHERE dl.deal_id=" . $id . " and dl.id=" . $load_id);
             $user_load_ids = array();
             if ($temp_user_load) {
                 $u_key = $GLOBALS['db']->getOne("SELECT u_key FROM " . DB_PREFIX . "deal_load_repay WHERE load_id=" . $load_id . " and (user_id=" . $user_id . " or t_user_id = " . $user_id . ")");
                 //					if(($temp_user_load["user_id"] == $user_id && intval($temp_user_load['t_user_id']) == 0 )|| $temp_user_load['t_user_id'] == $user_id){
                 $temp_user_load['repay_start_time'] = $deal['repay_start_time'];
                 $temp_user_load['repay_time'] = $deal['repay_time'];
                 $temp_user_load['rate'] = $deal['rate'];
                 $temp_user_load['u_key'] = $u_key;
                 $temp_user_load['load'] = get_deal_user_load_list($deal, $user_load_ids['user_id'], -1, 1);
                 $temp_user_load['impose_money'] = 0;
                 $temp_user_load['manage_fee'] = 0;
                 $temp_user_load['repay_money'] = 0;
                 $temp_user_load['manage_interest_money'] = 0;
                 foreach ($temp_user_load['load'] as $kk => $vv) {
                     $temp_user_load['impose_money'] += $vv['impose_money'];
                     $temp_user_load['manage_fee'] += $vv['manage_money'];
                     $temp_user_load['repay_money'] += $vv['month_has_repay_money'];
                     $temp_user_load['manage_interest_money'] += floatval($vv['manage_interest_money']);
                     //预期收益
                     $temp_user_load['load'][$kk]['yuqi_money'] = format_price($vv['month_repay_money'] - $vv['self_money'] - $vv['manage_money'] - $vv['manage_interest_money']);
                     //实际收益
                     if ($vv['has_repay'] == 1) {
                         $temp_user_load['load'][$kk]['real_money'] = format_price($vv['month_repay_money'] - $vv['self_money'] + $vv['impose_money'] - $vv['manage_money'] - $vv['manage_interest_money']);
                     }
                 }
                 $user_load_ids[] = $temp_user_load;
                 //					}
             }
             $inrepay_info = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_inrepay_repay WHERE deal_id={$id}");
             $root['inrepay_info'] = $inrepay_info;
             $root['true_repay_time_format'] = to_date($inrepay_info['true_repay_time'], 'Y-m-d');
             $root['user_load_ids'] = $user_load_ids;
             $root['load_id'] = $load_id;
             $root['response_code'] = 1;
             $root['show_err'] = '';
         }
     } else {
         $root['response_code'] = 0;
         $root['show_err'] = "未登录";
         $root['user_login_status'] = 0;
     }
     $root['program_title'] = "回款详情";
     output($root);
 }
Exemple #7
0
 function do_repay_plan_export_load($page = 1)
 {
     $pages = 1;
     $id = intval($_REQUEST['id']);
     $l_key = intval($_REQUEST['l_key']);
     set_time_limit(0);
     $limit = ($page - 1) * intval(app_conf("BATCH_PAGE_SIZE")) . "," . intval(app_conf("BATCH_PAGE_SIZE"));
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $deal_info = get_deal($id, 0);
     $content = "";
     $contents = "";
     if ($page == 1) {
         $repay_list = get_deal_load_list($deal_info);
         if ($repay_list) {
             $repay_plan_value_s = array('l_key' => '""', 'repay_day_format' => '""', 'month_has_repay_money_all_format' => '""', 'month_need_all_repay_money_format' => '""', 'month_need_all_repay_money' => '""', 'month_repay_money_format' => '""', 'month_manage_money_format' => '""', 'impose_money_format' => '""', 'manage_money_impose_format' => '""', 'status_format');
             if ($page == 1) {
                 $contents = iconv("utf-8", "gbk", "借款期数,还款日,已还金额,待还金额,还需还金额,到期应还本息,管理费,逾期费用,逾期管理费,还款情况");
             }
             if ($page == 1) {
                 $contents = $contents . "\n";
             }
             $repay_plan_value_s = array();
             $repay_plan_value_s['l_key'] = iconv('utf-8', 'gbk', '"' . ($repay_list[$l_key]['l_key'] + 1) . '"');
             $repay_plan_value_s['repay_day_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['repay_day_format'] . '"');
             $repay_plan_value_s['month_has_repay_money_all_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['month_has_repay_money_all_format'] . '"');
             $repay_plan_value_s['month_need_all_repay_money_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['month_need_all_repay_money_format'] . '"');
             $repay_plan_value_s['month_need_all_repay_money'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['month_need_all_repay_money_format'] . '"');
             $repay_plan_value_s['month_repay_money_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['month_repay_money_format'] . '"');
             $repay_plan_value_s['month_manage_money_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['month_manage_money_format'] . '"');
             $repay_plan_value_s['impose_money_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['impose_money_format'] . '"');
             $repay_plan_value_s['manage_money_impose_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['manage_money_impose_format'] . '"');
             $repay_plan_value_s['status_format'] = iconv('utf-8', 'gbk', '"' . $repay_list[$l_key]['status_format'] . '"');
             $contents .= implode(",", $repay_plan_value_s) . "\n";
         }
     }
     $sqll = array(deal_id => $id, l_key => $l_key);
     $deal_info = get_deal($sqll['deal_id']);
     //($deal_info,0,$l_key,-1,0,0,1,$limit)
     $listss = get_deal_user_load_list($deal_info, 0, $sqll['l_key'], -1, 0, 0, 1, $limit);
     // get_deal_load_list($deal_info);
     foreach ($listss['item'] as $k => $v) {
         $listss['item'][$k]['yuqi_money'] = format_price($v['month_repay_money'] + $v['impose_money'] - $v['self_money'] - $v['manage_money']);
         if ($v['has_repay'] == 1) {
             $listss['item'][$k]['real_money'] = format_price($v['month_repay_money'] + $v['impose_money'] - $v['self_money'] - $v['manage_money']);
         } else {
             $listss['item'][$k]['real_money'] = format_price("0.00");
         }
     }
     $lists = $listss['item'];
     if ($lists) {
         register_shutdown_function(array(&$this, 'do_repay_plan_export_load'), $page + 1);
         $repay_plan_value = array('id' => '""', 'user_name' => '""', 'month_repay_money_format' => '""', 'impose_money_format' => '""', 'yuqi_money' => '""', 'real_money' => '""', 'status_format' => '""', 'site_repay_format' => '""');
         if ($page == 1) {
             $content = iconv("utf-8", "gbk", "借款编号,会员,还款金额,逾期罚息,预期收益,实际收益,状态,还款人");
         }
         if ($page == 1) {
             $content = $content . "\n";
         }
         foreach ($lists as $k => $v) {
             $repay_plan_value = array();
             $repay_plan_value['id'] = iconv('utf-8', 'gbk', '"' . $v['id'] . '"');
             $repay_plan_value['user_name'] = iconv('utf-8', 'gbk', '"' . $v['user_name'] . '"');
             $repay_plan_value['month_repay_money_format'] = iconv('utf-8', 'gbk', '"' . $v['month_repay_money_format'] . '"');
             $repay_plan_value['impose_money_format'] = iconv('utf-8', 'gbk', '"' . $v['impose_money_format'] . '"');
             $repay_plan_value['yuqi_money'] = iconv('utf-8', 'gbk', '"' . $v['yuqi_money'] . '"');
             $repay_plan_value['real_money'] = iconv('utf-8', 'gbk', '"' . $v['real_money'] . '"');
             $repay_plan_value['status_format'] = iconv('utf-8', 'gbk', '"' . $v['status_format'] . '"');
             $repay_plan_value['site_repay_format'] = iconv('utf-8', 'gbk', '"' . $v['site_repay_format'] . '"');
             $content .= implode(",", $repay_plan_value) . "\n";
         }
     } else {
         if ($page == 1) {
             $this->error(L("NO_RESULT"));
         }
     }
     header("Content-Disposition: attachment; filename=" . $deal_info['name'] . "-第" . ($l_key + 1) . "期还款计划.csv");
     echo $contents;
     echo $content;
 }
Exemple #8
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;
    //还了几期了
    $has_repay_count = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id);
    //计算罚息
    $loan_list = get_deal_load_list($deal);
    $k_repay_time = 0;
    foreach ($loan_list as $k => $v) {
        if ($k > $has_repay_count - 1) {
            if ($k_repay_time == 0) {
                $k_repay_time = $v['repay_day'];
            }
            $impose_money += $v['impose_money'];
        }
    }
    if ($impose_money > 0) {
        $root["show_err"] = "请将逾期未还的借款还完才可以进行此操作!";
        return $root;
    }
    //月利率
    $rate = $deal['rate'] / 12 / 100;
    $impose_money = 0;
    //计算剩多少本金
    $benjin = $deal['borrow_amount'];
    if ($deal['loantype'] == 0) {
        //等额本息的时候才通过公式计算剩余多少本金
        for ($i = 1; $i <= $has_repay_count; $i++) {
            $benjin = $benjin - ($deal['month_repay_money'] - $benjin * $rate);
        }
        $impose_money = ($benjin - $deal['month_repay_money'] + $benjin * $rate) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $benjin * $rate;
    } elseif ($deal['loantype'] == 1) {
        //每月付息,到期还本
        $impose_money = $benjin * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $deal['month_repay_money'];
    } elseif ($deal['loantype'] == 2) {
        //到期还本息
        $impose_money += $benjin * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
        $total_repay_money = $benjin + $benjin * $rate;
        //计算应缴多罚息 多少管理费
        $now_ym = to_date($time, "Y-m");
        $i = 0;
        foreach ($loan_list as $k => $v) {
            ++$i;
            if ($now_ym == to_date($v['repay_day'], "Y-m")) {
                $deal['month_manage_money'] = $benjin * trim(app_conf('MANAGE_FEE')) / 100 * $i;
            }
        }
    }
    $GLOBALS['tmpl']->assign("impose_money", $impose_money);
    $GLOBALS['tmpl']->assign("total_repay_money", $total_repay_money);
    $true_total_repay_money = $total_repay_money + $impose_money + $deal['month_manage_money'];
    if ($total_repay_money + $impose_money + $deal['month_manage_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'] = round($total_repay_money);
    $inrepay_data['impose_money'] = round($impose_money, 2);
    $inrepay_data['manage_money'] = round($deal['month_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;
    }
    //录入还款列表
    $after_time = $GLOBALS['db']->getOne("SELECT repay_time FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $id . " ORDER BY repay_time DESC");
    if ($after_time == "") {
        $after_time = $deal['repay_start_time'];
    }
    $temp_ids[] = array();
    for ($i = 0; $i < $deal['repay_time'] - $has_repay_count; $i++) {
        $repay_data['id'] = $v['repay_id'];
        $repay_data['has_repay'] = 1;
        $repay_data['deal_id'] = $id;
        $repay_data['user_id'] = $GLOBALS['user_info']['id'];
        $repay_data['repay_time'] = $after_time = next_replay_month($after_time);
        $repay_data['true_repay_time'] = $time;
        $repay_data['status'] = 0;
        if ($i == 0) {
            $repay_data['repay_money'] = round($deal['month_repay_money'], 2);
            $repay_data['impose_money'] = round($impose_money, 2);
            $repay_data['manage_money'] = round($deal['month_manage_money']);
        } else {
            if ($deal['loantype'] == 0) {
                //等额本息
                $repay_data['repay_money'] = $benjin / ($deal['repay_time'] - $has_repay_count);
            } elseif ($deal['loantype'] == 1) {
                //每月还息
                if ($i + 1 == $deal['repay_time'] - $has_repay_count) {
                    $repay_data['repay_money'] = $benjin;
                } else {
                    $repay_data['repay_money'] = 0;
                }
            } elseif ($deal['loantype'] == 2) {
                //每月还息
                if ($i + 1 == $deal['repay_time'] - $has_repay_count) {
                    $repay_data['repay_money'] = $benjin;
                } else {
                    $repay_data['repay_money'] = 0;
                }
            }
            $repay_data['impose_money'] = 0;
            $repay_data['manage_money'] = 0;
        }
        $deal_repay_id = $v['repay_id'];
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", "id=" . $deal_repay_id);
        //假如出错 删除掉原来的以插入的数据
        if ($GLOBALS['db']->affected_rows() == 0) {
            if ($temp_ids) {
                $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay set has_repay = 0 WHERE id in (" . implode(",", $temp_ids) . ")");
            }
            $root["show_err"] = "对不起,处理数据失败请联系客服!";
            return $root;
        } else {
            $temp_ids[] = $deal_repay_id;
        }
    }
    //更新用户账户资金记录
    require APP_ROOT_PATH . 'system/libs/user.php';
    modify_account(array("money" => -round($impose_money)), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",提前还款违约金");
    modify_account(array("money" => -round($total_repay_money + $deal['month_manage_money'], 2)), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",提前还款");
    //用户获得额度
    modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",还清借款获得额度");
    $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) . "元,本笔借款已还款完毕!";
    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") . "】";
        $msg_data['dest'] = $GLOBALS['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'] = $GLOBALS['user_info']['id'];
        $msg_data['is_html'] = 0;
        $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
        //插入
    }
    //判断获取的信用是否超过限制
    if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_log WHERE (log_info='标:" . $deal['id'] . ",还清借款' or log_info='还清借款') AND user_id=" . $GLOBALS['user_info']['id']) < (int) trim(app_conf('REPAY_SUCCESS_LIMIT'))) {
        //获取上一次还款时间
        $befor_repay_time = $GLOBALS['db']->getOne("SELECT MAX(log_time) FROM " . DB_PREFIX . "user_log WHERE (log_info='标:" . $deal['id'] . ",还清借款' or log_info='还清借款') 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'], "标:" . $deal['id'] . ",还清借款");
        }
        //用户获得额度
        modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $GLOBALS['user_info']['id'], "标:" . $deal['id'] . ",还清借款获得额度");
    }
    syn_deal_status($id);
    sys_user_status($GLOBALS['user_info']['id'], false, true);
    //用户回款
    $user_loan_list = get_deal_user_load_list($deal);
    foreach ($user_loan_list as $lllk => $lllv) {
        foreach ($lllv as $kk => $vv) {
            //本金
            $user_self_money = 0;
            //本息
            $user_repay_money = 0;
            //违约金
            $user_impose_money = 0;
            //管理费
            $user_manage_money = 0;
            $in_user_id = $vv['user_id'];
            //判断是否转让了债权
            if ($vv['t_user_id'] > 0) {
                $in_user_id = $vv['t_user_id'];
                $loan_user_info['user_name'] = $vv['user_name'];
                $loan_user_info['t_email'] = $vv['email'];
                $loan_user_info['t_mobile'] = $vv['mobile'];
            } else {
                $loan_user_info['user_name'] = $vv['t_user_name'];
                $loan_user_info['t_email'] = $vv['t_email'];
                $loan_user_info['t_mobile'] = $vv['t_mobile'];
            }
            //借入者已还款,但是没打款到借出用户中心
            if ($vv['has_repay'] == 0) {
                $user_load_data['deal_id'] = $v['deal_id'];
                $user_load_data['user_id'] = $v['user_id'];
                $user_load_data['repay_time'] = $vv['repay_day'];
                $user_load_data['true_repay_time'] = $time;
                $user_load_data['is_site_repay'] = 0;
                $user_load_data['status'] = 0;
                //小于提前还款按正常还款
                if ($vv['repay_day'] < $k_repay_time) {
                    //等额本息的时候才通过公式计算剩余多少本金
                    $user_load_data['self_money'] = $vv['self_money'];
                    $user_load_data['repay_money'] = $vv['month_repay_money'];
                    $user_load_data['manage_money'] = $vv['month_manage_money'];
                    $user_load_data['impose_money'] = $vv['impose_money'];
                    if ($vv['status'] > 0) {
                        $user_load_data['status'] = $vv['status'] - 1;
                    }
                    $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal['url'] . "\">" . $deal['name'] . "</a>”成功还款" . number_format($vv['month_repay_money'] + $vv['impose_money'], 2) . "元,";
                    $unext_loan = $user_loan_list[$kk + 1];
                    if ($unext_loan) {
                        $content .= "本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需要本息" . number_format($unext_loan['month_repay_money'], 2) . "元。";
                    }
                    $user_self_money += (double) $user_load_data['self_money'];
                    if ($user_load_data['impose_money'] != 0 || $user_load_data['manage_money'] != 0 || $user_load_data['repay_money'] != 0) {
                        //更新用户账户资金记录
                        modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",逾期罚息");
                        modify_account(array("money" => -$user_load_data['manage_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",投标管理费");
                        modify_account(array("money" => $user_load_data['repay_money']), $in_user_id, "标:" . $deal['id'] . ",期:" . ($kk + 1) . ",回报本息");
                        $msg_conf = get_user_msg_conf($in_user_id);
                        //站内信
                        if ($msg_conf['sms_bidrepaid'] == 1) {
                            send_user_msg("", $content, 0, $in_user_id, $time, 0, true, 9);
                        }
                        //邮件
                        if ($msg_conf['mail_bidrepaid'] == 1) {
                        }
                    }
                } else {
                    if ($vv['repay_day'] == $k_repay_time) {
                        if ($deal['loantype'] == 0) {
                            //等额本息的时候才通过公式计算剩余多少本金
                            $user_load_data['self_money'] = $vv['month_repay_money'] - get_benjin($kk, $deal['repay_time'], $v['money'], $vv['month_repay_money'], $deal['rate']) * $deal['rate'] / 12 / 100;
                            $user_load_data['impose_money'] = ($user_load_data['self_money'] - $vv['month_repay_money'] + $user_load_data['self_money'] * $v['rate']) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
                        } elseif ($deal['loantype'] == 1) {
                            //每月还息,到期还本
                            $user_load_data['self_money'] = $vv['money'];
                            $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                        } elseif ($deal['loantype'] == 2) {
                            //每月还息,到期还本
                            $user_load_data['self_money'] = $vv['money'];
                            $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                        }
                        $user_self_money += (double) $user_load_data['self_money'];
                        if ($deal['loantype'] == 0) {
                            //等额本息的时候才通过公式计算剩余多少本金
                            $user_load_data['repay_money'] = $vv['month_repay_money'];
                            $user_load_data['manage_money'] = $vv['month_manage_money'];
                        } elseif ($deal['loantype'] == 1) {
                            $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                            $user_load_data['manage_money'] = $vv['month_manage_money'];
                        } elseif ($deal['loantype'] == 2) {
                            $user_load_data['repay_money'] = $vv['money'];
                            $user_load_data['manage_money'] = $vv['money'] * floatval(trim($deal['user_loan_manage_fee'])) / 100 * ($kk + 1);
                        }
                        $user_repay_k = $kk + 1;
                    } else {
                        //其他月份
                        //等额本息
                        if ($deal['loantype'] == 0) {
                            if ($user_self_money == 0) {
                                $user_load_data['self_money'] = $vv['month_repay_money'] - get_benjin($kk, $deal['repay_time'], $v['money'], $vv['month_repay_money'], $deal['rate']) * $deal['rate'] / 12 / 100;
                                $user_load_data['impose_money'] = ($user_load_data['self_money'] - $vv['month_repay_money'] + $user_load_data['self_money'] * $v['rate']) * (double) trim(app_conf('COMPENSATE_FEE')) / 100;
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = ($v['money'] - $user_self_money) / ($v['repay_time'] - $user_repay_k);
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        } elseif ($deal['loantype'] == 1) {
                            if ($user_self_money == 0) {
                                $user_self_money = $user_load_data['self_money'] = $v['money'];
                                $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                                $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                                $user_load_data['manage_money'] = $vv['month_manage_money'];
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = 0;
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        } elseif ($deal['loantype'] == 2) {
                            if ($user_self_money == 0) {
                                $user_self_money = $user_load_data['self_money'] = $v['money'];
                                $user_load_data['repay_money'] = $vv['month_repay_money'] + $v['money'];
                                $user_load_data['impose_money'] = $vv['money'] * floatval(trim($deal['compensate_fee'])) / 100;
                                $user_load_data['manage_money'] = $vv['money'] * floatval(trim($deal['user_loan_manage_fee'])) / 100 * ($kk + 1);
                            } else {
                                $user_load_data['self_money'] = $user_load_data['repay_money'] = 0;
                                $user_load_data['manage_money'] = 0;
                                $user_load_data['impose_money'] = 0;
                            }
                        }
                    }
                    $user_repay_money += (double) $user_load_data['repay_money'];
                    $user_impose_money += (double) $user_load_data['impose_money'];
                    $user_manage_money += (double) $user_load_data['manage_money'];
                    $user_load_data['l_key'] = $kk;
                    $user_load_data['u_key'] = $k;
                }
                $user_load_data['has_repay'] = 1;
                $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "INSERT");
            }
            if ($user_repay_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 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 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_impose_money), $in_user_id, "标:" . $deal['id'] . ",违约金");
                modify_account(array("money" => -$user_manage_money), $in_user_id, "标:" . $deal['id'] . ",投标管理费");
                modify_account(array("money" => $user_repay_money), $in_user_id, "标:" . $deal['id'] . ",回报本息");
                $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']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_SMS'");
                    $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);
                    //插入
                }
                //站内信
                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']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'");
                    $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);
                    //插入
                }
            }
        }
    }
    $root["status"] = 1;
    //0:出错;1:正确;
    $root["show_err"] = "操作成功!";
    return $root;
}
Exemple #9
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;
}
 public function mrefdetail()
 {
     $user_id = $GLOBALS['user_info']['id'];
     $id = intval($_REQUEST['id']);
     $load_id = intval($_REQUEST['load_id']);
     require APP_ROOT_PATH . "app/Lib/deal.php";
     $deal = get_deal($id);
     if (!$deal || $deal['deal_status'] < 4) {
         showErr("无法查看,可能有以下原因!<br>1。借款不存在<br>2。借款被删除<br>3。借款未成功");
     }
     $GLOBALS['tmpl']->assign('deal', $deal);
     $deal_load_list = get_deal_load_list($deal);
     //获取本期的投标记录
     $temp_user_load = $GLOBALS['db']->getRow("SELECT id,deal_id,user_id,money FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $id . " and id=" . $load_id . " and user_id=" . $user_id);
     $user_load_ids = array();
     if ($temp_user_load) {
         $u_key = $GLOBALS['db']->getOne("SELECT u_key FROM " . DB_PREFIX . "deal_load_repay WHERE load_id=" . $load_id . " and user_id=" . $user_id);
         if ($temp_user_load['user_id'] == $user_id) {
             $temp_user_load['repay_start_time'] = $deal['repay_start_time'];
             $temp_user_load['repay_time'] = $deal['repay_time'];
             $temp_user_load['rate'] = $deal['rate'];
             $temp_user_load['u_key'] = $u_key;
             $temp_user_load['load'] = get_deal_user_load_list($deal, $user_id, -1, $u_key);
             $temp_user_load['impose_money'] = 0;
             $temp_user_load['manage_fee'] = 0;
             $temp_user_load['repay_money'] = 0;
             $temp_user_load['manage_interest_money'] = 0;
             foreach ($temp_user_load['load'] as $kk => $vv) {
                 $temp_user_load['impose_money'] += $vv['impose_money'];
                 $temp_user_load['manage_fee'] += $vv['manage_money'];
                 $temp_user_load['repay_money'] += $vv['month_has_repay_money'];
                 $temp_user_load['manage_interest_money'] += $vv['manage_interest_money'];
                 //预期收益
                 $temp_user_load['load'][$kk]['yuqi_money'] = format_price($vv['month_repay_money'] - $vv['self_money'] - $vv['manage_money'] - $vv['manage_interest_money']);
                 //实际收益
                 if ($vv['has_repay'] == 1) {
                     $temp_user_load['load'][$kk]['real_money'] = format_price($vv['month_repay_money'] - $vv['self_money'] + $vv['impose_money'] - $vv['manage_money'] - $vv['manage_interest_money']);
                 }
             }
             $user_load_ids[] = $temp_user_load;
         }
     }
     $GLOBALS['tmpl']->assign('user_load_ids', $user_load_ids);
     $inrepay_info = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_inrepay_repay WHERE deal_id={$id}");
     $GLOBALS['tmpl']->assign("inrepay_info", $inrepay_info);
     $GLOBALS['tmpl']->assign("load_id", $load_id);
     $GLOBALS['tmpl']->assign("page_title", "我的回款");
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_invest_refdetail.html");
     $GLOBALS['tmpl']->display("uc_invest_mrefdetail.html");
 }
Exemple #11
0
 /**
  * 代还款
  */
 function do_site_repay($page = 1)
 {
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $id = intval($_REQUEST['id']);
     $l_key = intval($_REQUEST['l_key']);
     $this->assign("jumpUrl", U("Deal/repay_plan", array("id" => $id)));
     if ($id == 0) {
         $this->success("数据错误");
     }
     $deal_info = get_deal($id);
     if (!$deal_info) {
         $this->success("借款不存在");
     }
     if ($deal_info['ips_bill_no'] != "") {
         $this->success("第三方同步暂无法代还款");
     }
     if ($page == 0) {
         $page = 1;
     }
     $page_size = 10;
     $limit = ($page - 1) * $page_size . "," . $page_size;
     $user_loan_list = get_deal_user_load_list($deal_info, 0, $l_key, -1, 0, 0, 1, $limit);
     $rs_count = $user_loan_list['count'];
     $page_all = ceil($rs_count / $page_size);
     require_once APP_ROOT_PATH . "system/libs/user.php";
     foreach ($user_loan_list['item'] as $kk => $vv) {
         if ($vv['has_repay'] == 0) {
             //借入者已还款,但是没打款到借出用户中心
             $user_load_data = array();
             $user_load_data['true_repay_time'] = TIME_UTC;
             $user_load_data['is_site_repay'] = 1;
             $user_load_data['status'] = 0;
             $user_load_data['repay_money'] = $vv['month_repay_money'];
             $user_load_data['manage_money'] = $vv['month_manage_money'];
             $user_load_data['impose_money'] = $vv['impose_money'];
             $user_load_data['repay_manage_impose_money'] = $vv['repay_manage_impose_money'];
             if ($vv['status'] > 0) {
                 $user_load_data['status'] = $vv['status'] - 1;
             }
             $user_load_data['has_repay'] = 1;
             $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_load_repay", $user_load_data, "UPDATE", "id=" . $vv['id'] . " AND has_repay = 0 ", "SILENT");
             if ($GLOBALS['db']->affected_rows() > 0) {
                 $content = "您好,您在" . app_conf("SHOP_TITLE") . "的投标 “<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”成功还款" . ($vv['month_repay_money'] + $vv['impose_money']) . "元,";
                 $unext_loan = $user_loan_list[$vv['u_key']][$kk + 1];
                 if ($unext_loan) {
                     $content .= "本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需还本息" . number_format($unext_loan['month_repay_money'], 2) . "元。";
                 } else {
                     $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 deal_id=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']), 2);
                     $all_impose_money = number_format($GLOBALS['db']->getOne("SELECT sum(impose_money) FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']), 2);
                     $content .= "本次投标共获得收益:" . $all_repay_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!";
                 }
                 if ($user_load_data['impose_money'] != 0 || $user_load_data['manage_money'] != 0 || $user_load_data['repay_money'] != 0) {
                     $in_user_id = $vv['user_id'];
                     //如果是转让债权那么将回款打入转让者的账户
                     if ($vv['t_user_id'] > 0) {
                         $in_user_id = $vv['t_user_id'];
                         $loan_user_info['user_name'] = $vv['user_name'];
                         $loan_user_info['t_email'] = $vv['email'];
                         $loan_user_info['t_mobile'] = $vv['mobile'];
                     } else {
                         $loan_user_info['user_name'] = $vv['t_user_name'];
                         $loan_user_info['t_email'] = $vv['t_email'];
                         $loan_user_info['t_mobile'] = $vv['t_mobile'];
                     }
                     //更新用户账户资金记录
                     if ($user_load_data['repay_money'] != 0) {
                         modify_account(array("money" => $user_load_data['repay_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",回报本息");
                     }
                     if ($user_load_data['impose_money'] != 0) {
                         modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",逾期罚息");
                     }
                     if ($user_load_data['manage_money'] != 0) {
                         modify_account(array("money" => -$user_load_data['manage_money']), $in_user_id, "标:" . $deal_info['id'] . ",期:" . ($kk + 1) . ",投标管理费");
                     }
                     $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']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_SMS'");
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $loan_user_info['user_name'];
                         $notice['deal_name'] = $deal_info['sub_name'];
                         $notice['deal_url'] = $deal_info['url'];
                         $notice['site_name'] = app_conf("SHOP_TITLE");
                         $notice['repay_money'] = number_format($vv['month_repay_money'] + $vv['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $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_UTC;
                         $msg_data['user_id'] = $in_user_id;
                         $msg_data['is_html'] = 0;
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                     //站内信
                     if ($msg_conf['sms_bidrepaid'] == 1) {
                         send_user_msg("", $content, 0, $in_user_id, TIME_UTC, 0, true, 9);
                     }
                     //邮件
                     if ($msg_conf['mail_bidrepaid'] == 1 && app_conf('MAIL_ON') == 1) {
                         $tmpl = $GLOBALS['db']->getRowCached("select * from " . DB_PREFIX . "msg_template where name = 'TPL_DEAL_LOAD_REPAY_EMAIL'");
                         $tmpl_content = $tmpl['content'];
                         $notice['user_name'] = $loan_user_info['user_name'];
                         $notice['deal_name'] = $deal_info['sub_name'];
                         $notice['deal_url'] = $deal_info['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'] = number_format($vv['month_repay_money'] + $vv['impose_money'], 2);
                         if ($unext_loan) {
                             $notice['need_next_repay'] = $unext_loan;
                             $notice['next_repay_time'] = to_date($unext_loan['repay_day'], "Y年m月d日");
                             $notice['next_repay_money'] = number_format($unext_loan['month_repay_money'], 2);
                         } else {
                             $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_info['name'] . "”回款通知";
                         $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'] = $in_user_id;
                         $msg_data['is_html'] = $tmpl['is_html'];
                         $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data);
                         //插入
                     }
                 }
             }
         }
     }
     if ($page >= $page_all) {
         $s_count = $GLOBALS['db']->getOne("SELECT count(*) FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0");
         if ($s_count == 0) {
             $rs_sum = $GLOBALS['db']->getRow("SELECT sum(repay_money) as total_repay_money,sum(manage_money) as total_manage_money,sum(impose_money) as total_impose_money,sum(repay_manage_impose_money) as total_repay_manage_impose_money FROM  " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 1");
             $deal_load_list = get_deal_load_list($deal_info);
             $GLOBALS['db']->query("UPDATE " . DB_PREFIX . "deal_repay set status = " . ($deal_load_list[$l_key]['status'] - 1) . ",true_repay_time = " . TIME_UTC . ", has_repay = 1, impose_money='" . floatval($rs_sum['total_impose_money']) . "',mange_impose_money='" . floatval($rs_sum['total_repay_manage_impose_money']) . "' where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0");
             if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "generation_repay WHERE deal_id=" . $id . " AND repay_id=" . $deal_load_list[$l_key]['repay_id'] . "") == 0) {
                 $generation_repay['deal_id'] = $id;
                 $generation_repay['repay_id'] = $deal_load_list[$l_key]['repay_id'];
                 $adm_session = es_session::get(md5(conf("AUTH_KEY")));
                 $generation_repay['admin_id'] = $adm_session['adm_id'];
                 $generation_repay['agency_id'] = $deal_info['agency_id'];
                 $generation_repay['repay_money'] = $rs_sum['total_repay_money'];
                 $generation_repay['impose_money'] = $rs_sum['total_impose_money'];
                 $generation_repay['manage_money'] = $rs_sum['total_manage_money'];
                 $generation_repay['manage_impose_money'] = $rs_sum['total_repay_manage_impose_money'];
                 $generation_repay['create_time'] = TIME_UTC;
                 $GLOBALS['db']->autoExecute(DB_PREFIX . "generation_repay", $generation_repay);
             }
         }
         $this->success("代还款执行完毕!");
     } else {
         register_shutdown_function(array(&$this, 'do_site_repay'), $page + 1);
     }
 }
 public function mrefdetail()
 {
     $user_id = $GLOBALS['user_info']['id'];
     $id = intval($_REQUEST['id']);
     require APP_ROOT_PATH . "app/Lib/deal.php";
     $deal = get_deal($id);
     if (!$deal || $deal['deal_status'] < 4) {
         showErr("无法查看,可能有以下原因!<br>1。借款不存在<br>2。借款被删除<br>3。借款未成功");
     }
     $GLOBALS['tmpl']->assign('deal', $deal);
     $deal_load_list = get_deal_load_list($deal);
     //获取本期的投标记录
     $temp_user_load_ids = $GLOBALS['db']->getAll("SELECT deal_id,user_id,money FROM " . DB_PREFIX . "deal_load WHERE deal_id=" . $id);
     $user_load_ids = array();
     $i = 0;
     foreach ($temp_user_load_ids as $k => $v) {
         if ($v['user_id'] == $user_id) {
             $v['repay_start_time'] = $deal['repay_start_time'];
             $v['repay_time'] = $deal['repay_time'];
             $v['rate'] = $deal['rate'];
             $v['u_key'] = $k;
             $v['load'] = get_deal_user_load_list($deal, $user_id, -1, $k);
             $v['impose_money'] = 0;
             $v['manage_fee'] = 0;
             $v['repay_money'] = 0;
             foreach ($v['load'] as $kk => $vv) {
                 $v['impose_money'] += $vv['impose_money'];
                 $v['manage_fee'] += $vv['manage_money'];
                 $v['repay_money'] += $vv['month_has_repay_money'];
             }
             $user_load_ids[$i] = $v;
             $i++;
         }
     }
     $GLOBALS['tmpl']->assign('user_load_ids', $user_load_ids);
     $inrepay_info = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_inrepay_repay WHERE deal_id={$id}");
     $GLOBALS['tmpl']->assign("inrepay_info", $inrepay_info);
     $GLOBALS['tmpl']->assign("page_title", "我的回款");
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_invest_refdetail.html");
     $GLOBALS['tmpl']->display("uc_invest_mrefdetail.html");
 }