diff --git a/webht/third_party/pay/controllers/report.php b/webht/third_party/pay/controllers/report.php index 2a99cc1b..9b3d8202 100644 --- a/webht/third_party/pay/controllers/report.php +++ b/webht/third_party/pay/controllers/report.php @@ -168,6 +168,7 @@ class Report extends CI_Controller public function ipaylinks_excel() { $this->load->model('IPayLinks_model'); + $this->load->model('Note_model'); set_time_limit(0); // 解析excel $target_folder = $this->input->get_post("f"); @@ -175,6 +176,9 @@ class Report extends CI_Controller log_message('error','ipaylinks excel POST: ' . $target_folder . $this->input->get_post("fjson")); $statement_folder = FCPATH.'download_statement\statement_files\\' . $target_folder; if ( ! is_dir($statement_folder)) { + + log_message('error','is not dir' . $statement_folder); + return; } $files = $files ? $files : array_values(array_diff(scandir($statement_folder), array('.', '..'))); @@ -195,6 +199,7 @@ class Report extends CI_Controller continue; } $settlement_record = $this->read_ipaylinks_excel($file_path); + if (empty($settlement_record)) { continue; } @@ -208,24 +213,40 @@ class Report extends CI_Controller $old_info = $this->IPayLinks_model->get_money_t(trim($settle['pn_invoice'])); } } - $warrant["PR_AccreditNo"] = trim($settle['pn_invoice']); - $warrant["PR_payType"] = 15018; - $warrant["PR_entryCurrency"] = trim($settle['entry_currency']); - $warrant["PR_entryAmount"] = bcadd(floatval($settle['entry_security']), floatval($settle['entry_basic'])); - $warrant["PR_COLI_SN"] = !empty($old_info) ? $old_info[0]->GAI_COLI_SN : NULL; - $warrant["PR_currency"] = trim($settle['currency']); - $warrant["PR_amount"] = trim($settle['order_amount']); - $warrant["PR_orderType"] = $orderid_info ? $orderid_info->ordertype : NULL; - $warrant["PR_fee"] = bcadd(trim($settle['service_fee']), trim($settle['transaction_fee'])); - $warrant["PR_paymentTime"] = trim($settle['complete_date']); - $warrant["PR_dealType"] = trim($settle['data_type']); - $warrant["PR_orderId"] = trim($settle['orderid']); - $warrant["PR_rate"] = trim($settle['settlement_rate']); - $warrant["PR_status"] = ""; - $warrant["PR_buyerName"] = ""; - $warrant["PR_buyerEmail"] = ""; - $this->Report_model->new_report($warrant); - $warrant = NULL; + $this->Note_model->save_ipl( + strval(trim($settle['pn_invoice'])) + ,strval(trim($settle['orderid'])) + ,strval(trim($settle['currency'])) + ,strval($settle['payment_type'])=="消费" ? strval(trim($settle['order_amount'])) : "-".$settle['order_amount'] + ,NULL + ,NULL + ,strval(trim($settle['complete_date'])) + ,strval(trim($settle['complete_date'])) + ,json_encode($settle) + ,strval($settle['payment_type'])=="消费" ? "pay" : "refund" + ,"0000" + ,"" + ,strval(substr($settle["payer"],0,49)) + ,strval($settle["email"]) + ); + // $warrant["PR_AccreditNo"] = trim($settle['pn_invoice']); + // $warrant["PR_payType"] = 15018; + // $warrant["PR_entryCurrency"] = trim($settle['entry_currency']); + // $warrant["PR_entryAmount"] = bcadd(floatval($settle['entry_security']), floatval($settle['entry_basic'])); + // $warrant["PR_COLI_SN"] = !empty($old_info) ? $old_info[0]->GAI_COLI_SN : NULL; + // $warrant["PR_currency"] = trim($settle['currency']); + // $warrant["PR_amount"] = trim($settle['order_amount']); + // $warrant["PR_orderType"] = $orderid_info ? $orderid_info->ordertype : NULL; + // $warrant["PR_fee"] = bcadd(trim($settle['service_fee']), trim($settle['transaction_fee'])); + // $warrant["PR_paymentTime"] = trim($settle['complete_date']); + // $warrant["PR_dealType"] = trim($settle['data_type']); + // $warrant["PR_orderId"] = trim($settle['orderid']); + // $warrant["PR_rate"] = trim($settle['settlement_rate']); + // $warrant["PR_status"] = ""; + // $warrant["PR_buyerName"] = ""; + // $warrant["PR_buyerEmail"] = ""; + // $this->Report_model->new_report($warrant); + // $warrant = NULL; $update_cnt++; } $settlement_record = null; // reset @@ -260,6 +281,60 @@ class Report extends CI_Controller /**取得最大的列号*/ $allColumn = $currentSheet->getHighestColumn(); + /**取得一共有多少行*/ + $allRow = $currentSheet->getHighestRow(); + $col_titles = $this->ipaylinks_col_title(); + /**从第二行开始输出,因为excel表中第一行为列名*/ + for($currentRow = 2;$currentRow <= $allRow;$currentRow++){ + $row_tmp = array(); + /**从第A列开始输出*/ + for($currentColumn= 'A';$currentColumn<= "Z"; $currentColumn++){ + /**ord()将字符转为十进制数*/ + $val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue()); + if ( ! isset($col_titles[$currentColumn])) { + continue; + } + $col_mean = $col_titles[$currentColumn]; + if($col_mean == 'data_type' && in_array($val, $this->ipaylinks_noStore_dealType()) ) // strcasecmp('清算', $val) !== 0 + { + break; + } + if ($col_mean == 'orderid' && strcasecmp('-', $val) === 0) { + break; + } + $row_tmp[$col_mean] = $val; + } + if ($row_tmp['payment_type']!='消费') { + $row_tmp['orderid']=$row_tmp['raw_order']; + } + if (isset($row_tmp['order_amount'])) { + $tarr1[] = $row_tmp; + } + } + return $tarr1; + } + + public function read_ipaylinks_excel2($filePath) + { + $tarr1=array(); + $this->load->library('PHPExcel'); + $PHPExcel = new PHPExcel(); + /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ + $PHPReader = new PHPExcel_Reader_Excel2007(); + if(!$PHPReader->canRead($filePath)){ + $PHPReader = new PHPExcel_Reader_Excel5(); + if(!$PHPReader->canRead($filePath)){ + echo 'no Excel'; + return ; + } + } + $PHPExcel = $PHPReader->load($filePath); + /**读取excel文件中的第一个工作表*/ + $currentSheet = $PHPExcel->getSheet(0); + + /**取得最大的列号*/ + $allColumn = $currentSheet->getHighestColumn(); + /**取得一共有多少行*/ $allRow = $currentSheet->getHighestRow(); $col_titles = $this->ipaylinks_col_title(); @@ -287,6 +362,21 @@ class Report extends CI_Controller return $tarr1; } public function ipaylinks_col_title() + { + return array( + "A" => "orderid", + "B" => "pn_invoice", + "C" => "complete_date", + "D" => "require_date", + "E" => "currency", + "F" => "order_amount", + "H" => "payer", + "M" => "raw_order", + "N" => "payment_type", + "R" => "email" + ); + } + public function ipaylinks_col_title2() { return array( "A" => "complete_date",