Example #1
0
 public function detail($sn)
 {
     $sql = 'SELECT `id`, `sn`,`title`,`amount`, `period`, `apr`, from_unixtime(`verified_time`) FROM t_borrow WHERE `sn` = "' . $sn . '"';
     $query = $this->db->query($sql);
     $borrow = $query->row_array();
     $sql = 'SELECT `uid`, `capital`,`recover_total_interest`,`bag_id` FROM t_tender_log WHERE `borrow_id` = ' . (int) $borrow['id'];
     $query = $this->db->query($sql);
     $logs = $query->result_array();
     //        echo join(',', $borrow) . "\n";
     foreach ($logs as $log) {
         $realpay = $log['recover_total_interest'];
         $payable = EqualDayEnd($borrow['period'], $log['capital'], $borrow['apr'], "all");
         $spread = bcsub($realpay, $payable['interest_total'], 3);
         $add_apr = $this->_get_add_apr($log['bag_id']);
         echo "{$log['uid']}, {$log['capital']}, {$add_apr}, {$payable['interest_total']}, {$realpay}, {$spread}\n";
     }
 }
Example #2
0
 /**
  * 审核借款信息
  * @param  array   $borrow        借款信息
  * @return boolean
  */
 public function fills($borrow)
 {
     $this->load->model('tender_log_model', 'tender_log');
     $this->load->model('repay_log_model', 'repay_log');
     $this->load->model('api_fund_model', 'api_fund');
     $this->load->model('plus_coupons_model', 'plus_coupons');
     $this->config->load('account_status');
     $account_status = $this->config->item('account_status');
     $tender_log = $this->tender_log->get_by_borrow($borrow['id']);
     if ($tender_log) {
         foreach ($tender_log as $v) {
             //如果使用了道具,加息
             if ($v['bag_id'] > 0) {
                 $this->plus_coupons->sucess_coupons($v['bag_id'], $v['id']);
                 $bag = $this->plus_coupons->get_Ones($v['bag_id']);
                 $add_apr = $bag['apr'];
             } else {
                 $add_apr = 0;
             }
             //调用计算算法计算每期本息
             if ($borrow['repay_type'] == 'day') {
                 $equal = EqualDayEnd($borrow['period'], $v['capital'], $borrow['apr'] + $add_apr, "");
             } else {
                 if ($borrow['repay_type'] == 'monthly') {
                     $equal = EqualMonth($borrow['period'] / 30, $v['capital'], $borrow['apr'] + $add_apr, '', "");
                 }
             }
             if ($equal) {
                 $money = 0;
                 $re = 1;
                 foreach ($equal as $key => $item) {
                     $money = $money + $item['account_interest'];
                     if ($re) {
                         $data['uid'] = $v['uid'];
                         $data['borrow_id'] = $v['borrow_id'];
                         $data['borrower'] = $v['borrower'];
                         $data['tender_id'] = $v['id'];
                         $data['recover_period'] = $key + 1;
                         $data['recover_time'] = $item['repay_time'];
                         $data['recover_amount'] = $item['account_all'];
                         $data['recover_interest'] = $item['account_interest'];
                         $data['recover_capital'] = $item['account_capital'];
                         $data['everyday_interest'] = isset($item['interest_day']) ? $item['interest_day'] : 0;
                         $re = $re && $this->repay_log->replace($data);
                     } else {
                         return FALSE;
                     }
                 }
             }
             if ($re) {
                 if ($borrow['repay_type'] == 'day') {
                     $invest = EqualDayEnd($borrow['period'], $v['capital'], $borrow['apr'] + $add_apr, "all");
                 } else {
                     if ($borrow['repay_type'] == 'monthly') {
                         $invest = EqualMonth($borrow['period'] / 30, $v['capital'], $borrow['apr'] + $add_apr, '', "all");
                     }
                 }
                 $t_data = array('recover_total_money' => $invest['account_total'], 'recover_total_interest' => $invest['interest_total'], 'recover_wait_money' => $invest['account_total'], 'recover_wait_interest' => $invest['interest_total'], 'recover_wait_capital' => $invest['capital_total'], 'status' => 'going', 'recover_times' => count($equal), 'recover_last_time' => $equal[count($equal) - 1]['repay_time']);
                 $re = $this->tender_log->update($v['id'], $t_data);
                 if ($re === FALSE) {
                     return FALSE;
                 }
                 $param = array('uid' => $v['uid'], 'money' => "{$v['capital']}, {$money}", 'tob' => 'tender_success_capital,tender_success_interest', 'rel_data_id' => $v['id'], 'trans_id' => $v['id'], 'pot' => date('Ymd'));
                 $api = $this->api_fund->send($param);
                 if ($api['error'] == 1) {
                     //记录需要发送的短信
                     $sms_data[$v['id']] = array('uid' => $v['uid'], 'borrow_no' => 'NO.' . $borrow['sn'], 'money' => round($v['capital'], 0), 'income' => $invest['interest_total'], 'repaydate' => date('Y年m月d日', $t_data['recover_last_time']), 'borrow_info' => ($borrow['period'] % 30 == 0 ? $borrow['period'] / 30 . '月' : $borrow['period'] . '天') . "/" . ($borrow['deal_flag'] == 'mortgage' ? '抵押' : '质押') . "/" . $borrow['apr'], 'is_auto' => $v['is_auto'], 'tender_id' => $v['id']);
                     //统计变化
                     $this->load->model('User_account_count_model', 'user_account_count');
                     $this->user_account_count->upData(array('await_count' => $t_data['recover_wait_interest'], 'await_corpus_count' => $t_data['recover_wait_capital'], 'await_count_count' => 1), $v['uid']);
                     $account_log = array('rel_data' => array('money' => $v['capital'], 'title' => $borrow['title'], 'account' => $api['data']['balance'], 'logs' => array(1 => array('status' => '资金解冻', 'success' => 1, 'created' => date("Y-m-d H:i:s")))), 'rel_type' => 'tender', 'uid' => $v['uid'], 'ticket_id' => $v['id']);
                     Event::trigger('user_account_change', $account_log);
                 } else {
                     return FALSE;
                 }
             } else {
                 return FALSE;
             }
         }
         //总利息
         $total_interest = $this->tender_log->get_ones_interest($borrow['id'], array('recover_wait_interest'));
         //修改标的状态
         $re = $this->update($borrow['id'], array('status' => 'repayment', 'reverified_time' => time(), 'repay_times' => count($equal), 'repay_last_time' => $equal[count($equal) - 1]['repay_time'], 'total_interest' => $total_interest[0]['recover_wait_interest']));
         if (!$re) {
             return FALSE;
         }
         $this->sms_tender_success($sms_data);
     }
     return TRUE;
 }