|
|
|
@ -907,6 +907,11 @@ class Index extends CI_Controller {
|
|
|
|
|
$data['notelist'] = $this->Note_model->search_date($data['date']);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 导出记录用的记录节点
|
|
|
|
|
*/
|
|
|
|
|
$data['record_flags'] = $this->Note_model->list_export_record();
|
|
|
|
|
|
|
|
|
|
$this->load->view('n-header', $data);
|
|
|
|
|
$this->load->view('note_list');
|
|
|
|
|
$this->load->view('n-footer');
|
|
|
|
@ -989,11 +994,80 @@ class Index extends CI_Controller {
|
|
|
|
|
$from_date = $this->input->post("from_date");
|
|
|
|
|
$to_date = $this->input->post("to_date");
|
|
|
|
|
$currency = $this->input->post("currency");
|
|
|
|
|
$export_list = $this->Note_model->date_range($from_date, $to_date, $currency);
|
|
|
|
|
$amount = $this->input->post("set_amount");
|
|
|
|
|
$last_record = $this->input->post("date_history");
|
|
|
|
|
if (empty($amount)) {
|
|
|
|
|
$export_list = $this->Note_model->date_range($from_date, $to_date, $currency);
|
|
|
|
|
} else {
|
|
|
|
|
$allmost_day = intval(ceil($amount/10000));
|
|
|
|
|
if ( ! in_array($currency, array('CNY','USD'))) {
|
|
|
|
|
$allmost_day = 30;
|
|
|
|
|
}
|
|
|
|
|
$last_sn = null;
|
|
|
|
|
if ( ! empty($last_record)) {
|
|
|
|
|
$last_sn = strstr($last_record, '@', TRUE);
|
|
|
|
|
$from_date = substr(strstr($last_record, '@'),1);
|
|
|
|
|
}
|
|
|
|
|
$all_list = $this->target_amount_recursive($currency, $amount, 0, $from_date, $allmost_day, array(), $last_sn);
|
|
|
|
|
$export_list = $all_list['list'];
|
|
|
|
|
}
|
|
|
|
|
if ($export_list == false) {
|
|
|
|
|
echo "Not found any records for export.";
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
// 记录这次导出的最后一条
|
|
|
|
|
if (isset($all_list['last_flag']) && ! empty($all_list['last_flag'])) {
|
|
|
|
|
$insert_db = array(
|
|
|
|
|
"TEL_transactionType" => 15002
|
|
|
|
|
,"TEL_transactionNoticeId" => $all_list['last_flag']->pn_sn
|
|
|
|
|
,"TEL_transactionId" => $all_list['last_flag']->pn_txn_id
|
|
|
|
|
,"TEL_transactionDate" => $all_list['last_flag']->pn_datetime
|
|
|
|
|
,"TEL_transactionAmount" => $all_list['last_flag']->pn_mc_gross
|
|
|
|
|
,"TEL_transactionCurrency" => $all_list['last_flag']->pn_mc_currency
|
|
|
|
|
,"TEL_orderId" => $all_list['last_flag']->pn_invoice
|
|
|
|
|
,"TEL_exportAmount" => $all_list['last_flag']->pn_mc_gross
|
|
|
|
|
,"TEL_exportDate" => date('Y-m-d H:i:s')
|
|
|
|
|
);
|
|
|
|
|
$this->Note_model->export_record($insert_db);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->save_excel($export_list);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* 递归查询收款记录, 直到总金额>=目标总金额
|
|
|
|
|
* @date 2019-02-27
|
|
|
|
|
*/
|
|
|
|
|
public function target_amount_recursive($currency, $target_amount, $now_amount, $from_date,$days=10,$list=array(), $last_sn=null, $last_flag=null)
|
|
|
|
|
{
|
|
|
|
|
$to_date = date('Y-m-d', strtotime("+$days days", strtotime($from_date)));
|
|
|
|
|
$former_list = $this->Note_model->date_range($from_date, $to_date, $currency, $last_sn);
|
|
|
|
|
$list_index = 0;
|
|
|
|
|
$last_sn = $last_sn===null ? 0 : $last_sn;
|
|
|
|
|
$last_flag = $last_flag===null ? null : $last_flag;
|
|
|
|
|
while ($now_amount < $target_amount && isset($former_list[$list_index])) {
|
|
|
|
|
$list[] = $former_list[$list_index];
|
|
|
|
|
$now_amount = bcadd($now_amount, $former_list[$list_index]->pn_mc_gross);
|
|
|
|
|
$last_sn = $former_list[$list_index]->pn_sn;
|
|
|
|
|
$last_flag = $former_list[$list_index];
|
|
|
|
|
$list_index++;
|
|
|
|
|
}
|
|
|
|
|
$ret = array(
|
|
|
|
|
"last_flag" => $last_flag,
|
|
|
|
|
"list" => $list
|
|
|
|
|
);
|
|
|
|
|
if (empty($former_list)) {
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
if ($now_amount < $target_amount) {
|
|
|
|
|
return $this->target_amount_recursive($currency, $target_amount, $now_amount, $to_date, 10, $list, $last_sn, $last_flag);
|
|
|
|
|
} else {
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function save_excel($export_list)
|
|
|
|
|
{
|
|
|
|
|
$this->load->library('PHPExcel');
|
|
|
|
|
$objPHPExcel = new PHPExcel();
|
|
|
|
|
$objPHPExcel->setActiveSheetIndex(0);
|
|
|
|
@ -1005,18 +1079,21 @@ class Index extends CI_Controller {
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(30);
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(20);
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(20);
|
|
|
|
|
// 对齐
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getStyle('B')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getStyle('C')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
|
|
|
|
|
$objPHPExcel->getActiveSheet()->getStyle('D')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
|
|
|
|
|
// 表标题行
|
|
|
|
|
$objPHPExcel->getActiveSheet()
|
|
|
|
|
->SetCellValue('A1', '#')
|
|
|
|
|
->SetCellValue('B1', '团号')
|
|
|
|
|
->SetCellValue('C1', '金额')
|
|
|
|
|
->SetCellValue('D1', '付款人')
|
|
|
|
|
->SetCellValue('E1', '付款人邮箱')
|
|
|
|
|
->SetCellValue('F1', '交易号')
|
|
|
|
|
->SetCellValue('G1', '收单时间');
|
|
|
|
|
->SetCellValue('D1', '币种')
|
|
|
|
|
->SetCellValue('E1', '付款人')
|
|
|
|
|
->SetCellValue('F1', '付款人邮箱')
|
|
|
|
|
->SetCellValue('G1', '交易号')
|
|
|
|
|
->SetCellValue('H1', '收单时间');
|
|
|
|
|
$currency_sum = array();
|
|
|
|
|
bcscale(2);
|
|
|
|
|
$rowCount = 2;
|
|
|
|
@ -1028,12 +1105,14 @@ class Index extends CI_Controller {
|
|
|
|
|
$orderid = $row->pn_invoice ? $row->pn_invoice : $row->pn_item_number;
|
|
|
|
|
$objPHPExcel->getActiveSheet()
|
|
|
|
|
->SetCellValue('A'.$rowCount, ($rowCount-1))
|
|
|
|
|
// ->SetCellValue('A'.$rowCount, $row->pn_sn)
|
|
|
|
|
->setCellValueExplicit('B'.$rowCount, $orderid,PHPExcel_Cell_DataType::TYPE_STRING)
|
|
|
|
|
->setCellValueExplicit('C'.$rowCount, trim($row->pn_mc_currency) . number_format($row->pn_mc_gross, 2, ".", ""),PHPExcel_Cell_DataType::TYPE_STRING)
|
|
|
|
|
->SetCellValue('D'.$rowCount, $row->pn_payer)
|
|
|
|
|
->SetCellValue('E'.$rowCount, $row->pn_payer_email)
|
|
|
|
|
->setCellValueExplicit('F'.$rowCount, $row->pn_txn_id,PHPExcel_Cell_DataType::TYPE_STRING)
|
|
|
|
|
->SetCellValue('G'.$rowCount, $row->pn_datetime);
|
|
|
|
|
->setCellValue('C'.$rowCount, number_format($row->pn_mc_gross, 2, ".", ""))
|
|
|
|
|
->setCellValueExplicit('D'.$rowCount, trim($row->pn_mc_currency) ,PHPExcel_Cell_DataType::TYPE_STRING)
|
|
|
|
|
->SetCellValue('E'.$rowCount, $row->pn_payer)
|
|
|
|
|
->SetCellValue('F'.$rowCount, $row->pn_payer_email)
|
|
|
|
|
->setCellValueExplicit('G'.$rowCount, $row->pn_txn_id,PHPExcel_Cell_DataType::TYPE_STRING)
|
|
|
|
|
->SetCellValue('H'.$rowCount, $row->pn_datetime);
|
|
|
|
|
$payer = $orderid = "";
|
|
|
|
|
$rowCount++;
|
|
|
|
|
}
|
|
|
|
|