public function index()
 {
     $root = array();
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     $id = intval($GLOBALS['request']['id']);
     //检查用户,用户密码
     $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($id);
         if (!$deal || $deal['user_id'] != $user_id || $deal['deal_status'] != 4) {
             $root['show_err'] = "操作失败!";
             $root['response_code'] = 0;
         } else {
             //还款列表
             $loan_list = get_deal_load_list($deal);
             $root['loan_list'] = $loan_list;
             $root['deal'] = $deal;
             $root['response_code'] = 1;
             $root['show_err'] = '';
         }
     } else {
         $root['response_code'] = 0;
         $root['show_err'] = "未登录";
         $root['user_login_status'] = 0;
     }
     output($root);
 }
 public function index()
 {
     $root = array();
     $email = strim($GLOBALS['request']['email']);
     //用户名或邮箱
     $pwd = strim($GLOBALS['request']['pwd']);
     //密码
     $id = intval($GLOBALS['request']['id']);
     //检查用户,用户密码
     $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($id);
         if (!$deal || $deal['user_id'] != $user_id || $deal['deal_status'] != 4) {
             $root['show_err'] = "操作失败!";
             $root['response_code'] = 0;
         } else {
             //还款列表
             $loan_list = get_deal_load_list($deal);
             $flag = 1;
             foreach ($loan_list as $k => $v) {
                 if ($loan_list[$k]['has_repay'] == 0 && $flag == 1) {
                     $loan_list[$k]["flag"] = $flag;
                     $flag = 0;
                 }
             }
             $root['loan_list'] = $loan_list;
             $root['deal'] = $deal;
             $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);
 }
 public function index()
 {
     if (trim($_REQUEST['search']) == "do") {
         $start_time = trim($_REQUEST['start_time']);
         if ($start_time == "") {
             $this->error("请选择开始时间");
             die;
         }
         $this->assign("start_time", $start_time);
         $end_time = trim($_REQUEST['end_time']);
         if ($end_time == "") {
             $this->error("请选择结束时间");
             die;
         }
         $this->assign("end_time", $end_time);
         $start_time = to_timespan($start_time, "Y-m-d");
         $end_time = to_timespan($end_time, "Y-m-d");
         if ($end_time < $start_time) {
             $this->error("结束时间必须大于开始时间");
             die;
         }
         $now_time = to_timespan(to_date(TIME_UTC, "Y-m-d"), "Y-m-d");
         if ($end_time > $now_time) {
             $end_time = $now_time;
         }
         //开始时间跟结束时间差多少天
         $day = ($end_time - $start_time) / 24 / 3600;
         $list = array();
         $day_time = $start_time;
         //标分类
         $deal_cate = load_auto_cache("cache_deal_cate");
         /*foreach($deal_cate as $kk=>$vv){
          		if(strpos($vv['name'],"智能")!==false){
          			unset($deal_cate[$kk]);
          		}
          	}*/
         $this->assign("deal_cate", $deal_cate);
         //获取改时间段内所有的 还款中和 已还清的贷款
         //$deals = $GLOBALS['db']->getAll("SELECT id FROM ".DB_PREFIX."deal where deal_status in(4,5) and is_effect=1 and is_delete=0 and publish_wait=0 AND success_time >= $start_time and  ((loantype=1 and (success_time + repay_time*31*24*3600) >=$end_time) or (loantype=0 and (success_time + (repay_time+1)*24*3600)>=$end_time))");
         $deals = $GLOBALS['db']->getAll("SELECT id FROM " . DB_PREFIX . "deal where deal_status in(4,5) and is_effect=1 and is_delete=0 and publish_wait=0 AND success_time >= {$start_time}");
         $temp_deals = array();
         require_once APP_ROOT_PATH . "app/Lib/common.php";
         require_once APP_ROOT_PATH . "app/Lib/deal.php";
         require_once APP_ROOT_PATH . "system/libs/user.php";
         for ($i = 0; $i <= $day; $i++) {
             $list[$i]['day'] = $day_time;
             //线上充值金额
             $list[$i]['online_pay'] = floatval($GLOBALS['db']->getOne("SELECT sum(deal_total_price) FROM " . DB_PREFIX . "deal_order where pay_status=2 and type = 1 and is_delete = 0 and create_time between {$day_time} and {$day_time}+24*3600 and payment_id not in (SELECT id from " . DB_PREFIX . "payment where class_name='Otherpay') "));
             //线下充值金额
             $list[$i]['below_pay'] = floatval($GLOBALS['db']->getOne("SELECT sum(deal_total_price) FROM " . DB_PREFIX . "deal_order where pay_status=2 and type = 1 and is_delete = 0 and create_time between {$day_time} and {$day_time}+24*3600 and payment_id in (SELECT id from " . DB_PREFIX . "payment where class_name='Otherpay') "));
             foreach ($deal_cate as $kk => $vv) {
                 //if(strpos($vv['name'],"智能")===false)
                 $list[$i][$vv['id']]['borrow_amount'] = floatval($GLOBALS['db']->getOne("SELECT sum(borrow_amount) FROM " . DB_PREFIX . "deal where deal_status=4 and is_delete = 0 and publish_wait = 0 and success_time between {$day_time} and {$day_time}+24*3600 and cate_id=" . $vv['id']));
             }
             //投资总额[投标者]
             $list[$i]['load_amount'] = floatval($GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "deal_load where is_repay=0 and create_time between {$day_time} and {$day_time}+24*3600"));
             //已获利息总额[投标者]
             $list[$i]['load_lixi_amount'] = floatval($GLOBALS['db']->getOne("SELECT (sum(repay_money) - sum(self_money)) FROM " . DB_PREFIX . "deal_load_repay where true_repay_time between {$day_time} and {$day_time}+24*3600"));
             //应付本金
             $list[$i]['benjin_amount'] = 0;
             //应付利息
             $list[$i]['pay_lxi_amount'] = 0;
             //应付罚息
             $list[$i]['impose_amount'] = 0;
             //已付本金
             $list[$i]['has_repay_benjin_amount'] = 0;
             //已付利息
             $list[$i]['has_repay_lxi_amount'] = 0;
             //已付罚息
             $list[$i]['has_repay_impose_amount'] = 0;
             foreach ($deals as $kk => $vv) {
                 if (!isset($temp_deals[$vv['id']])) {
                     $temp_deals[$vv['id']]['deal'] = get_deal($vv['id']);
                     $temp_deals[$vv['id']]['loan'] = get_deal_load_list($temp_deals[$vv['id']]['deal']);
                 }
                 foreach ($temp_deals[$vv['id']]['loan'] as $kkk => $vvv) {
                     //如果刚好等于传入的时间就开始计算
                     if ($vvv['true_repay_time'] >= $day_time && $vvv['true_repay_time'] <= $day_time + 24 * 3600 - 1 || $vvv['repay_day'] == $day_time) {
                         if ($temp_deals[$vv['id']]['deal']['month_repay_money'] > 0 || $temp_deals[$vv['id']]['deal']['last_month_repay_money'] > 0) {
                             if ($temp_deals[$vv['id']]['deal']['loantype'] == 0) {
                                 $benj = get_benjin($kkk, count($temp_deals[$vv['id']]['loan']), $temp_deals[$vv['id']]['deal']['borrow_amount'], $temp_deals[$vv['id']]['deal']['month_repay_money'], $temp_deals[$vv['id']]['deal']['rate']);
                                 $list[$i]['benjin_amount'] += $benj;
                                 $list[$i]['pay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['month_repay_money'] - $benj;
                             } elseif ($temp_deals[$vv['id']]['deal']['loantype'] == 1) {
                                 if ($kkk + 1 == count($temp_deals[$vv['id']]['loan'])) {
                                     $list[$i]['benjin_amount'] += $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                     $list[$i]['pay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['last_month_repay_money'] - $list[$i]['benjin_amount'];
                                 } else {
                                     $list[$i]['pay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['month_repay_money'];
                                 }
                             } elseif ($temp_deals[$vv['id']]['deal']['loantype'] == 2) {
                                 if ($kkk + 1 == count($temp_deals[$vv['id']]['loan'])) {
                                     $list[$i]['benjin_amount'] += $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                     $list[$i]['pay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['last_month_repay_money'] - $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                 }
                             }
                             $list[$i]['impose_amount'] += $vvv['impose_money'];
                             if ($vvv['has_repay'] == 1) {
                                 if ($temp_deals[$vv['id']]['deal']['loantype'] == 0) {
                                     $benj = get_benjin($kkk, count($temp_deals[$vv['id']]['loan']), $temp_deals[$vv['id']]['deal']['borrow_amount'], $temp_deals[$vv['id']]['deal']['month_repay_money'], $temp_deals[$vv['id']]['deal']['rate']);
                                     $list[$i]['has_repay_benjin_amount'] += $benj;
                                     $list[$i]['has_repay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['month_repay_money'] - $benj;
                                 } elseif ($temp_deals[$vv['id']]['deal']['loantype'] == 1) {
                                     if ($kkk + 1 == count($temp_deals[$vv['id']]['loan'])) {
                                         $list[$i]['has_repay_benjin_amount'] += $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                         $list[$i]['has_repay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['last_month_repay_money'] - $list[$i]['benjin_amount'];
                                     } else {
                                         $list[$i]['has_repay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['month_repay_money'];
                                     }
                                 } elseif ($temp_deals[$vv['id']]['deal']['loantype'] == 2) {
                                     if ($kkk + 1 == count($temp_deals[$vv['id']]['loan'])) {
                                         $list[$i]['has_repay_benjin_amount'] += $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                         $list[$i]['has_repay_lxi_amount'] += $temp_deals[$vv['id']]['deal']['last_month_repay_money'] - $temp_deals[$vv['id']]['deal']['borrow_amount'];
                                     }
                                 }
                                 $list[$i]['has_repay_impose_amount'] += $vvv['impose_money'];
                             }
                         }
                     }
                 }
             }
             //待还本金
             $list[$i]['wait_repay_benjin_amount'] = $list[$i]['benjin_amount'] - $list[$i]['has_repay_benjin_amount'];
             //待还利息
             $list[$i]['wait_repay_lxi_amount'] = $list[$i]['pay_lxi_amount'] - $list[$i]['has_repay_lxi_amount'];
             //待还罚息
             $list[$i]['wait_repay_impose_amount'] = $list[$i]['impose_amount'] - $list[$i]['has_repay_impose_amount'];
             //申请提现总额
             $list[$i]['carry'] = floatval($GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "user_carry where create_time between {$day_time} and {$day_time}+24*3600 "));
             //成功提现金额
             $list[$i]['suc_carry'] = floatval($GLOBALS['db']->getOne("SELECT sum(money) FROM " . DB_PREFIX . "user_carry where status=1 and update_time between {$day_time} and {$day_time}+24*3600 "));
             $day_time += 24 * 3600;
         }
         //待投资资金
         $user_amount = M("User")->where("is_delete=0 AND is_effect=1")->sum("money");
         $this->assign("user_amount", $user_amount);
         $this->assign("list", $list);
     }
     $this->display();
 }
 public function mobile()
 {
     /*if(!$GLOBALS['user_info']){
     			set_gopreview();
     			app_redirect(url("index","user#login"));
     		}*/
     $id = intval($_REQUEST['id']);
     $deal = get_deal($id);
     send_deal_contract_email($id, $deal, $deal['user_id']);
     if (!$deal) {
         app_redirect(url("index"));
     }
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $id);
     $u_info = get_user("*", $deal['user_id']);
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     if ($GLOBALS['user_info']) {
         $deal['is_faved'] = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_collect WHERE deal_id = " . $id . " AND user_id=" . intval($GLOBALS['user_info']['id']));
         if ($deal['deal_status'] >= 4) {
             //还款列表
             $loan_repay_list = get_deal_load_list($deal);
             $GLOBALS['tmpl']->assign("loan_repay_list", $loan_repay_list);
             foreach ($load_list as $k => $v) {
                 $load_list[$k]['remain_money'] = $v['money'] - $GLOBALS['db']->getOne("SELECT sum(self_money) FROM " . DB_PREFIX . "deal_load_repay WHERE user_id=" . $v['user_id'] . " AND deal_id=" . $id);
                 if ($load_list[$k]['remain_money'] <= 0) {
                     $load_list[$k]['remain_money'] = 0;
                     $load_list[$k]['status'] = 1;
                 }
             }
         }
         $user_statics = sys_user_status($deal['user_id'], true);
         $GLOBALS['tmpl']->assign("user_statics", $user_statics);
     }
     $GLOBALS['tmpl']->assign("load_list", $load_list);
     $GLOBALS['tmpl']->assign("credit_file", $credit_file);
     $GLOBALS['tmpl']->assign("u_info", $u_info);
     //工作认证是否过期
     $GLOBALS['tmpl']->assign('expire', user_info_expire($u_info));
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $GLOBALS['tmpl']->assign("page_title", $seo_title);
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $GLOBALS['tmpl']->assign("page_keyword", $seo_keyword . ",");
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $GLOBALS['tmpl']->assign("seo_description", $seo_description . ",");
     //留言
     require APP_ROOT_PATH . 'app/Lib/message.php';
     require APP_ROOT_PATH . 'app/Lib/page.php';
     $rel_table = 'deal';
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "'");
     $condition = "rel_table = '" . $rel_table . "' and rel_id = " . $id;
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
     } else {
         if ($message_type['is_effect'] == 0) {
             $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
         }
     }
     //message_form 变量输出
     $GLOBALS['tmpl']->assign('rel_id', $id);
     $GLOBALS['tmpl']->assign('rel_table', "deal");
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
     $msg_condition = $condition . " AND is_effect = 1 ";
     $message = get_message_list($limit, $msg_condition);
     $page = new Page($message['count'], app_conf("PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     foreach ($message['list'] as $k => $v) {
         $msg_sub = get_message_list("", "pid=" . $v['id'], false);
         $message['list'][$k]["sub"] = $msg_sub["list"];
     }
     $GLOBALS['tmpl']->assign("message_list", $message['list']);
     if (!$GLOBALS['user_info']) {
         $GLOBALS['tmpl']->assign("message_login_tip", sprintf($GLOBALS['lang']['MESSAGE_LOGIN_TIP'], url("shop", "user#login"), url("shop", "user#register")));
     }
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->display("deal_mobile.html");
 }
 public function detail()
 {
     /*if(!$GLOBALS['user_info']){
     			
     			app_redirect(url("index","user#login")); 
     		}*/
     set_gopreview();
     $id = intval($_REQUEST['id']);
     $deal_id = $GLOBALS['db']->getOne("SELECT deal_id FROM " . DB_PREFIX . "deal_load_transfer WHERE id=" . $id);
     if ($deal_id == 0) {
         echo "不存在的债权";
         die;
     }
     $deal = get_deal($deal_id);
     syn_transfer_status($id);
     $deal['yq_count'] = $GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE has_repay = 1 and deal_id=" . $deal_id . " AND status >= 2");
     $GLOBALS['tmpl']->assign('deal', $deal);
     //借款列表
     $load_list = $GLOBALS['db']->getAll("SELECT deal_id,user_id,user_name,money,is_auto,create_time FROM " . DB_PREFIX . "deal_load WHERE deal_id = " . $deal_id);
     $u_info = get_user("*", $deal['user_id']);
     if ($deal['view_info'] != "") {
         $view_info_list = unserialize($deal['view_info']);
         $GLOBALS['tmpl']->assign('view_info_list', $view_info_list);
     }
     //可用额度
     $can_use_quota = get_can_use_quota($deal['user_id']);
     $GLOBALS['tmpl']->assign('can_use_quota', $can_use_quota);
     $credit_file = get_user_credit_file($deal['user_id']);
     $deal['is_faved'] = 0;
     if ($GLOBALS['user_info']) {
         if ($u_info['user_type'] == 1) {
             $company = $GLOBALS['db']->getRowCached("SELECT * FROM " . DB_PREFIX . "user_company WHERE user_id=" . $u_info['id']);
         }
         if ($deal['deal_status'] >= 4) {
             //还款列表
             $loan_repay_list = get_deal_load_list($deal);
             $GLOBALS['tmpl']->assign("loan_repay_list", $loan_repay_list);
             if ($loan_repay_list) {
                 $temp_self_money_list = $GLOBALS['db']->getAllCached("SELECT sum(self_money) as total_money,u_key FROM " . DB_PREFIX . "deal_load_repay WHERE has_repay=1 AND deal_id=" . $id . " group by u_key ");
                 $self_money_list = array();
                 foreach ($temp_self_money_list as $k => $v) {
                     $self_money_list[$v['u_key']] = $v['total_money'];
                 }
                 foreach ($load_list as $k => $v) {
                     $load_list[$k]['remain_money'] = $v['money'] - $self_money_list[$k];
                     if ($load_list[$k]['remain_money'] <= 0) {
                         $load_list[$k]['remain_money'] = 0;
                         $load_list[$k]['status'] = 1;
                     }
                 }
             }
         }
         $user_statics = sys_user_status($deal['user_id'], true);
         $GLOBALS['tmpl']->assign("user_statics", $user_statics);
         $GLOBALS['tmpl']->assign("company", $company);
     }
     $GLOBALS['tmpl']->assign("load_list", $load_list);
     $GLOBALS['tmpl']->assign("credit_file", $credit_file);
     $GLOBALS['tmpl']->assign("u_info", $u_info);
     //工作认证是否过期
     $GLOBALS['tmpl']->assign('expire', user_info_expire($u_info));
     //留言
     require APP_ROOT_PATH . 'app/Lib/message.php';
     require APP_ROOT_PATH . 'app/Lib/page.php';
     $rel_table = 'transfer';
     $message_type = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "message_type where type_name='" . $rel_table . "'");
     $condition = "rel_table = '" . $rel_table . "' and rel_id = " . $id;
     if (app_conf("USER_MESSAGE_AUTO_EFFECT") == 0) {
         $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
     } else {
         if ($message_type['is_effect'] == 0) {
             $condition .= " and user_id = " . intval($GLOBALS['user_info']['id']);
         }
     }
     //message_form 变量输出
     $GLOBALS['tmpl']->assign('rel_id', $id);
     $GLOBALS['tmpl']->assign('rel_table', $rel_table);
     //分页
     $page = intval($_REQUEST['p']);
     if ($page == 0) {
         $page = 1;
     }
     $limit = ($page - 1) * app_conf("PAGE_SIZE") . "," . app_conf("PAGE_SIZE");
     $msg_condition = $condition . " AND is_effect = 1 ";
     $message = get_message_list($limit, $msg_condition);
     $page = new Page($message['count'], app_conf("PAGE_SIZE"));
     //初始化分页对象
     $p = $page->show();
     $GLOBALS['tmpl']->assign('pages', $p);
     foreach ($message['list'] as $k => $v) {
         $msg_sub = get_message_list("", "pid=" . $v['id'], false);
         $message['list'][$k]["sub"] = $msg_sub["list"];
     }
     $GLOBALS['tmpl']->assign("message_list", $message['list']);
     //==================================================
     $condition = ' AND dlt.id=' . $id . ' AND d.deal_status >= 4 and d.is_effect=1 and d.is_delete=0  and d.repay_time_type =1 and  d.publish_wait=0 ';
     $union_sql = " LEFT JOIN " . DB_PREFIX . "deal_load_transfer dlt ON dlt.deal_id = dl.deal_id ";
     $transfer = get_transfer($union_sql, $condition);
     $GLOBALS['tmpl']->assign('transfer', $transfer);
     if ($deal['type_match_row']) {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['type_match_row'] . " - " . $deal['name'];
     } else {
         $seo_title = $deal['seo_title'] != '' ? $deal['seo_title'] : $deal['name'];
     }
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['TRANSFER'] . " - " . $seo_title);
     $seo_keyword = $deal['seo_keyword'] != '' ? $deal['seo_keyword'] : $deal['type_match_row'] . "," . $deal['name'];
     $GLOBALS['tmpl']->assign("page_keyword", $GLOBALS['lang']['TRANSFER'] . "," . $seo_keyword . ",");
     $seo_description = $deal['seo_description'] != '' ? $deal['seo_description'] : $deal['name'];
     $GLOBALS['tmpl']->assign("seo_description", $GLOBALS['lang']['TRANSFER'] . "," . $seo_description . ",");
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->display("page/transfer.html");
 }
 public function repay_plan()
 {
     require_once APP_ROOT_PATH . "app/Lib/common.php";
     require_once APP_ROOT_PATH . "app/Lib/deal.php";
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         $this->success("数据错误");
     }
     $deal_info = get_deal($id);
     if (!$deal_info) {
         $this->success("借款不存在");
     }
     $this->assign("deal_info", $deal_info);
     $repay_list = get_deal_load_list($deal_info);
     if (!$repay_list) {
         $this->success("无还款信息");
     }
     foreach ($repay_list as $k => $v) {
         $repay_list[$k]['idx'] = $k + 1;
     }
     $this->assign("repay_list", $repay_list);
     $this->assign("deal_id", $id);
     $this->assign("deal_info", $deal_info);
     $this->display();
 }
示例#7
0
 public function quick_refund()
 {
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         showErr("操作失败!");
     }
     $deal = get_deal($id);
     if (!$deal) {
         showErr("借款不存在!");
     }
     if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
         showErr("不属于你的借款!");
     }
     if ($deal['deal_status'] != 4) {
         showErr("借款不是还款状态!");
     }
     $GLOBALS['tmpl']->assign('deal', $deal);
     //还款列表
     $loan_list = get_deal_load_list($deal);
     $GLOBALS['tmpl']->assign("loan_list", $loan_list);
     $GLOBALS['tmpl']->assign("deal_id", $id);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_DEAL_REFUND']);
     $GLOBALS['tmpl']->assign("inc_file", "inc/uc/uc_deal_quick_refund.html");
     $GLOBALS['tmpl']->display("page/uc.html");
 }
