From b4030d80ea192b0afb64bed121f39e8da1586e36 Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 31 Jan 2020 13:46:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=AD=E7=94=B5=E5=89=8D=E6=8F=90=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; }