断电前提交

feature/pay
lyt 5 years ago
parent 47bb503cbf
commit b4030d80ea

@ -11,6 +11,7 @@ class PaymentService extends CI_Controller {
$this->config->load('ipaylinks', true); $this->config->load('ipaylinks', true);
$this->config->load('wxpay', true); $this->config->load('wxpay', true);
$this->config->load('paypal', 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_note_model', 'note_model');
$this->load->model('Online_payment_account_model', 'account_model'); $this->load->model('Online_payment_account_model', 'account_model');
} }
@ -603,16 +604,15 @@ class PaymentService extends CI_Controller {
return false; return false;
} }
public function ipalinks_settlement($year, $month, $day=null) public function ipalinks_settlement($year, $month, $day="01")
{ {
set_time_limit(0); set_time_limit(0);
ignore_user_abort(true); ignore_user_abort(true);
$this->load->library('ipaylinks_call');
$fun_version = $this->input->get_post('fun'); $fun_version = $this->input->get_post('fun');
$target_folder = "ipaylinks-" . $year; $target_folder = "ipaylinks-" . $year;
$target_file = $year . "-" . $month; $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; $statement_folder = FCPATH.'download_statement\settlement_files\\' . $target_folder;
if ( ! is_dir($statement_folder)) { if ( ! is_dir($statement_folder)) {
echo "read folder failed"; echo "read folder failed";
@ -638,89 +638,27 @@ class PaymentService extends CI_Controller {
continue; continue;
} }
if ($fun_version==='old') { 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 { } 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)) { if (empty($settlement_record)) {
continue; continue;
} }
foreach ($settlement_record as $settle) { if ($fun_version==='old') {
// $orderid_info = analysis_orderid(trim($settle['orderid'])); $update_cnt = $this->ipaylinks_call->save_excel_old($settlement_record);
// $orderid_info = json_decode($orderid_info); } else {
// if ( ! empty($orderid_info)) { // $update_cnt = $this->ipaylinks_call->read_excel_new($file_path);
// 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; $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;
} }
} }

