From 47bb503cbfdd435177153fe3680e0fcd7cb078bf Mon Sep 17 00:00:00 2001 From: lyt Date: Mon, 20 Jan 2020 16:00:40 +0800 Subject: [PATCH 1/5] =?UTF-8?q?todo:=20iPaylinks=E8=B4=A6=E5=8D=95?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BD=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webht/third_party/pay/config/iPayLinks.php | 1 + .../pay/controllers/PaymentService.php | 121 +++++++++ .../pay/helpers/payment_helper.php | 13 +- .../pay/libraries/ipaylinks_call.php | 242 ++++++++++++++++++ .../pay/models/Online_payment_note_model.php | 9 + 5 files changed, 384 insertions(+), 2 deletions(-) create mode 100644 webht/third_party/pay/libraries/ipaylinks_call.php diff --git a/webht/third_party/pay/config/iPayLinks.php b/webht/third_party/pay/config/iPayLinks.php index 7de2b398..4d45f9ba 100644 --- a/webht/third_party/pay/config/iPayLinks.php +++ b/webht/third_party/pay/config/iPayLinks.php @@ -1,4 +1,5 @@ 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; + } + } + } diff --git a/webht/third_party/pay/helpers/payment_helper.php b/webht/third_party/pay/helpers/payment_helper.php index 3d7ce814..181c0118 100644 --- a/webht/third_party/pay/helpers/payment_helper.php +++ b/webht/third_party/pay/helpers/payment_helper.php @@ -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字符 diff --git a/webht/third_party/pay/libraries/ipaylinks_call.php b/webht/third_party/pay/libraries/ipaylinks_call.php new file mode 100644 index 00000000..201e5e85 --- /dev/null +++ b/webht/third_party/pay/libraries/ipaylinks_call.php @@ -0,0 +1,242 @@ +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 */ diff --git a/webht/third_party/pay/models/Online_payment_note_model.php b/webht/third_party/pay/models/Online_payment_note_model.php index c17f0cb4..36af1388 100644 --- a/webht/third_party/pay/models/Online_payment_note_model.php +++ b/webht/third_party/pay/models/Online_payment_note_model.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) { From b4030d80ea192b0afb64bed121f39e8da1586e36 Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 31 Jan 2020 13:46:31 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=96=AD=E7=94=B5=E5=89=8D=E6=8F=90?= =?UTF-8?q?=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pay/controllers/PaymentService.php | 94 +++------------- .../pay/libraries/ipaylinks_call.php | 106 ++++++++---------- .../pay/models/Online_payment_note_model.php | 5 +- 3 files changed, 66 insertions(+), 139 deletions(-) diff --git a/webht/third_party/pay/controllers/PaymentService.php b/webht/third_party/pay/controllers/PaymentService.php index 8aa0623b..d70daaba 100644 --- a/webht/third_party/pay/controllers/PaymentService.php +++ b/webht/third_party/pay/controllers/PaymentService.php @@ -11,6 +11,7 @@ class PaymentService extends CI_Controller { $this->config->load('ipaylinks', true); $this->config->load('wxpay', true); $this->config->load('paypal', true); + $this->load->library('ipaylinks_call'); $this->load->model('Online_payment_note_model', 'note_model'); $this->load->model('Online_payment_account_model', 'account_model'); } @@ -603,16 +604,15 @@ class PaymentService extends CI_Controller { return false; } - public function ipalinks_settlement($year, $month, $day=null) + public function ipalinks_settlement($year, $month, $day="01") { 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); + // $target_file .= ($day===null) ? null : ("-" . $day); $statement_folder = FCPATH.'download_statement\settlement_files\\' . $target_folder; if ( ! is_dir($statement_folder)) { echo "read folder failed"; @@ -638,89 +638,27 @@ class PaymentService extends CI_Controller { continue; } if ($fun_version==='old') { - $settlement_record = $this->ipalinks_call->read_excel_old($file_path); + $settlement_record = $this->ipaylinks_call->read_excel_old($file_path); } else { - $settlement_record = $this->ipalinks_call->read_excel_new($file_path); + $settlement_record = $this->ipaylinks_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++; + if ($fun_version==='old') { + $update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record); + } else { + // $update_cnt = $this->ipaylinks_call->read_excel_new($file_path); } - $settlement_record = null; // reset - $settle_cnt++; $file_path_output .= "\r\n" . $file_path; + if ($k > 0) { + break; + } } + $result = "Store $update_cnt records;" . $file_path_output; + log_message('error', $result); + echo $result; + return; } } diff --git a/webht/third_party/pay/libraries/ipaylinks_call.php b/webht/third_party/pay/libraries/ipaylinks_call.php index 201e5e85..a6c98c89 100644 --- a/webht/third_party/pay/libraries/ipaylinks_call.php +++ b/webht/third_party/pay/libraries/ipaylinks_call.php @@ -17,79 +17,65 @@ class Ipaylinks_call public function save_excel_old($excel_data) { + $settle_cnt = 0; 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') { + $save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks'); + if ($settle['data_type'] == '已清算退款' || $settle['data_type'] == '未清算退款') { // 退款 - $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); + // $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_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 { + // $save_column['OPN_relatedId'] = $row['transaction_id']; + } elseif ($settle['data_type'] == '清算') { // 收款 - $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); + // $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_resultCode'] = $settle['trade_state']; + // $save_column['OPN_resultMsg'] = $settle['trade_state']; + // $save_column['OPN_entryAmountCNY'] = floatval($ssje); $save_column['OPN_noticeType'] = 'pay'; - $save_column['OPN_relatedId'] = ''; + // $save_column['OPN_relatedId'] = ''; + } else { + continue; } + $save_column['OPN_transactionId'] = $settle['transaction_id']; + $save_column['OPN_orderAmount'] = $settle['order_amount']; + $save_column['OPN_payAmount'] = $settle['order_amount']; $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_orderId'] = $settle['orderid']; + $save_column['OPN_rawOrderId'] = $settle['orderid']; + $save_column['OPN_invoiceId'] = $settle['orderid']; + // $save_column['OPN_subject'] = $settle['item_name']; + $save_column['OPN_currency'] = $settle['currency']; + $save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); + $save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); + $save_column['OPN_remark'] = $settle['mark_memo']; + // $save_column['OPN_payerLogId'] = $settle['openid']; + $save_column['OPN_fundSource'] = 'cht'; + $save_column['OPN_rawContent'] = json_encode($settle); $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++; + $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); + if (true === $note_exists) { + // update + $update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' "; + $this->ci->note_model->update_note($update_where, $save_column) ; + $settle_cnt++; + } elseif (false === $note_exists) { + // insert + $this->ci->note_model->insert_note($save_column) ; + $settle_cnt++; + } } + return $settle_cnt; } - private function read_excel_old($filePath) + public function read_excel_old($filePath) { $tarr1=array(); - $this->load->library('PHPExcel'); + $this->ci->load->library('PHPExcel'); $PHPExcel = new PHPExcel(); /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ $PHPReader = new PHPExcel_Reader_Excel2007(); @@ -142,6 +128,8 @@ class Ipaylinks_call ,"解冻" ,"提现" ,"提现手续费" + ,"单笔处理费" + ,"退款手续费" ); } private function excel_title_old() @@ -164,7 +152,7 @@ class Ipaylinks_call ); } - private function read_excel_new($filePath) + public function read_excel_new($filePath) { $tarr1=array(); $this->load->library('PHPExcel'); diff --git a/webht/third_party/pay/models/Online_payment_note_model.php b/webht/third_party/pay/models/Online_payment_note_model.php index 36af1388..d3528c29 100644 --- a/webht/third_party/pay/models/Online_payment_note_model.php +++ b/webht/third_party/pay/models/Online_payment_note_model.php @@ -8,12 +8,13 @@ class Online_payment_note_model extends CI_Model { $this->info = $this->load->database('INFO', TRUE); } - public function if_note_exists($transaction_id) + public function if_note_exists($transaction_id, $raw_id=null) { if ($transaction_id === null) { return null; } - $ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? ORDER BY OPN_SN DESC "; + $order_sql = $raw_id===null ? " " : " AND OPN_rawOrderId='" . $raw_id . "'"; + $ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_transactionId=? $order_sql ORDER BY OPN_SN DESC "; return $this->info->query($ret, array($transaction_id))->num_rows() > 0; } From a602a2a3a454940162744efc1dca74967593d2e2 Mon Sep 17 00:00:00 2001 From: lyt Date: Thu, 12 Mar 2020 09:19:14 +0800 Subject: [PATCH 3/5] =?UTF-8?q?feat:=20=E8=A7=A3=E6=9E=90=E5=BD=95?= =?UTF-8?q?=E5=85=A5iPaylinks=E5=AF=B9=E8=B4=A6=E5=8D=95=E5=88=B0OPN;=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=E5=88=97=E8=A1=A8=E6=94=AF=E6=8C=81=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webht/config/database.php | 2 +- .../pay/controllers/PaymentService.php | 62 +++---- .../pay/libraries/ipaylinks_call.php | 156 +++++++++++++++--- .../models/Online_payment_account_model.php | 42 ++++- .../pay/models/Online_payment_note_model.php | 76 +++++++-- webht/third_party/pay/views/payment_list.php | 17 +- 6 files changed, 272 insertions(+), 83 deletions(-) diff --git a/webht/config/database.php b/webht/config/database.php index 3a7d8aae..564717fb 100644 --- a/webht/config/database.php +++ b/webht/config/database.php @@ -45,4 +45,4 @@ require 'C:/database_conn.php'; /* End of file database.php */ -/* Location: ./application/config/database.php */ \ No newline at end of file +/* Location: ./application/config/database.php */ diff --git a/webht/third_party/pay/controllers/PaymentService.php b/webht/third_party/pay/controllers/PaymentService.php index d70daaba..c1d31f05 100644 --- a/webht/third_party/pay/controllers/PaymentService.php +++ b/webht/third_party/pay/controllers/PaymentService.php @@ -16,23 +16,39 @@ class PaymentService extends CI_Controller { $this->load->model('Online_payment_account_model', 'account_model'); } + private $code_brandname = array( + "15002" => "PayPal", + "15010" => "PayPal", + "15015" => "Alipay", + "15016" => "WeChat", + "15018" => "Credit Card", + ); + public function index() { } - public function note_list() + public function note_list($method=null) { $this->permission->is_admin(true); $data = array(); + $data['method_code'] = ''; // $data["paytext"] = $this->payment_status(); - $data["method_name"] = $this->input->get_post("method_name"); + if (isset($this->code_brandname[$method])) { + $data['method_code'] = $method; + $data["method_name"] = $this->code_brandname[$method]; + } $data["keywords"] = $this->input->get_post("keywords"); $data["date"] = $this->input->get_post("date"); empty($data['date']) ? $data['date'] = date('Y-m-d') : false; if (!empty($data['keywords'])) { $data['notelist'] = $this->note_model->search_key($data['keywords']); } else { - $data['notelist'] = $this->note_model->search_date($data['date']); + $search_date = $this->note_model->search_date($data['date'], $method); + $unsend = $this->note_model->unsend_note(false, $method); + $sendfail = $this->note_model->sendfail_note(false, $method); + $closed = $this->note_model->closed_note($data['date'], 300, $method); + $data['notelist'] = array_merge(array_merge($unsend, $sendfail), array_merge($search_date, $closed)); } array_walk($data["notelist"], 'PaymentService::set_brandname'); @@ -51,7 +67,7 @@ class PaymentService extends CI_Controller { $this->permission->is_admin(true); $data = array(); $data['date'] = date('Y-m-d'); - $data['notelist'] = $this->note_model->failnote(100); + $data['notelist'] = $this->note_model->sendfail_note(false); array_walk($data["notelist"], 'PaymentService::set_brandname'); $this->load->view("payment_list",$data); return; @@ -60,22 +76,8 @@ class PaymentService extends CI_Controller { public function set_brandname(&$ele) { $ele->brand_name = "none"; - switch ($ele->OPN_accountMethod) { - case '15016': - $ele->brand_name = "WeChat"; - break; - case '15010': - case '15002': - $ele->brand_name = "PayPal"; - break; - case '15018': - $ele->brand_name = "Credit Card"; - break; - case '15015': - $ele->brand_name = "Alipay"; - break; - default: - break; + if ($this->code_brandname[$ele->OPN_accountMethod]) { + $ele->brand_name = $this->code_brandname[$ele->OPN_accountMethod]; } } @@ -623,8 +625,6 @@ class PaymentService extends CI_Controller { 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"))) { @@ -637,18 +637,18 @@ class PaymentService extends CI_Controller { if ( ! file_exists($file_path)) { continue; } - if ($fun_version==='old') { + if ($target_file==='2019-09') { // 2019.09.10 切换清算账单, 此处特殊处理 + $settlement_record = $this->ipaylinks_call->read_excel_old($file_path); + $update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record); + $settlement_record2 = $this->ipaylinks_call->read_excel_new($file_path,1); + $update_cnt2 = $this->ipaylinks_call->save_excel_new($settlement_record2); + $update_cnt += $update_cnt2; + } else if ($fun_version==='old') { $settlement_record = $this->ipaylinks_call->read_excel_old($file_path); - } else { - $settlement_record = $this->ipaylinks_call->read_excel_new($file_path); - } - if (empty($settlement_record)) { - continue; - } - if ($fun_version==='old') { $update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record); } else { - // $update_cnt = $this->ipaylinks_call->read_excel_new($file_path); + $settlement_record = $this->ipaylinks_call->read_excel_new($file_path); + $update_cnt = $this->ipaylinks_call->save_excel_new($settlement_record); } $file_path_output .= "\r\n" . $file_path; if ($k > 0) { diff --git a/webht/third_party/pay/libraries/ipaylinks_call.php b/webht/third_party/pay/libraries/ipaylinks_call.php index a6c98c89..3382cf4f 100644 --- a/webht/third_party/pay/libraries/ipaylinks_call.php +++ b/webht/third_party/pay/libraries/ipaylinks_call.php @@ -18,9 +18,17 @@ class Ipaylinks_call public function save_excel_old($excel_data) { $settle_cnt = 0; - foreach ($excel_data as $settle) { + foreach ($excel_data as $key => $settle) { + // test: + // $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); + // if (true === $note_exists) { + // continue; + // } $save_column = array(); $save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks'); + $save_column['OPN_invoiceId'] = $settle['orderid']; + $save_column['OPN_orderId'] = $settle['orderid']; + $save_column['OPN_orderAmount'] = $settle['order_amount']; if ($settle['data_type'] == '已清算退款' || $settle['data_type'] == '未清算退款') { // 退款 // $ssje = $this->account_model->get_ssje($row['settlement_refund_fee'], str_replace("CNY", "RMB", strtoupper($row['currency_type'])), $save_column['OPN_accountMethod']); @@ -28,38 +36,68 @@ class Ipaylinks_call // $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']; + $save_column['OPN_relatedId'] = $settle['transaction_id']; + $save_column['OPN_transactionId'] = ''; + if (true === $this->ci->note_model->if_refund_exists($settle['orderid'])) { + continue; + } + $query_from_ipalinkslog = $this->ci->note_model->query_ipalinkslog_memo($settle['orderid']); + if ( ! empty($query_from_ipalinkslog)) { + $save_column['OPN_transactionId'] = $query_from_ipalinkslog->IPL_dealId; + $save_column['OPN_invoiceId'] = $query_from_ipalinkslog->IPL_orderId; + $save_column['OPN_orderId'] = $query_from_ipalinkslog->IPL_orderId; + } + $related = $this->ci->note_model->query_related($save_column['OPN_relatedId']); + if ( ! empty($related)) { + $save_column['OPN_orderId'] = $related[0]->OPN_orderId; + $save_column['OPN_accountType'] = $related[0]->OPN_accountType; + } } elseif ($settle['data_type'] == '清算') { // 收款 - // $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_resultCode'] = $settle['trade_state']; - // $save_column['OPN_resultMsg'] = $settle['trade_state']; - // $save_column['OPN_entryAmountCNY'] = floatval($ssje); $save_column['OPN_noticeType'] = 'pay'; - // $save_column['OPN_relatedId'] = ''; + $save_column['OPN_transactionId'] = $settle['transaction_id']; + + $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); + if (true === $note_exists) { + continue; // test: + } } else { continue; } - $save_column['OPN_transactionId'] = $settle['transaction_id']; - $save_column['OPN_orderAmount'] = $settle['order_amount']; + if ($save_column['OPN_transactionId']==='') { + continue; + } + // test: 月账单太长 + if ($settle_cnt > 999) { + break; + } + $order_info = $this->ci->account_model + ->get_gai( + $save_column['OPN_transactionId'], + $save_column['OPN_orderId'], + $save_column['OPN_orderAmount'], + $save_column['OPN_accountMethod'] + ); + if ($order_info['data'] !== null) { + $save_column['OPN_orderId'] = $order_info['data']->orderId; + $save_column['OPN_accountType'] = $order_info['type']; + $save_column['OPN_accountStatus'] = 'recorded'; + } $save_column['OPN_payAmount'] = $settle['order_amount']; - $save_column['OPN_noticeSendStatus'] = 'unsend'; + $save_column['OPN_noticeSendStatus'] = 'closed'; $save_column['OPN_transactionResult'] = 'completed'; - $save_column['OPN_orderId'] = $settle['orderid']; $save_column['OPN_rawOrderId'] = $settle['orderid']; - $save_column['OPN_invoiceId'] = $settle['orderid']; - // $save_column['OPN_subject'] = $settle['item_name']; $save_column['OPN_currency'] = $settle['currency']; $save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); $save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); $save_column['OPN_remark'] = $settle['mark_memo']; - // $save_column['OPN_payerLogId'] = $settle['openid']; $save_column['OPN_fundSource'] = 'cht'; - $save_column['OPN_rawContent'] = json_encode($settle); + $save_column['OPN_rawContent'] = json_encode($settle, JSON_UNESCAPED_UNICODE); $save_column['OPN_noticeTime'] = date('Y-m-d H:i:s'); $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); if (true === $note_exists) { + continue; // test: // update $update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' "; $this->ci->note_model->update_note($update_where, $save_column) ; @@ -72,7 +110,7 @@ class Ipaylinks_call } return $settle_cnt; } - public function read_excel_old($filePath) + public function read_excel_old($filePath, $sheetIndex=0) { $tarr1=array(); $this->ci->load->library('PHPExcel'); @@ -88,13 +126,15 @@ class Ipaylinks_call } $PHPExcel = $PHPReader->load($filePath); /**读取excel文件中的第一个工作表*/ - $currentSheet = $PHPExcel->getSheet(0); + $currentSheet = $PHPExcel->getSheet($sheetIndex); /**取得最大的列号*/ $allColumn = $currentSheet->getHighestColumn(); /**取得一共有多少行*/ $allRow = $currentSheet->getHighestRow(); + log_message('error','all row ' . $allRow); + $realRow = 0; $col_titles = $this->excel_title_old(); /**从第二行开始输出,因为excel表中第一行为列名*/ for($currentRow = 2;$currentRow <= $allRow;$currentRow++){ @@ -115,8 +155,10 @@ class Ipaylinks_call } if (isset($row_tmp['settlement_amount'])) { $tarr1[] = $row_tmp; + $realRow++; } } + log_message('error','real row ' . $realRow); return $tarr1; } private function no_store_deal_type() @@ -152,10 +194,67 @@ class Ipaylinks_call ); } - public function read_excel_new($filePath) + public function save_excel_new($excel_data) + { + $settle_cnt = 0; + foreach ($excel_data as $settle) { + $save_column = array(); + $save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks'); + $save_column['OPN_noticeType'] = trim($settle['trade_type']) === '消费' ? 'pay' : 'refund'; + $save_column['OPN_fundSource'] = trim($settle['site_id']) === 'www.chinahighlights.com' ? 'cht' : 'app'; + + $save_column['OPN_transactionId'] = $settle['transaction_id']; + $save_column['OPN_relatedId'] = str_ireplace("-", '', $settle['related_id']); + + $save_column['OPN_orderAmount'] = $settle['trade_amount']; + $save_column['OPN_orderId'] = $settle['orderid']; + $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); + if (true === $note_exists) { + continue; // test: + } + $order_info = $this->ci->account_model + ->get_gai( + $save_column['OPN_transactionId'], + $save_column['OPN_orderId'], + $save_column['OPN_orderAmount'], + $save_column['OPN_accountMethod'] + ); + if ($order_info['data'] !== null) { + $save_column['OPN_orderId'] = $order_info['data']->orderId; + $save_column['OPN_accountType'] = $order_info['type']; + $save_column['OPN_accountStatus'] = 'recorded'; + } + $save_column['OPN_payAmount'] = $settle['trade_amount']; + $save_column['OPN_noticeSendStatus'] = 'closed'; + $save_column['OPN_transactionResult'] = 'completed'; + $save_column['OPN_rawOrderId'] = $settle['orderid']; + $save_column['OPN_invoiceId'] = $settle['orderid']; + $save_column['OPN_currency'] = $settle['trade_currency']; + $save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); + $save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date'])); + $save_column['OPN_remark'] = str_ireplace("-", '', $settle['apply_pay_type']) . "_" . str_ireplace("-", '', $settle['trade_region']) . "_" . str_ireplace("-", '', $settle['card_issuers']) . "_" . str_ireplace("-", '', $settle['card_bin_country']) . "_" . str_ireplace("-", '', $settle['card_type']); + $save_column['OPN_rawContent'] = json_encode($settle, JSON_UNESCAPED_UNICODE); + $save_column['OPN_noticeTime'] = date('Y-m-d H:i:s'); + + $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']); + if (true === $note_exists) { + // update + $update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' "; + $this->ci->note_model->update_note($update_where, $save_column) ; + $settle_cnt++; + } elseif (false === $note_exists) { + // insert + $this->ci->note_model->insert_note($save_column) ; + $settle_cnt++; + } + } + return $settle_cnt; + } + + public function read_excel_new($filePath, $sheetIndex=0) { $tarr1=array(); - $this->load->library('PHPExcel'); + $this->ci->load->library('PHPExcel'); $PHPExcel = new PHPExcel(); /**默认用excel2007读取excel,若格式不对,则用之前的版本进行读取*/ $PHPReader = new PHPExcel_Reader_Excel2007(); @@ -168,23 +267,34 @@ class Ipaylinks_call } $PHPExcel = $PHPReader->load($filePath); /**读取excel文件中的第一个工作表*/ - $currentSheet = $PHPExcel->getSheet(0); + $currentSheet = $PHPExcel->getSheet($sheetIndex); /**取得最大的列号*/ $allColumn = $currentSheet->getHighestColumn(); - /**取得一共有多少行*/ $allRow = $currentSheet->getHighestRow(); + + log_message('error','all row ' . $allRow); + $col_titles = $this->excel_title_new(); /**从第二行开始输出,因为excel表中第一行为列名*/ for($currentRow = 2;$currentRow <= $allRow;$currentRow++){ $row_tmp = array(); /**从第A列开始输出*/ - for($currentColumn= 'A';$currentColumn<= "AD"; $currentColumn++){ + $columnNum = 0; + // for($currentColumn= 'A';$currentColumn<= "AD"; $currentColumn++){ + // 列标题Z之后的不能直接用逻辑运算 + for($currentColumn= 'A';str_pad($currentColumn, 2, "0", STR_PAD_LEFT)<= $allColumn; $currentColumn++){ /**ord()将字符转为十进制数*/ - $val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue()); + // $val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue()); + // 列标题Z之后不能直接用ord计算ASCII码,因ord仅返回第一个字符的结果导致列AA的值读取到列A + $val = trim($currentSheet->getCellByColumnAndRow($columnNum,$currentRow)->getValue()); + if ( ! isset($col_titles[$currentColumn])) { + continue; + } $col_mean = $col_titles[$currentColumn]; $row_tmp[$col_mean] = trim($val)==='-' ? '' : $val; + $columnNum++; } $tarr1[] = $row_tmp; } diff --git a/webht/third_party/pay/models/Online_payment_account_model.php b/webht/third_party/pay/models/Online_payment_account_model.php index 272f441a..5db785f8 100644 --- a/webht/third_party/pay/models/Online_payment_account_model.php +++ b/webht/third_party/pay/models/Online_payment_account_model.php @@ -164,24 +164,50 @@ class Online_payment_account_model extends CI_Model { return $query; } + public function get_gai($t_id, $order=null, $amount=null, $type=null) + { + $ret = array("type"=> null, "data"=>null); + $result_t = $this->get_money_t($t_id); + $result_b = $this->get_money_b($t_id, $order, $amount, $type); + if ( ! empty($result_t)) { + $ret['type'] = 'T'; + $ret['data'] = $result_t[0]; + } else if ( ! empty($result_b)) { + $ret['type'] = 'B'; + $ret['data'] = $result_b[0]; + } + return $ret; + } + //根据交易号获取收款记录(传统订单) public function get_money_t($pn_invoice) { - $sql = "SELECT GroupAccountInfo.* - from GroupAccountInfo - where DeleteFlag=0 and GAI_AccreditNo=? + $sql = "SELECT COLI_ID orderId, g.* + from GroupAccountInfo g + inner join Tourmanager.dbo.ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN + where g.DeleteFlag=0 and g.GAI_AccreditNo=? "; $query = $this->HT->query($sql, array($pn_invoice)); $result = $query->result(); return $result; } //根据交易号获取收款记录(商务订单) - public function get_money_b($pn_invoice) { - $sql = "SELECT BIZ_GroupAccountInfo.* - from BIZ_GroupAccountInfo - where DeleteFlag=0 and GAI_AccreditNo=? + public function get_money_b($t_id, $raw_order=null, $amount=null, $payment_type=null) { + $sql = "SELECT COLI_ID orderId, g.* + from BIZ_GroupAccountInfo g + inner join Tourmanager.dbo.BIZ_ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN + where g.DeleteFlag=0 and g.GAI_AccreditNo=? "; - $query = $this->HT->query($sql, array($pn_invoice)); + $query = $this->HT->query($sql, array($t_id)); $result = $query->result(); + if (empty($result)) { + $raw_order_sql = "SELECT COLI_ID orderId, g.* + from BIZ_GroupAccountInfo g + inner join Tourmanager.dbo.BIZ_ConfirmLineInfo on g.GAI_COLI_SN=COLI_SN + where g.DeleteFlag=0 and COLI_ID=? and g.GAI_SQJE=? and g.GAI_Type=? + "; + $query = $this->HT->query($raw_order_sql, array($raw_order, $amount, $payment_type)); + $result = $query->result(); + } return $result; } /** 删除收款记录 */ diff --git a/webht/third_party/pay/models/Online_payment_note_model.php b/webht/third_party/pay/models/Online_payment_note_model.php index d3528c29..6ccbed7f 100644 --- a/webht/third_party/pay/models/Online_payment_note_model.php +++ b/webht/third_party/pay/models/Online_payment_note_model.php @@ -18,6 +18,15 @@ class Online_payment_note_model extends CI_Model { return $this->info->query($ret, array($transaction_id))->num_rows() > 0; } + public function if_refund_exists($refund_id) + { + if ($refund_id === null) { + return null; + } + $ret = "SELECT TOP 1 * FROM OnlinePaymentNote WHERE OPN_rawOrderId=? ORDER BY OPN_SN DESC "; + return $this->info->query($ret, array($refund_id))->num_rows() > 0; + } + public function insert_note($column) { if ($column === null) { @@ -50,18 +59,32 @@ class Online_payment_note_model extends CI_Model { return $this->update_note($where, $column); } - public function unsend_note($num=2) + public function unsend_note($num=2, $method=null) { $this->init_query(); $this->topnum = $num; - $this->send = " AND (OPN_noticeSendStatus='unsend' OR OPN_noticeSendStatus='' OR OPN_noticeSendStatus IS NULL) "; + // $this->send = " AND (OPN_noticeSendStatus='unsend' OR OPN_noticeSendStatus='' OR OPN_noticeSendStatus IS NULL) "; + $this->search = $method===null ? "" : " AND OPN_accountMethod=$method "; + + $this->send = " AND ISNULL(OPN_noticeSendStatus,'') in ('', 'unsend') "; return $this->query_note(); } - public function sendfail_note($num=2) + public function closed_note($date, $num=2, $method=null) { $this->init_query(); $this->topnum = $num; + $this->send = " AND (OPN_noticeSendStatus) = 'closed' "; + $this->search = $method===null ? "" : " AND OPN_accountMethod=$method "; + $this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' "; + return $this->query_note(); + } + + public function sendfail_note($num=2, $method=null) + { + $this->init_query(); + $this->topnum = $num; + $this->search = $method===null ? "" : " AND OPN_accountMethod=$method "; $this->send = " AND OPN_noticeSendStatus='sendfail' "; return $this->query_note(); } @@ -98,6 +121,9 @@ class Online_payment_note_model extends CI_Model { $this->search ? $sql.=$this->search : false; $this->transactionId ? $sql.=$this->transactionId : false; $this->orderby ? $sql.=$this->orderby : false; + + // log_message('error', PHP_EOL . $sql); + $query = $this->info->query($sql); return $query->result(); } @@ -125,17 +151,12 @@ class Online_payment_note_model extends CI_Model { return $this->query_note(); } - public function search_date($date) + public function search_date($date, $method=null) { $this->init_query(); - $this->search = " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' "; - return $this->query_note(); - } - - public function failnote($topnum = 2) { - $this->init_query(); - $this->topnum = $topnum; - $this->send = " AND OPN_noticeSendStatus='sendfail' "; + $this->search = $method===null ? "" : " AND OPN_accountMethod=$method "; + $this->search .= " AND OPN_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' "; + $this->send = " AND isnull(OPN_noticeSendStatus,'') NOT IN ('', 'sendfail', 'unsend', 'closed' )"; return $this->query_note(); } @@ -148,13 +169,36 @@ class Online_payment_note_model extends CI_Model { { $search_sql = $sn===0 ? "" : " and TEL_SN=$sn "; $sql = "SELECT TOP 10 * - FROM [InfoManager].[dbo].[Transaction_Export_Log] - WHERE 1=1 - $search_sql - order by TEL_SN desc"; + FROM [InfoManager].[dbo].[Transaction_Export_Log] + WHERE 1=1 + $search_sql + order by TEL_SN desc"; return $this->info->query($sql)->result(); } + public function query_ipalinkslog_memo($memo) + { + $sql = "SELECT * + from IPayLinksLog + where CHARINDEX(?,IPL_memo)>0"; + return $this->info->query($sql, array($memo))->row(); + } + + public function query_ipalinkslog_dealid($id) + { + $sql = "SELECT * + from IPayLinksLog + where IPL_dealId=?"; + return $this->info->query($sql, array($id))->row(); + } + + public function query_related($related_id) + { + $this->init_query(); + $this->search = " AND OPN_transactionId='$related_id' and OPN_accountType is not null "; + return $this->query_note(); + } + } diff --git a/webht/third_party/pay/views/payment_list.php b/webht/third_party/pay/views/payment_list.php index 7116d96b..c7ad4bb9 100644 --- a/webht/third_party/pay/views/payment_list.php +++ b/webht/third_party/pay/views/payment_list.php @@ -125,13 +125,22 @@

Payment List

- 微信 + ALL   - PayPal» + class="text-muted" + href="/webht.php/apps/pay/paymentservice/note_list/15016">微信»   - 信用卡» + + class="text-muted" + href="/webht.php/apps/pay/paymentservice/note_list/15002">PayPal»   - 支付宝» + class="text-muted" + href="/webht.php/apps/pay/paymentservice/note_list/15018">信用卡» + +   + class="text-muted" + href="/webht.php/apps/pay/paymentservice/note_list/15015">支付宝» +