示例#8
0
 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"));
         }
     }
 }
示例#9
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;
 }
示例#10
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;
}
示例#11
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;
}
示例#12
0
 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");
 }
 public function order_detail()
 {
     $id = intval($_REQUEST['id']);
     if ($id == 0) {
         showErr("操作失败!");
     }
     $deal = get_deal($id);
     if (!$deal) {
         showErr("借款不存在!");
     }
     if ($deal['user_id'] != $GLOBALS['user_info']['id']) {
         showErr("不属于你的借款!");
     }
     /*if($deal['deal_status']!=4){
     			showErr("借款不是还款状态!");
     		}*/
     $GLOBALS['tmpl']->assign('deal', $deal);
     //还款列表
     $loan_list = get_deal_load_list($deal);
     $left_repay_count = $deal["repay_time"];
     foreach ($loan_list as $k => $v) {
         if ($v["has_repay"] == 1) {
             $left_repay_count--;
         }
     }
     $deal["left_repay_count"] = $left_repay_count;
     $GLOBALS['tmpl']->assign("loan_list", $loan_list);
     $GLOBALS['tmpl']->assign("deal", $deal);
     $GLOBALS['tmpl']->assign("page_title", $GLOBALS['lang']['UC_DEAL_REFUND']);
     $GLOBALS['tmpl']->assign("inc_file", "debit/debit_uc_center_order_detail.html");
     $GLOBALS['tmpl']->display("debit/debit_uc.html");
 }
