function borrowRepayment($borrow_id, $sort_order, $type = 1) { //type 1:会员自己还,2网站代还 $pre = C('DB_PREFIX'); $done = false; $borrowDetail = D('investor_detail'); $binfo = M("borrow_info")->field("id,borrow_name,borrow_uid,borrow_type,borrow_money,borrow_duration,repayment_type,has_pay,total,deadline")->find($borrow_id); $b_member = M('members')->field("user_name")->find($binfo['borrow_uid']); if ($binfo['has_pay'] >= $sort_order) { return "本期已还过,不用再还"; } if ($binfo['has_pay'] == $binfo['total']) { return "此标已经还完,不用再还"; } if ($binfo['has_pay'] + 1 < $sort_order) { return "对不起,此借款第" . ($binfo['has_pay'] + 1) . "期还未还,请先还第" . ($binfo['has_pay'] + 1) . "期"; } if ($binfo['deadline'] < time() && $type == 2) { return "此标还没逾期,不用代还"; } //流转标与普通标,判断还款期数不一样 $voxe = $borrowDetail->field('sort_order,sum(capital) as capital, sum(interest) as interest,sum(interest_fee) as interest_fee,deadline,substitute_time')->where("borrow_id={$borrow_id}")->group('sort_order')->select(); foreach ($voxe as $ee => $ss) { if ($ss['sort_order'] == $sort_order) { $vo = $ss; } } if ($vo['deadline'] < time()) { //此标已逾期 $is_expired = true; if ($vo['substitute_time'] > 0) { $is_substitute = true; } else { $is_substitute = false; } //逾期的相关计算 $expired_days = getExpiredDays($vo['deadline']); $expired_money = getExpiredMoney($expired_days, $vo['capital'], $vo['interest']); $call_fee = getExpiredCallFee($expired_days, $vo['capital'], $vo['interest']); //逾期的相关计算 } else { $is_expired = false; $expired_days = 0; $expired_money = 0; $call_fee = 0; } //流转标与普通标,判断还款期数不一样 MTip('chk25', $binfo['borrow_uid'], $borrow_id); //sss $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money')->find($binfo['borrow_uid']); if ($type == 1 && $binfo['borrow_type'] != 3 && round($accountMoney_borrower['account_money'], 2) < round($vo['capital'] + $vo['interest'] + $expired_money + $call_fee, 2)) { return "帐户可用余额不足,本期还款共需" . ($vo['capital'] + $vo['interest'] + $expired_money + $call_fee) . "元,请先充值"; } if ($is_substitute && $is_expired) { //已代还后的会员还款,则只需要对会员的帐户进行操作后然后更新还款时间即可返回 $borrowDetail->startTrans(); $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 11; $datamoney_x['affect_money'] = -($vo['capital'] + $vo['interest']); $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "对{$borrow_id}号标第{$sort_order}期还款"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } //单独记录还款本金 $datamoney_x['type'] = 32; $datamoney_x['affect_money'] = -$vo['capital']; $datamoney_x['info'] = "对{$borrow_id}号标第{$sort_order}期还款本金金额"; M('member_moneylog')->add($datamoney_x); //逾期了 //逾期罚息 $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money')->find($binfo['borrow_uid']); $datamoney_x = array(); $mmoney_x = array(); $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 30; $datamoney_x['affect_money'] = -$expired_money; $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "{$borrow_id}号标第{$sort_order}期的逾期罚息"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } //催收费 $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money')->find($binfo['borrow_uid']); $datamoney_x = array(); $mmoney_x = array(); $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 31; $datamoney_x['affect_money'] = -$call_fee; $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "{$borrow_id}号标第{$sort_order}期的逾期催收费"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } //逾期了 $day = ceil(($vo['deadline'] - time()) / (3600 * 24)); if ($day > 0 && $day <= 3) { //正常还款 $d_status = 1; } elseif ($day > -3 && $day <= 0) { // $d_status = 3; } elseif ($day <= -3) { //逾期还款 $d_status = 5; } elseif ($day > 3) { //提前还款 $d_status = 2; } $updetail_res = M()->execute("update `{$pre}investor_detail` set `repayment_time`=" . time() . ",`receive_interest`=({$vo['interest']}-{$vo['interest_fee']}),`call_fee`={$call_fee},`expired_money`={$expired_money},`expired_days`={$expired_days},`status`={$d_status} WHERE `borrow_id`={$borrow_id} AND `sort_order`={$sort_order}"); //更新借款信息 $upborrowsql = "update `{$pre}borrow_info` set "; $upborrowsql .= "`repayment_money`=`repayment_money`+{$vo['capital']}"; $upborrowsql .= ",`repayment_interest`=`repayment_interest`+ {$vo['interest']}"; if ($sort_order == $binfo['total'] || $binfo['repayment_type'] == 1) { $upborrowsql .= ",`borrow_status`=7"; } //还款完成 $upborrowsql .= ",`has_pay`={$sort_order}"; //代还则不记录还到第几期,避免会员还款时,提示已还过 if ($is_expired) { $upborrowsql .= ",`expired_money`=`expired_money`+{$expired_money}"; } //代还则不记录还到第几期,避免会员还款时,提示已还过 $upborrowsql .= " WHERE `id`={$borrow_id}"; $upborrow_res = M()->execute($upborrowsql); //更新借款信息 //if($updetail_res&&$bxid&&$upborrow_res){ if ($updetail_res && $upborrow_res) { $borrowDetail->commit(); return true; } else { $borrowDetail->rollback(); return false; } } //流转标与普通标,判断还款期数不一样 $detailList = $borrowDetail->field('invest_id,investor_uid,capital,interest,interest_fee,borrow_id,total')->where("borrow_id={$borrow_id} AND sort_order={$sort_order}")->select(); //流转标与普通标,判断还款期数不一样 //积分与还款状态处理 if ($type == 1) { //客户自己还款才需要记录这些操作 $day_span = ceil(($vo['deadline'] - time()) / (3600 * 24)); $credits_money = intval($vo['capital'] / 100); $credits_info = "对第{$borrow_id}号标的"; $objectFlag = "borrow_" . $borrow_id . "_" . $sort_order; if ($day_span > 0 && $day_span <= 3) { //正常还款 $credits_result = memberCreditsLog($binfo['borrow_uid'], 3, $credits_money, $credits_info . "正常还款奖励经验", $objectFlag); $scores_result = memberScoresLog($binfo['borrow_uid'], 3, $credits_money, $credits_info . "正常还款奖励积分", $objectFlag); $idetail_status = 1; } elseif ($day_span > -3 && $day_span <= 0) { //迟还 $credits_result = memberCreditsLog($binfo['borrow_uid'], 4, $credits_money * -3, $credits_info . "迟还惩罚经验", $objectFlag); $scores_result = memberScoresLog($binfo['borrow_uid'], 4, $credits_money * -3, $credits_info . "迟还惩罚积分", $objectFlag); $idetail_status = 3; } elseif ($day_span <= -3) { //逾期还款 $credits_result = memberCreditsLog($binfo['borrow_uid'], 5, $credits_money * -10, $credits_info . "逾期还款惩罚经验", $objectFlag); $scores_result = memberScoresLog($binfo['borrow_uid'], 5, $credits_money * -10, $credits_info . "逾期还款惩罚积分", $objectFlag); $idetail_status = 5; } elseif ($day_span > 3) { //提前还款 $credits_result = memberCreditsLog($binfo['borrow_uid'], 6, $credits_money * 2, $credits_info . "提前还款奖励经验", $objectFlag); $scores_result = memberScoresLog($binfo['borrow_uid'], 6, $credits_money * 2, $credits_info . "提前还款奖励积分", $objectFlag); $idetail_status = 2; } if (!$credits_result || !$scores_result) { return "因积分经验记录失败,未完成还款操作"; } } //积分与还款状态处理 $borrowDetail->startTrans(); //对借款者帐户进行减少 $bxid = true; if ($type == 1) { $bxid = false; $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 11; $datamoney_x['affect_money'] = -($vo['capital'] + $vo['interest']); $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "对{$borrow_id}号标第{$sort_order}期还款"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } //单独记录还款本金 $datamoney_x['type'] = 32; $datamoney_x['affect_money'] = -$vo['capital']; $datamoney_x['info'] = "对{$borrow_id}号标第{$sort_order}期还款本金金额"; M('member_moneylog')->add($datamoney_x); //逾期了 if ($is_expired) { //逾期罚息 if ($expired_money > 0) { $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money')->find($binfo['borrow_uid']); $datamoney_x = array(); $mmoney_x = array(); $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 30; $datamoney_x['affect_money'] = -$expired_money; $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "{$borrow_id}号标第{$sort_order}期的逾期罚息"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } } //催收费 if ($call_fee > 0) { $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money')->find($binfo['borrow_uid']); $datamoney_x = array(); $mmoney_x = array(); $datamoney_x['uid'] = $binfo['borrow_uid']; $datamoney_x['type'] = 31; $datamoney_x['affect_money'] = -$call_fee; $datamoney_x['account_money'] = $accountMoney_borrower['account_money'] + $datamoney_x['affect_money']; $datamoney_x['collect_money'] = $accountMoney_borrower['money_collect']; $datamoney_x['freeze_money'] = $accountMoney_borrower['money_freeze']; //会员帐户 $mmoney_x['money_freeze'] = $datamoney_x['freeze_money']; $mmoney_x['money_collect'] = $datamoney_x['collect_money']; $mmoney_x['account_money'] = $datamoney_x['account_money']; //会员帐户 $datamoney_x['info'] = "{$borrow_id}号标第{$sort_order}期的逾期催收费"; $datamoney_x['add_time'] = time(); $datamoney_x['add_ip'] = get_client_ip(); $datamoney_x['target_uid'] = 0; $datamoney_x['target_uname'] = '@网站管理员@'; $moneynewid_x = M('member_moneylog')->add($datamoney_x); if ($moneynewid_x) { $bxid = M('member_money')->where("uid={$datamoney_x['uid']}")->save($mmoney_x); } } } //逾期了 } //对借款者帐户进行减少 //更新借款信息 $upborrowsql = "update `{$pre}borrow_info` set "; $upborrowsql .= "`repayment_money`=`repayment_money`+{$vo['capital']}"; $upborrowsql .= ",`repayment_interest`=`repayment_interest`+ {$vo['interest']}"; if ($sort_order == $binfo['total'] || $binfo['repayment_type'] == 1) { $upborrowsql .= ",`borrow_status`=7"; } //还款完成 //如果是网站代还的,则记录代还金额 if ($type == 2) { $total_subs = $vo['capital'] + $vo['interest']; $upborrowsql .= ",`substitute_money`=`substitute_money`+ {$total_subs}"; } //如果是网站代还的,则记录代还金额 if ($type == 1) { $upborrowsql .= ",`has_pay`={$sort_order}"; } //代还则不记录还到第几期,避免会员还款时,提示已还过 if ($is_expired) { $upborrowsql .= ",`expired_money`=`expired_money`+{$expired_money}"; } //代还则不记录还到第几期,避免会员还款时,提示已还过 $upborrowsql .= " WHERE `id`={$borrow_id}"; $upborrow_res = M()->execute($upborrowsql); //更新借款信息 //更新还款详情表 if ($type == 2) { //网站代还 $updetail_res = M()->execute("update `{$pre}investor_detail` set `receive_capital`=`capital`,`substitute_time`=" . time() . " ,`substitute_money`=`substitute_money`+{$total_subs},`status`=4 WHERE `borrow_id`={$borrow_id} AND `sort_order`={$sort_order}"); } else { $updetail_res = M()->execute("update `{$pre}investor_detail` set `receive_capital`=`capital` ,`receive_interest`=(`interest`-`interest_fee`),`repayment_time`=" . time() . ", `status`={$idetail_status} WHERE `borrow_id`={$borrow_id} AND `sort_order`={$sort_order}"); } //更新还款详情表 //更新还款概要表 $smsUid = ""; foreach ($detailList as $v) { $getInterest = $v['interest'] - $v['interest_fee']; $upsql = "update `{$pre}borrow_investor` set "; $upsql .= "`receive_capital`=`receive_capital`+{$v['capital']},"; $upsql .= "`receive_interest`=`receive_interest`+ {$getInterest},"; if ($type == 2) { $total_s_invest = $v['capital'] + $getInterest; $upsql .= "`substitute_money` = `substitute_money` + {$total_s_invest},"; } if ($sort_order == $binfo['total'] || $binfo['repayment_type'] == 1) { $upsql .= "`status`=5,"; } //还款完成 $upsql .= "`paid_fee`=`paid_fee`+{$v['interest_fee']}"; $upsql .= " WHERE `id`={$v['invest_id']}"; $upinfo_res = M()->execute($upsql); //对投资帐户进行增加 if ($upinfo_res) { $accountMoney = M('member_money')->field('money_freeze,money_collect,account_money')->find($v['investor_uid']); $datamoney['uid'] = $v['investor_uid']; $datamoney['type'] = $type == 2 ? "10" : "9"; $datamoney['affect_money'] = $v['capital'] + $v['interest']; //先收利息加本金,再扣管理费 $datamoney['account_money'] = $accountMoney['account_money'] + $datamoney['affect_money']; $datamoney['collect_money'] = $accountMoney['money_collect'] - $datamoney['affect_money']; $datamoney['freeze_money'] = $accountMoney['money_freeze']; //会员帐户 $mmoney['money_freeze'] = $datamoney['freeze_money']; $mmoney['money_collect'] = $datamoney['collect_money']; $mmoney['account_money'] = $datamoney['account_money']; //会员帐户 $datamoney['info'] = $type == 2 ? "网站对{$v['borrow_id']}号标第{$sort_order}期代还" : "会员对{$v['borrow_id']}号标第{$sort_order}期还款"; $datamoney['add_time'] = time(); $datamoney['add_ip'] = get_client_ip(); if ($type == 2) { $datamoney['target_uid'] = 0; $datamoney['target_uname'] = '@网站管理员@'; } else { $datamoney['target_uid'] = $binfo['borrow_uid']; $datamoney['target_uname'] = $b_member['user_name']; } $moneynewid = M('member_moneylog')->add($datamoney); if ($moneynewid) { $xid = M('member_money')->where("uid={$datamoney['uid']}")->save($mmoney); } $systips = M("sys_tip")->find($v['investor_uid']); if ($type == 2) { MTip('chk18', $v['investor_uid'], $borrow_id); //sss if (checkNeedTip($systips, 'altpay_3')) { $smsUid .= empty($smsUid) ? $v['investor_uid'] : ",{$v['investor_uid']}"; } } else { MTip('chk16', $v['investor_uid'], $borrow_id); //sss if (checkNeedTip($systips, 'getpay_3')) { $smsUid .= empty($smsUid) ? $v['investor_uid'] : ",{$v['investor_uid']}"; } } //利息管理费 $xid_z = true; if ($v['interest_fee'] > 0 && $type == 1) { $xid_z = false; $accountMoney = M('member_money')->field('money_freeze,money_collect,account_money')->find($v['investor_uid']); $datamoney_z['uid'] = $v['investor_uid']; $datamoney_z['type'] = 23; $datamoney_z['affect_money'] = -$v['interest_fee']; //扣管理费 $datamoney_z['account_money'] = $mmoney['account_money'] + $datamoney_z['affect_money']; $datamoney_z['collect_money'] = $mmoney['money_collect']; $datamoney_z['freeze_money'] = $mmoney['money_freeze']; //会员帐户 $mmoney_z['money_freeze'] = $datamoney_z['freeze_money']; $mmoney_z['money_collect'] = $datamoney_z['collect_money']; $mmoney_z['account_money'] = $datamoney_z['account_money']; //会员帐户 $datamoney_z['info'] = "收到第{$v['borrow_id']}号标第{$sort_order}期还款的利息管理费"; $datamoney_z['add_time'] = time(); $datamoney_z['add_ip'] = get_client_ip(); $datamoney_z['target_uid'] = 0; $datamoney_z['target_uname'] = '@网站管理员@'; $moneynewid_z = M('member_moneylog')->add($datamoney_z); if ($moneynewid_z) { $xid_z = M('member_money')->where("uid={$datamoney_z['uid']}")->save($mmoney_z); } } //利息管理费 } //对投资帐户进行增加 } //邮件提醒 $subject = "您借出的借款[" . $binfo['borrow_name'] . "]收到了新的还款"; $link = '<br /><a href="http://' . $_SERVER['HTTP_HOST'] . '/invest/' . $borrow_id . '.html" style="color:#91273d">点击查看[' . $binfo['borrow_name'] . ']</a>'; if ($type == 2) { investDetailEmail($subject, $subject . $link, 'chk18', "altpay_2", $borrow_id); } else { investDetailEmail($subject, $subject . $link, 'chk16', "getpay_2", $borrow_id); } //更新还款概要表 //echo "$updetail_res && $upinfo_res && $xid &&$upborrow_res && $bxid && $xid_z"; if ($updetail_res !== false && $upinfo_res !== false && $xid !== false && $upborrow_res !== false && $bxid !== false && $xid_z !== false) { $borrowDetail->commit(); $_last = true; if (($binfo['total'] == $binfo['has_pay'] + 1 || $binfo['repayment_type'] == 1) && $type == 1) { $_last = false; $_last = lastRepayment($binfo); //最后一笔还款 } if ($_last === false) { return "因满标操作未完成,还款操作失败"; } $done = true; $vphone = M("members")->alias("m")->join("{$pre}members_status ms on ms.uid=m.id")->field("m.user_phone")->where("m.id in({$smsUid}) and ms.phone_status=1")->select(); $sphone = ""; foreach ($vphone as $v) { $sphone .= empty($sphone) ? $v['user_phone'] : ",{$v['user_phone']}"; } SMStip("payback", $sphone, array("#ID#", "#ORDER#"), array($borrow_id, $sort_order), $borrow_id, explode(',', $smsUid)); } else { $borrowDetail->rollback(); } return $done; }
function getMBreakRepaymentList($uid = 0, $size = 10, $Wsql = "") { if (empty($uid)) { return; } $pre = C('DB_PREFIX'); if ($size) { //分页处理 import("ORG.Util.Page"); $count = M()->query("select d.id as count from {$pre}investor_detail d where d.borrow_id in(select tb.id from {$pre}borrow_info tb where tb.borrow_uid={$uid} AND tb.borrow_status in(6,9)) AND d.deadline<" . time() . " AND d.repayment_time=0 {$Wsql} group by d.sort_order,d.borrow_id"); $count = count($count); $p = new \Org\Util\Page($count, $size); $page = $p->show(); $Lsql = "{$p->firstRow},{$p->listRows}"; //分页处理 } else { $page = ""; $Lsql = "{$parm['limit']}"; } $field = "b.borrow_name,d.status,d.total,d.borrow_id,d.sort_order,sum(d.capital) as capital,sum(d.interest) as interest,d.deadline"; $sql = "select {$field} from {$pre}investor_detail d left join {$pre}borrow_info b ON b.id=d.borrow_id where d.borrow_uid ={$uid} AND b.borrow_status in(6,9) AND d.deadline<" . time() . " AND d.repayment_time=0 {$Wsql} group by d.sort_order,d.borrow_id order by d.borrow_id,d.sort_order limit {$Lsql}"; $list = M()->query($sql); $status_arr = array('还未还', '已还完', '已提前还款', '逾期还款', '网站代还本金'); $glodata = get_global_setting(); $expired = explode("|", $glodata['fee_expired']); $call_fee = explode("|", $glodata['fee_call']); foreach ($list as $key => $v) { $list[$key]['status'] = $status_arr[$v['status']]; $list[$key]['breakday'] = getExpiredDays($v['deadline']); if ($list[$key]['breakday'] > $expired[0]) { $list[$key]['expired_money'] = getExpiredMoney($list[$key]['breakday'], $v['capital'], $v['interest']); } if ($list[$key]['breakday'] > $call_fee[0]) { $list[$key]['call_fee'] = getExpiredCallFee($list[$key]['breakday'], $v['capital'], $v['interest']); } $list[$key]['allneed'] = $list[$key]['call_fee'] + $list[$key]['expired_money'] + $v['capital'] + $v['interest']; } $row = array(); $row['list'] = $list; $row['page'] = $page; $row['count'] = $count; return $row; }
function repaymentList($borrow_id, $sort_order, $type = 1) { $pre = C('DB_PREFIX'); $loanconfig = FS("Webconfig/loanconfig"); $detail = array(); $borrowDetail = D('investor_detail'); $binfo = M("borrow_info")->field("id,borrow_uid, borrow_type, borrow_money, borrow_duration,repayment_type,has_pay,total,deadline, borrow_status")->find($borrow_id); $b_member = M('members')->field("user_name")->find($binfo['borrow_uid']); if ($binfo['has_pay'] >= $sort_order) { ajaxmsg("本期已还过,不用再还", 0); } if ($binfo['has_pay'] == $binfo['total']) { ajaxmsg("此标已经还完,不用再还", 0); } if ($binfo['has_pay'] + 1 < $sort_order) { ajaxmsg("对不起,此借款第" . ($binfo['has_pay'] + 1) . "期还未还,请先还第" . ($binfo['has_pay'] + 1) . "期", 0); } if ($binfo['deadline'] > time() && $type == 2) { ajaxmsg("此标还没逾期,不用代还", 0); } $accountMoney_borrower = M('member_money')->field('money_freeze,money_collect,account_money,back_money')->find($binfo['borrow_uid']); $voxe = $borrowDetail->field('sort_order,sum(capital) as capital, sum(interest) as interest,sum(interest_fee) as interest_fee,deadline,substitute_time')->where("borrow_id={$borrow_id} and sort_order={$sort_order} and pay_status=1")->group('sort_order')->find(); if ($voxe['deadline'] < time()) { //此标已逾期 $is_expired = 1; $expired_days = getExpiredDays($voxe['deadline']); $expired_money = getExpiredMoney($expired_days, $voxe['capital'], $voxe['interest']); // 预期管理费 $call_fee = getExpiredCallFee($expired_days, $voxe['capital'], $voxe['interest']); // 催收费用 //逾期的相关计算 } else { $is_expired = 0; $expired_days = 0; $expired_money = 0; $call_fee = 0; } $detail['is_expired'] = $is_expired; //逾期的相关计算 start $detail['expired_days'] = $expired_days; $detail['expired_money'] = $expired_money; $detail['call_fee'] = $call_fee; //逾期的相关计算 end if ($type == 1 && $binfo['borrow_type'] != 3 && $accountMoney_borrower['account_money'] + $accountMoney_borrower['back_money'] < $vo['capital'] + $vo['interest'] + $expired_money + $call_fee) { $this->error("帐户可用余额不足,本期还款共需" . ($voxe['capital'] + $voxe['interest'] + $expired_money + $call_fee) . "元,请先充值"); } $vo = $borrowDetail->field('invest_id, investor_uid, sort_order,capital, interest, interest_fee , deadline,substitute_time')->where("borrow_id={$borrow_id} and sort_order={$sort_order} and pay_status=1")->select(); foreach ($vo as $k => $v) { if ($v['substitute_time'] > 0) { //已代还 将资金给网站 $v['qdd_marked'] = $loanconfig['pfmmm']; } else { // 没有待还将资金还给投资人 $escrow = M('escrow_account')->field('qdd_marked')->where("uid={$v['investor_uid']}")->find(); $v['qdd_marked'] = $escrow['qdd_marked']; } $detail['list'][$k] = $v; } //print_R($detail);exit; return $detail; }
private function _listFilter($list) { $row = array(); foreach ($list as $key => $v) { $v['breakday'] = getExpiredDays($v['deadline']); $v['expired_money'] = getExpiredMoney($v['breakday'], $v['capital'], $v['interest']); $v['call_fee'] = getExpiredCallFee($v['breakday'], $v['capital'], $v['interest']); $row[$key] = $v; } return $row; }
private function _tendlist($list) { $areaList = getArea(); $row = array(); foreach ($list as $key => $v) { $v['location'] = $areaList[$v['province']] . $areaList[$v['city']] . $areaList[$v['area']]; $v['breakday'] = getExpiredDays($v['deadline']); $v['expired_money'] = getExpiredMoney($v['breakday'], $v['total_expired'], $v['interest']); $v['call_fee'] = getExpiredCallFee($v['breakday'], $v['total_expired'], $v['interest']); $row[$key] = $v; } return $row; }