@ -17,79 +17,65 @@ class Ipaylinks_call
public function save_excel_old($excel_data) public function save_excel_old($excel_data)
{ {
$settle_cnt = 0;
foreach ($excel_data as $settle) { 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 = array();
$save_column['OPN_accountMethod'] = $this->config->item('method_code', 'ipaylinks'); $save_column['OPN_accountMethod'] = $this->ci->config->item('method_code', 'ipaylinks');
if ($row['refund_id'] != '0') { 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']); // $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_resultCode'] = $row['refund_status'];
$save_column['OPN_orderAmount'] = "-" . $row['settlement_refund_fee']; // $save_column['OPN_resultMsg'] = $row['refund_status'];
$save_column['OPN_payAmount'] = "-" . $row['settlement_refund_fee']; // $save_column['OPN_entryAmountCNY'] = floatval("-" . $ssje);
$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_noticeType'] = 'refund';
$save_column['OPN_relatedId'] = $row['transaction_id']; // $save_column['OPN_relatedId'] = $row['transaction_id'];
} else { } 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']); // $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_resultCode'] = $settle['trade_state'];
$save_column['OPN_orderAmount'] = $row['settlement_total_fee']; // $save_column['OPN_resultMsg'] = $settle['trade_state'];
$save_column['OPN_payAmount'] = $row['settlement_total_fee']; // $save_column['OPN_entryAmountCNY'] = floatval($ssje);
$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_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_noticeSendStatus'] = 'unsend';
$save_column['OPN_transactionResult'] = 'completed'; $save_column['OPN_transactionResult'] = 'completed';
$save_column['OPN_orderId'] = $row['out_trade_no']; $save_column['OPN_orderId'] = $settle['orderid'];
$save_column['OPN_rawOrderId'] = $row['out_trade_no']; $save_column['OPN_rawOrderId'] = $settle['orderid'];
$save_column['OPN_invoiceId'] = $row['out_trade_no']; $save_column['OPN_invoiceId'] = $settle['orderid'];
$save_column['OPN_subject'] = $row['item_name']; // $save_column['OPN_subject'] = $settle['item_name'];
$save_column['OPN_currency'] = $row['currency_type']; $save_column['OPN_currency'] = $settle['currency'];
$save_column['OPN_acquiringTime'] = date('Y-m-d H:i:s',strtotime($row['complete_time'])); $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($row['complete_time'])); $save_column['OPN_completeTime'] = date('Y-m-d H:i:s',strtotime($settle['complete_date']));
$save_column['OPN_remark'] = $row['attach']; $save_column['OPN_remark'] = $settle['mark_memo'];
$save_column['OPN_payerLogId'] = $row['openid']; // $save_column['OPN_payerLogId'] = $settle['openid'];
$save_column['OPN_fundSource'] = $target_account; $save_column['OPN_fundSource'] = 'cht';
$save_column['OPN_rawContent'] = json_encode($row); $save_column['OPN_rawContent'] = json_encode($settle);
$save_column['OPN_noticeTime'] = date('Y-m-d H:i:s'); $save_column['OPN_noticeTime'] = date('Y-m-d H:i:s');
$this->note_model->insert_note($save_column) ; $note_exists = $this->ci->note_model->if_note_exists($settle['transaction_id'], $settle['orderid']);
// $warrant["PR_AccreditNo"] = trim($settle['pn_invoice']); if (true === $note_exists) {
// $warrant["PR_payType"] = 15018; // update
// $warrant["PR_entryCurrency"] = trim($settle['entry_currency']); $update_where = " OPN_transactionId='" . $settle['transaction_id'] . "' AND OPN_rawOrderId='" . $settle['orderid'] . "' ";
// $warrant["PR_entryAmount"] = bcadd(floatval($settle['entry_security']), floatval($settle['entry_basic'])); $this->ci->note_model->update_note($update_where, $save_column) ;
// $warrant["PR_COLI_SN"] = !empty($old_info) ? $old_info[0]->GAI_COLI_SN : NULL; $settle_cnt++;
// $warrant["PR_currency"] = trim($settle['currency']); } elseif (false === $note_exists) {
// $warrant["PR_amount"] = trim($settle['order_amount']); // insert
// $warrant["PR_orderType"] = $orderid_info ? $orderid_info->ordertype : NULL; $this->ci->note_model->insert_note($save_column) ;
// $warrant["PR_fee"] = bcadd(trim($settle['service_fee']), trim($settle['transaction_fee'])); $settle_cnt++;
// $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++;
} }
return $settle_cnt;
} }
private function read_excel_old($filePath) public function read_excel_old($filePath)
{ {
$tarr1=array(); $tarr1=array();
$this->load->library('PHPExcel'); $this->ci->load->library('PHPExcel');
$PHPExcel = new PHPExcel(); $PHPExcel = new PHPExcel();
/**默认用excel2007读取excel若格式不对则用之前的版本进行读取*/ /**默认用excel2007读取excel若格式不对则用之前的版本进行读取*/
$PHPReader = new PHPExcel_Reader_Excel2007(); $PHPReader = new PHPExcel_Reader_Excel2007();
@ -142,6 +128,8 @@ class Ipaylinks_call
,"解冻" ,"解冻"
,"提现" ,"提现"
,"提现手续费" ,"提现手续费"
,"单笔处理费"
,"退款手续费"
); );
} }
private function excel_title_old() 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(); $tarr1=array();
$this->load->library('PHPExcel'); $this->load->library('PHPExcel');

@ -8,12 +8,13 @@ class Online_payment_note_model extends CI_Model {
$this->info = $this->load->database('INFO', TRUE); $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) { if ($transaction_id === null) {
return 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; return $this->info->query($ret, array($transaction_id))->num_rows() > 0;
} }

Loading…
Cancel
Save