示例#14
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);
     $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' => '""', '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['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);
     $lists = M("DealLoadRepay")->join('LEFT JOIN ' . DB_PREFIX . 'user ON user_id = ' . DB_PREFIX . 'user.id')->limit($limit)->where($sqll)->findAll();
     //$lists->join('LEFT JOIN user ON user_id = user.id')->select();
     //$export_sql= getRow("select * from ".DB_PREFIX."deal where id=".$id) ;
     if ($lists) {
         register_shutdown_function(array(&$this, 'do_repay_plan_export_load'), $page + 1);
         $repay_plan_value = array('id' => '""', 'user_id' => '""', 'repay_money' => '""', 'manage_money' => '""', 'impose_money' => '""', 'repay_time' => '""', 'true_repay_time' => '""');
         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['repay_money'] = iconv('utf-8', 'gbk', '"' . format_price($v['repay_money']) . '"');
             $repay_plan_value['manage_money'] = iconv('utf-8', 'gbk', '"' . format_price($v['manage_money']) . '"');
             $repay_plan_value['impose_money'] = iconv('utf-8', 'gbk', '"' . format_price($v['impose_money']) . '"');
             $repay_plan_value['repay_time'] = iconv('utf-8', 'gbk', '"' . to_date($v['repay_time'], "Y-m-d") . '"');
             $repay_plan_value['true_repay_time'] = iconv('utf-8', 'gbk', '"' . to_date($v['true_repay_time']) . '"');
             $content .= implode(",", $repay_plan_value) . "\n";
         }
     } else {
         if ($page == 1) {
             $this->error(L("NO_RESULT"));
         }
     }
     header("Content-Disposition: attachment; filename=repay_plan_list_one.csv");
     echo $contents;
     echo $content;
 }
示例#15
0
 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");
 }