todo: iPaylinks账单数据录入

feature/pay
lyt 6 years ago
parent 32bf3e0211
commit 47bb503cbf

@ -1,4 +1,5 @@
<?php
$config['method_code'] = "15018";
$config['version'] = "1.1";
$config['partnerId'] = "10000004000";
$config['siteId'] = "www.chinahighlights.com";

@ -8,6 +8,7 @@ class PaymentService extends CI_Controller {
bcscale(2);
mb_regex_encoding("UTF-8");
$this->load->helper('payment');
$this->config->load('ipaylinks', true);
$this->config->load('wxpay', true);
$this->config->load('paypal', true);
$this->load->model('Online_payment_note_model', 'note_model');
@ -602,5 +603,125 @@ class PaymentService extends CI_Controller {
return false;
}
public function ipalinks_settlement($year, $month, $day=null)
{
set_time_limit(0);
ignore_user_abort(true);
$this->load->library('ipaylinks_call');
$fun_version = $this->input->get_post('fun');
$target_folder = "ipaylinks-" . $year;
$target_file = $year . "-" . $month;
$target_file .= ($day===null) ? null : ("-" . $day);
$statement_folder = FCPATH.'download_statement\settlement_files\\' . $target_folder;
if ( ! is_dir($statement_folder)) {
echo "read folder failed";
return;
}
$files = array_values(array_diff(scandir($statement_folder), array('.', '..')));
if (empty($files)) {
echo "none excel.";
return;
}
$settle_cnt = 0;
$insert_cnt = 0;
$file_path_output = "";
foreach ($files as $k => $fe) {
if ( ! in_array(strrchr($fe, '.'), array(".xlsx", ".xls"))) {
continue;
}
if (stripos($fe, $target_file)===false) {
continue;
}
$file_path = $statement_folder . '\\' . $fe;
if ( ! file_exists($file_path)) {
continue;
}
if ($fun_version==='old') {
$settlement_record = $this->ipalinks_call->read_excel_old($file_path);
} else {
$settlement_record = $this->ipalinks_call->read_excel_new($file_path);
}
if (empty($settlement_record)) {
continue;
}
foreach ($settlement_record as $settle) {
// $orderid_info = analysis_orderid(trim($settle['orderid']));
// $orderid_info = json_decode($orderid_info);
// if ( ! empty($orderid_info)) {
// if (strcasecmp($orderid_info->table, "biz") === 0
// ) {
// $old_info = $this->account_model->get_money_b(trim($settle['pn_invoice']));
// } else if (strcasecmp($orderid_info->table, "tour") === 0){
// $old_info = $this->account_model->get_money_t(trim($settle['pn_invoice']));
// }
// }
$save_column = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'ipaylinks');
if ($row['refund_id'] != '0') {
// 退款
$ssje = $this->account_model->get_ssje($row['settlement_refund_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['refund_id'];
$save_column['OPN_orderAmount'] = "-" . $row['settlement_refund_fee'];
$save_column['OPN_payAmount'] = "-" . $row['settlement_refund_fee'];
$save_column['OPN_resultCode'] = $row['refund_status'];
$save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$save_column['OPN_noticeType'] = 'refund';
$save_column['OPN_relatedId'] = $row['transaction_id'];
} else {
// 收款
$ssje = $this->account_model->get_ssje($row['settlement_total_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['transaction_id'];
$save_column['OPN_orderAmount'] = $row['settlement_total_fee'];
$save_column['OPN_payAmount'] = $row['settlement_total_fee'];
$save_column['OPN_resultCode'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_state'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_relatedId'] = '';
}
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_orderId'] = $row['out_trade_no'];
$save_column['OPN_rawOrderId'] = $row['out_trade_no'];
$save_column['OPN_invoiceId'] = $row['out_trade_no'];
$save_column['OPN_subject'] = $row['item_name'];
$save_column['OPN_currency'] = $row['currency_type'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_remark'] = $row['attach'];
$save_column['OPN_payerLogId'] = $row['openid'];
$save_column['OPN_fundSource'] = $target_account;
$save_column['OPN_rawContent'] = json_encode($row);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->note_model->insert_note($save_column) ;
// $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->note_model->new_report($warrant);
$warrant = NULL;
$insert_cnt++;
}
$settlement_record = null; // reset
$settle_cnt++;
$file_path_output .= "\r\n" . $file_path;
}
}
}

@ -151,7 +151,7 @@ function analysis_orderid($note_invoice_string) {
} elseif (isset($note_invoice_string[0]) && $note_invoice_string[0] !== "China Train Booking") {
$note_invoice_string = trim($note_invoice_string[0]);
}
return json_encode(array('orderid' => $note_invoice_string, 'ordertype' => 'A')); //APP订单不需要处理交易记录和通知
return json_encode(array('orderid' => $note_invoice_string, 'ordertype' => 'A', 'table' => 'biz')); //APP订单不需要处理交易记录和通知
}
//订单号例子 160420021_B--9608
@ -170,21 +170,27 @@ function analysis_orderid($note_invoice_string) {
//订单类型识别
$ordertype = 'N';
$table = null;
if (isset($note_invoice_string[1])) {
$ordertype_temp = trim($note_invoice_string[1]);
if (substr($ordertype_temp, 0, 2) == 'TP') {
$ordertype = 'TP';
$table = 'biz';
} elseif (substr($ordertype_temp, 0, 1) == 'T') {
$ordertype = 'T';
$table = 'tour';
} elseif (substr($ordertype_temp, 0, 1) == 'B') {
$ordertype = 'B';
$table = 'biz';
} elseif (substr($ordertype_temp, 0, 1) == 'A') {
$ordertype = 'A';
$table = 'biz';
}
}
// 2018.05.28 for Trippest, tourMaster的订单号是01开头
if (substr($note_invoice_string[0], 0, 2) == '01') {
$ordertype = 'TP';
$table = 'biz';
}
//手机订单、机票订单都没有加标示,在这里帮加上,暂时的,今后还是要在网前设置好
@ -192,6 +198,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 9 && substr($orderid_temp, 0, 2) == '16') {
$ordertype = 'B';
$table = 'biz';
}
}
@ -201,6 +208,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 8 && substr($orderid_temp, 0, 2) == '45') {
$ordertype = 'M';
$table = null;
}
}
//新的订单号14733661876255
@ -208,6 +216,7 @@ function analysis_orderid($note_invoice_string) {
$orderid_temp = $note_invoice_string[0];
if (strlen($orderid_temp) == 14 && substr($orderid_temp, 0, 2) == '14') {
$ordertype = 'M';
$table = null;
}
}
@ -228,7 +237,7 @@ function analysis_orderid($note_invoice_string) {
if (empty($pm_orderid) || strlen($pm_orderid) < 8) {
return false;
}
return json_encode(array('orderid' => $pm_orderid, 'ordertype' => $ordertype));
return json_encode(array('orderid' => $pm_orderid, 'ordertype' => $ordertype, 'table' => $table));
}
/**
* 输出xml字符

@ -0,0 +1,242 @@
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Ipaylinks_call
{
protected $ci;
public function __construct()
{
$this->ci = &get_instance();
$this->ci->load->helper('payment');
$this->ci->config->load('ipaylinks', true);
$this->ci->load->model('Online_payment_note_model', 'note_model');
$this->ci->load->model('Online_payment_account_model', 'account_model');
}
public function save_excel_old($excel_data)
{
foreach ($excel_data as $settle) {
$note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id']);
if (true === $note_exists) {
// update
} elseif (false === $note_exists) {
// insert
}
$save_column = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'ipaylinks');
if ($row['refund_id'] != '0') {
// 退款
$ssje = $this->account_model->get_ssje($row['settlement_refund_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['refund_id'];
$save_column['OPN_orderAmount'] = "-" . $row['settlement_refund_fee'];
$save_column['OPN_payAmount'] = "-" . $row['settlement_refund_fee'];
$save_column['OPN_resultCode'] = $row['refund_status'];
$save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$save_column['OPN_noticeType'] = 'refund';
$save_column['OPN_relatedId'] = $row['transaction_id'];
} else {
// 收款
$ssje = $this->account_model->get_ssje($row['settlement_total_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']);
$save_column['OPN_transactionId'] = $row['transaction_id'];
$save_column['OPN_orderAmount'] = $row['settlement_total_fee'];
$save_column['OPN_payAmount'] = $row['settlement_total_fee'];
$save_column['OPN_resultCode'] = $row['trade_state'];
$save_column['OPN_resultMsg'] = $row['trade_state'];
$save_column['OPN_entryAmountCNY'] = floatval($ssje);
$save_column['OPN_noticeType'] = 'pay';
$save_column['OPN_relatedId'] = '';
}
$save_column['OPN_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_orderId'] = $row['out_trade_no'];
$save_column['OPN_rawOrderId'] = $row['out_trade_no'];
$save_column['OPN_invoiceId'] = $row['out_trade_no'];
$save_column['OPN_subject'] = $row['item_name'];
$save_column['OPN_currency'] = $row['currency_type'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time']));
$save_column['OPN_remark'] = $row['attach'];
$save_column['OPN_payerLogId'] = $row['openid'];
$save_column['OPN_fundSource'] = $target_account;
$save_column['OPN_rawContent'] = json_encode($row);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->note_model->insert_note($save_column) ;
// $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->note_model->new_report($warrant);
$warrant = NULL;
$insert_cnt++;
}
}
private function read_excel_old($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->excel_title_old();
/**从第二行开始输出因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
$row_tmp = array();
/**从第A列开始输出*/
for($currentColumn= 'A';$currentColumn<= "N"; $currentColumn++){
/**ord()将字符转为十进制数*/
$val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
$col_mean = $col_titles[$currentColumn];
if($col_mean == 'data_type' && in_array($val, $this->no_store_deal_type()) )
{
break;
}
if ($col_mean == 'orderid' && strcasecmp('-', $val) === 0) {
break;
}
$row_tmp[$col_mean] = $val;
}
if (isset($row_tmp['settlement_amount'])) {
$tarr1[] = $row_tmp;
}
}
return $tarr1;
}
private function no_store_deal_type()
{
return array(
"归还保证金"
// ,"记账"
,"冻结"
,"解冻"
,"提现"
,"提现手续费"
);
}
private function excel_title_old()
{
return array(
"A" => "complete_date",
"B" => "transaction_id",
"C" => "orderid",
"D" => "data_type",
"E" => "currency",
"F" => "order_amount",
"G" => "settlement_rate",
"H" => "settlement_amount",
"I" => "service_fee",
"J" => "transaction_fee",
"K" => "mark_memo",
"L" => "entry_currency",
"M" => "entry_security",
"N" => "entry_basic"
);
}
private function read_excel_new($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->excel_title_new();
/**从第二行开始输出因为excel表中第一行为列名*/
for($currentRow = 2;$currentRow <= $allRow;$currentRow++){
$row_tmp = array();
/**从第A列开始输出*/
for($currentColumn= 'A';$currentColumn<= "AD"; $currentColumn++){
/**ord()将字符转为十进制数*/
$val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
$col_mean = $col_titles[$currentColumn];
$row_tmp[$col_mean] = trim($val)==='-' ? '' : $val;
}
$tarr1[] = $row_tmp;
}
return $tarr1;
}
private function excel_title_new()
{
return array(
"A" => "complete_date",
"B" => "transaction_id",
"C" => "related_id",
"D" => "orderid",
"E" => "site_id",
"F" => "local_channel",
"G" => "apply_pay_type",
"H" => "trade_region",
"I" => "card_issuers",
"J" => "card_bin_country",
"K" => "card_type",
"L" => "trade_type",
"M" => "trade_currency",
"N" => "trade_amount",
"O" => "settlement_currency",
"P" => "settlement_amount",
"Q" => "service_fee",
"R" => "trade_fee",
"S" => "chargeback_fee",
"T" => "security_amount",
"U" => "system_fee",
"V" => "refund_fee",
"W" => "3d_fee",
"X" => "extra_info1",
"Y" => "extra_info2",
"Z" => "extra_info3",
"AA" => "extra_info4",
"AB" => "extra_info5",
"AC" => "basic_account_entry_amount",
"AD" => "security_account_entry_amount"
);
}
}
/* End of file Ipaylinks_call.php */

@ -8,6 +8,15 @@ class Online_payment_note_model extends CI_Model {
$this->info = $this->load->database('INFO', TRUE);
}
public function if_note_exists($transaction_id)
{
if ($transaction_id === null) {
return null;
}
$ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? ORDER BY OPN_SN DESC ";
return $this->info->query($ret, array($transaction_id))->num_rows() > 0;
}
public function insert_note($column)
{
if ($column === null) {

Loading…
Cancel
Save