/** * 代还款 */ 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("第三方同步暂无法代还款"); } $user_id = $deal_info['user_id']; 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['true_repay_date'] = to_date(TIME_UTC); $user_load_data['is_site_repay'] = 1; $user_load_data['status'] = 0; $user_load_data['true_repay_money'] = (double) $vv['month_repay_money']; $user_load_data['true_self_money'] = (double) $vv['self_money']; $user_load_data['true_interest_money'] = (double) $vv['interest_money']; $user_load_data['true_manage_money'] = (double) $vv['manage_money']; $user_load_data['true_manage_interest_money'] = (double) $vv['manage_interest_money']; $user_load_data['true_repay_manage_money'] = (double) $vv['repay_manage_money']; $user_load_data['true_manage_interest_money_rebate'] = (double) $vv['manage_interest_money_rebate']; $user_load_data['impose_money'] = (double) $vv['impose_money']; $user_load_data['repay_manage_impose_money'] = (double) $vv['repay_manage_impose_money']; $user_load_data['true_reward_money'] = (double) $vv['reward_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>”成功还款".($user_load_data['true_repay_money']+$user_load_data['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)."元。"; $notices['content'] = ",本笔投标的下个还款日为" . to_date($unext_loan['repay_day'], "Y年m月d日") . ",需还本息" . number_format($unext_loan['month_repay_money'], 2) . "元。"; } else { $load_repay_rs = $GLOBALS['db']->getOne("SELECT (sum(true_interest_money) + sum(impose_money)) as shouyi,sum(impose_money) as total_impose_money FROM " . DB_PREFIX . "deal_load_repay WHERE deal_id=" . $deal_info['id'] . " AND user_id=" . $vv['user_id']); $all_shouyi_money = number_format($load_repay_rs['shouyi'], 2); $all_impose_money = number_format($load_repay_rs['total_impose_money'], 2); //$content .= "本次投标共获得收益:".$all_shouyi_money."元,其中违约金为:".$all_impose_money."元,本次投标已回款完毕!"; $notices['content'] = ",本次投标共获得收益:" . $all_shouyi_money . "元,其中违约金为:" . $all_impose_money . "元,本次投标已回款完毕!"; } if ($user_load_data['impose_money'] != 0 || $user_load_data['true_manage_money'] != 0 || $user_load_data['true_repay_money'] != 0) { $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']; } //更新用户账户资金记录 modify_account(array("money" => $user_load_data['true_repay_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,回报本息", 5); if ($user_load_data['true_manage_money'] > 0) { modify_account(array("money" => -$user_load_data['true_manage_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,投标管理费", 20); } //利息管理费 modify_account(array("money" => -$user_load_data['true_manage_interest_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,投标利息管理费", 20); if ($user_load_data['impose_money'] != 0) { modify_account(array("money" => $user_load_data['impose_money']), $in_user_id, "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,逾期罚息", 21); } //普通会员邀请返利 get_referrals($vv['id']); //投资者返佣金 if ($user_load_data['true_manage_interest_money_rebate'] != 0) { /*ok*/ $reback_memo = sprintf($GLOBALS['lang']["INVEST_REBATE_LOG"], $deal_info["url"], $deal_info["name"], $loan_user_info["user_name"], intval($vv["l_key"]) + 1); reback_rebate_money($in_user_id, $user_load_data['true_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'"); $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($user_load_data['true_repay_money'] + $user_load_data['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_shouyi_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); //插入 } //站内信 $notices['shop_title'] = app_conf("SHOP_TITLE"); $notices['url'] = "“<a href=\"" . $deal_info['url'] . "\">" . $deal_info['name'] . "</a>”"; $notices['money'] = $user_load_data['true_repay_money'] + $user_load_data['impose_money']; $tmpl_content = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "msg_template where name = 'TPL_SITE_REPAY'", false); $GLOBALS['tmpl']->assign("notice", $notices); $content = $GLOBALS['tmpl']->fetch("str:" . $tmpl_content['content']); 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']->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_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_shouyi_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"); $adm_session = es_session::get(md5(conf("AUTH_KEY"))); if ($s_count == 0) { $rs_sum = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) as total_repay_money,sum(true_self_money) as total_self_money,sum(true_interest_money) as total_interest_money,sum(true_repay_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); //统计网站代还款 $rs_site_sum = $GLOBALS['db']->getRow("SELECT sum(true_repay_money) as total_repay_money,sum(true_self_money) as total_self_money,sum(true_repay_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 is_site_repay=1 and has_repay = 1"); $repay_data['status'] = (int) $GLOBALS['db']->getOne("SELECT `status` FROM " . DB_PREFIX . "deal_load_repay where deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 1 AND is_site_repay=1 ORDER BY l_key DESC"); $repay_data['true_repay_time'] = TIME_UTC; $repay_data['true_repay_date'] = to_date(TIME_UTC); $repay_data['has_repay'] = 1; $repay_data['impose_money'] = floatval($rs_sum['total_impose_money']); $repay_data['true_self_money'] = floatval($rs_sum['total_self_money']); $repay_data['true_repay_money'] = floatval($rs_sum['total_repay_money']); $repay_data['true_manage_money'] = floatval($rs_sum['total_manage_money']); $repay_data['true_interest_money'] = floatval($rs_sum['total_interest_money']); $repay_data['manage_impose_money'] = floatval($rs_sum['total_repay_manage_impose_money']); $rebate_rs = get_rebate_fee($user_id, "borrow"); $repay_data['true_manage_money_rebate'] = $repay_data['true_manage_money'] * floatval($rebate_rs['rebate']) / 100; //借款者返佣 if ($repay_data['true_manage_money_rebate'] != 0) { /*ok*/ $reback_memo = sprintf(L("BORROW_REBATE_LOG"), $deal_info["url"], $deal_info["name"], $deal_info["user"]["user_name"], intval($l_key) + 1); reback_rebate_money($user_id, $repay_data['true_manage_money_rebate'], "borrow", $reback_memo); } $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $repay_data, "UPDATE", " deal_id=" . $id . " AND l_key=" . $l_key . " and has_repay = 0 "); $impose_day = ceil((to_timespan(to_date(TIME_UTC, "Y-m-d"), "Y-m-d") - $deal_load_list[$l_key]['repay_day']) / 24 / 3600); if ($impose_day > 0) { //VIP 逾期还款降级 $type = 2; $type_info = 5; $resultdate = syn_user_vip($user_id, $type, $type_info); if ($impose_day < app_conf('YZ_IMPSE_DAY')) { modify_account(array("point" => trim(app_conf('IMPOSE_POINT'))), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,逾期还款", 11); } else { modify_account(array("point" => trim(app_conf('YZ_IMPOSE_POINT'))), $deal_info['user_id'], "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . ($kk + 1) . "期,严重逾期", 11); } } else { //VIP 代还款降级 $type = 2; $type_info = 6; $resultdate = syn_user_vip($user_id, $type, $type_info); } if ($rs_site_sum) { $r_msg = "网站代还款"; if ($rs_site_sum['total_repay_money'] > 0) { $r_msg .= ",本息:" . format_price($rs_site_sum['total_repay_money']); } if ($rs_site_sum['total_impose_money'] > 0) { $r_msg .= ",逾期费用:" . format_price($rs_site_sum['total_impose_money']); } if ($rs_site_sum['total_manage_money'] > 0) { $r_msg .= ",管理费:" . format_price($rs_site_sum['total_manage_money']); } if ($rs_site_sum['total_repay_manage_impose_money'] > 0) { $r_msg .= ",逾期管理费:" . format_price($rs_site_sum['total_repay_manage_impose_money']); } repay_log($deal_load_list[$l_key]['repay_id'], $r_msg, 0, $adm_session['adm_id']); } 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']; $generation_repay['admin_id'] = $adm_session['adm_id']; $generation_repay['agency_id'] = $deal_info['agency_id']; $generation_repay['repay_money'] = $rs_site_sum['total_repay_money']; $generation_repay['self_money'] = $rs_site_sum['total_self_money']; $generation_repay['impose_money'] = $rs_site_sum['total_impose_money']; $generation_repay['manage_money'] = $rs_site_sum['total_manage_money']; $generation_repay['manage_impose_money'] = $rs_site_sum['total_repay_manage_impose_money']; $generation_repay['create_time'] = TIME_UTC; $generation_repay['create_date'] = to_date(TIME_UTC, "Y-m-d"); $GLOBALS['db']->autoExecute(DB_PREFIX . "generation_repay", $generation_repay); $site_money_data['user_id'] = $user_id; $site_money_data['create_time'] = TIME_UTC; $site_money_data['create_time_ymd'] = to_date(TIME_UTC, "Y-m-d"); $site_money_data['create_time_ym'] = to_date(TIME_UTC, "Ym"); $site_money_data['create_time_y'] = to_date(TIME_UTC, "Y"); if ($rs_sum['total_manage_money'] != 0) { $site_money_data['memo'] = "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . $l_key . "期,借款管理费"; $site_money_data['type'] = 10; $site_money_data['money'] = $rs_sum['total_manage_money']; $GLOBALS['db']->autoExecute(DB_PREFIX . "site_money_log", $site_money_data, "INSERT"); } if ($rs_sum['total_repay_manage_impose_money'] != 0) { $site_money_data['memo'] = "[<a href='" . $deal_info['url'] . "' target='_blank'>" . $deal_info['name'] . "</a>],第" . $l_key . "期,逾期管理费"; $site_money_data['type'] = 12; $site_money_data['money'] = $rs_sum['total_repay_manage_impose_money']; $GLOBALS['db']->autoExecute(DB_PREFIX . "site_money_log", $site_money_data, "INSERT"); } } } syn_deal_status($deal_info['id']); syn_transfer_status(0, $deal_info['id']); $this->success("代还款执行完毕!"); } else { register_shutdown_function(array(&$this, 'do_site_repay'), $page + 1); } }
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"); }
/** * 更新 用户回款 计划数据 * @param unknown_type $deal_id * @param unknown_type $deal_repay_id */ function syn_deal_repay_status($deal_id, $deal_repay_id) { //has_repay 0未收到还款,1已收到还款 $deal_id = intval($deal_id); $deal_repay_id = intval($deal_repay_id); $deal = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal WHERE id=" . $deal_id); $deal['url'] = url("index", "deal", array("id" => $deal['id'])); $deal["user"] = $GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "user WHERE id=" . $deal['user_id']); //未还款记录数 $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 0 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id; $has_repay_0 = $GLOBALS['db']->getOne($sql); //已经还款记录数 $sql = "select count(*) from " . DB_PREFIX . "deal_load_repay where has_repay = 1 and deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id; $has_repay_1 = $GLOBALS['db']->getOne($sql); //第几期 $kk = $GLOBALS['db']->getOne("select l_key from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id); //has_repay 0未还,1已还 2部分还款 if ($has_repay_0 == 0 && $has_repay_1 == 0 || $has_repay_0 == 0 && $has_repay_1 > 0) { $deal_rs_sql = "select sum(true_interest_money) as total_true_interest_money," . "sum(true_self_money) as total_true_self_money," . "sum(true_repay_money) as total_true_repay_money," . "sum(true_repay_manage_money) as total_true_repay_manage_money," . "sum(repay_manage_impose_money) as total_repay_manage_impose_money, " . "sum(impose_money) as total_impose_money " . "from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id; $deal_rs = $GLOBALS['db']->getRow($deal_rs_sql); $last_Rs = $GLOBALS['db']->getRow("SELECT `status`,`true_repay_time`,`repay_time` from " . DB_PREFIX . "deal_load_repay where deal_id = " . $deal_id . " and repay_id = " . $deal_repay_id . " ORDER BY `true_repay_time` DESC"); $deal_repay_data['true_repay_money'] = $deal_rs['total_true_repay_money']; $deal_repay_data['true_manage_money'] = $deal_rs['total_true_repay_manage_money']; $deal_repay_data['manage_impose_money'] = $deal_rs['total_repay_manage_impose_money']; $deal_repay_data['true_self_repay'] = $deal_rs['total_true_self_money']; $deal_repay_data['impose_money'] = $deal_rs['total_impose_money']; $deal_repay_data['true_interest_money'] = $deal_rs['total_true_interest_money']; $deal_repay_data['true_repay_time'] = $last_Rs['true_repay_time']; $deal_repay_data['true_repay_date'] = to_date($last_Rs['true_repay_time']); $deal_repay_data['status'] = $last_Rs['status']; $deal_repay_data['has_repay'] = 1; //返佣金额 $rebate_rs = get_rebate_fee($deal['user_id'], "borrow"); $deal_repay_data['true_manage_money_rebate'] = floatval($deal_repay_data['true_manage_money']) * floatval($rebate_rs['rebate']) / 100; $true_manage_money_rebate = $deal_repay_data['true_manage_money'] * floatval($rebate_rs['rebate']) / 100; //借款者返佣 if ($true_manage_money_rebate != 0) { /*ok*/ $reback_memo = sprintf($GLOBALS['lang']["BORROW_REBATE_LOG"], $deal["url"], $deal["name"], $deal["user"]["user_name"], intval($kk) + 1); reback_rebate_money($deal['user_id'], $true_manage_money_rebate, "borrow", $reback_memo); } require_once APP_ROOT_PATH . "system/libs/user.php"; if ($last_Rs['status'] > 1) { $impose_day = ceil(($last_Rs['true_repay_time'] - $last_Rs['repay_time'] + 24 * 3600 - 1) / 24 / 3600); //VIP降级-逾期还款 $type = 2; $type_info = 5; $resultdate = syn_user_vip($deal['user_id'], $type, $type_info); if ($impose_day < app_conf('YZ_IMPSE_DAY')) { modify_account(array("point" => trim(app_conf('IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,逾期还款", 11); $repay_update_data['status'] = 2; } else { modify_account(array("point" => trim(app_conf('YZ_IMPOSE_POINT'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],第" . ($kk + 1) . "期,严重逾期", 11); $repay_update_data['status'] = 3; } } elseif ($last_Rs['status'] == 1) { //VIP升级 -正常还款 $type = 1; $type_info = 3; $resultdate = syn_user_vip($deal['user_id'], $type, $type_info); } elseif ($last_Rs['status'] == 0) { //VIP升级 -提前还款 $type = 1; $type_info = 4; $resultdate = syn_user_vip($deal['user_id'], $type, $type_info); } $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_repay", $deal_repay_data, "UPDATE", "id = " . $deal_repay_id); $last_repay_key = $kk; //判断本借款是否还款完毕 if ($GLOBALS['db']->getOne("SELECT count(*) FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and l_key=" . $last_repay_key . " AND has_repay <> 1 ") == 0) { //全部还完 if ($GLOBALS['db']->getRow("SELECT * FROM " . DB_PREFIX . "deal_repay WHERE deal_id=" . $deal['id'] . " and has_repay=0 ") == 0) { //判断获取的信用是否超过限制 if ($GLOBALS['db']->getOne("SELECT sum(point) FROM " . DB_PREFIX . "user_point_log WHERE `type`=6 AND user_id=" . $deal['user_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=" . $deal['user_id']); $day = ceil(($last_Rs['true_repay_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'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款", 4); } } //用户获得额度 modify_account(array("quota" => trim(app_conf('USER_REPAY_QUOTA'))), $deal['user_id'], "[<a href='" . $deal['url'] . "' target='_blank'>" . $deal['name'] . "</a>],还清借款获得额度", 4); } } sys_user_status(intval($GLOBALS['user_info']['id']), false, true); syn_deal_status($deal_id); syn_transfer_status(0, $deal_id); } else { if ($has_repay_0 > 0 && $has_repay_1 == 0) { $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 0 where id = " . $deal_repay_id; } else { $sql = "update " . DB_PREFIX . "deal_repay set has_repay = 2 where id = " . $deal_repay_id; } } $GLOBALS['db']->query($sql); }