paypal 对账单文件保存

feature/trippest
lyt 7 years ago
parent 3d293d802a
commit 523b773bba

1
.gitignore vendored

@ -5,3 +5,4 @@
/kcfinder/cache/*
*/cache/*
*/statement_files/*
*/paypal_activities/*

@ -15,9 +15,10 @@ $config['currency'] = "USD";
$config['token_url'] = "https://api.paypal.com/v1/oauth2/token";
$config['web_profiles_url'] = "https://api.paypal.com/v1/payment-experience/web-profiles/";
$config['webhooks_url'] = "https://api.paypal.com/v1/notifications/webhooks";
$config['payment_url'] = "https://api.paypal.com/v1/payments/payment";
$config['sale_url'] = "https://api.paypal.com/v1/payments/sale";
$config['activities_url'] = "https://api.paypal.com/v1/activities/activities";
$config['payment_url'] = "https://api.paypal.com/v1/payments/payment/";
$config['sale_url'] = "https://api.paypal.com/v1/payments/sale/";
// $config['activities_url'] = "https://api.paypal.com/v1/activities/activities";
// $config['reporting_url'] = "https://api.paypal.com/v1/reporting/transactions";
$config['return_url'] = "https://www.chinahighlights.com";
$config['cancel_url'] = "https://www.chinahighlights.com";

@ -596,6 +596,7 @@ class IPayLinksService extends CI_Controller
$resp_arr = $resp;
} else {
$resp_arr = $this->input->post();
log_message('error','iPayLinks asyn notify: ' . $this->input->post("orderId"));
}
$asyns_resp = $this->verify_sign($resp_arr);
// 未得到结果

@ -271,7 +271,7 @@ class Report extends CI_Controller
/**ord()将字符转为十进制数*/
$val = trim($currentSheet->getCellByColumnAndRow(ord($currentColumn) - 65,$currentRow)->getValue());
$col_mean = $col_titles[$currentColumn];
if($col_mean == 'data_type' && in_array($val, $this->noStore_dealType()) ) // strcasecmp('清算', $val) !== 0
if($col_mean == 'data_type' && in_array($val, $this->ipaylinks_noStore_dealType()) ) // strcasecmp('清算', $val) !== 0
{
break;
}
@ -305,7 +305,7 @@ class Report extends CI_Controller
"N" => "entry_basic"
);
}
public function noStore_dealType()
public function ipaylinks_noStore_dealType()
{
return array(
"归还保证金"
@ -317,6 +317,112 @@ class Report extends CI_Controller
);
}
public function paypal_excel()
{
// $this->load->model('IPayLinks_model');
set_time_limit(0);
// 解析excel
$target_folder = $this->input->get_post("f");
$files = json_decode($this->input->get_post("fjson"));
log_message('error','paypal excel POST: ' . $target_folder . $this->input->get_post("fjson"));
$statement_folder = FCPATH.'download_statement\paypal_activities\\' . $target_folder;
if ( ! is_dir($statement_folder)) {
return;
}
$files = $files ? $files : array_values(array_diff(scandir($statement_folder), array('.', '..')));
if (empty($files)) {
echo "none excel.";
return;
}
$settle_cnt = 0;
$update_cnt = 0;
$file_path_output = "";
bcscale(4);
foreach ($files as $k => $fe) {
if ( ! in_array(strrchr($fe, '.'), array(".xlsx", ".xls"))) {
continue;
}
$file_path = $statement_folder . '\\' . $fe;
if ( ! file_exists($file_path)) {
continue;
}
$settlement_record = $this->paypal_read_excel($file_path);
if (empty($settlement_record)) {
continue;
}
var_dump($settlement_record);
foreach ($settlement_record as $settle) {
$orderid_info = analysis_orderid(trim($settle['Invoice Number'])); // todo
$orderid_info = json_decode($orderid_info);
if ( ! empty($orderid_info)) {
if (strcasecmp($orderid_info->ordertype, "B") === 0) {
// $old_info = $this->IPayLinks_model->get_money_b(trim($settle['Transaction ID']));
} else if (strcasecmp($orderid_info->ordertype, "T") === 0){
// $old_info = $this->IPayLinks_model->get_money_t(trim($settle['Transaction ID']));
}
}
$warrant["PR_AccreditNo"] = trim($settle['Transaction ID']);
$warrant["PR_payType"] = 15002;
$warrant["PR_entryCurrency"] = trim($settle['Currency']);
$warrant["PR_entryAmount"] = number_format(trim($settle['Net']), 2, ".", "");
$warrant["PR_COLI_SN"] = !empty($old_info) ? $old_info[0]->GAI_COLI_SN : NULL;
$warrant["PR_currency"] = trim($settle['Currency']);
$warrant["PR_amount"] = number_format(trim($settle['Gross']), 2, ".", "");
$warrant["PR_orderType"] = $orderid_info ? $orderid_info->ordertype : NULL;
$warrant["PR_fee"] = number_format(trim($settle['Fee']), 2, ".", "");
$warrant["PR_paymentTime"] = trim($settle['Date']) . " " . trim($settle['Time']);
$warrant["PR_dealType"] = trim($settle['Type']);
$warrant["PR_orderId"] = trim($settle['Invoice Number']); // todo
$warrant["PR_rate"] = "1.00";
$warrant["PR_status"] = trim($settle['Status']);
$warrant["PR_buyerName"] = trim($settle['Name']);
$warrant["PR_buyerEmail"] = trim($settle['From Email Address']);
$this->Report_model->new_report($warrant);
$warrant = NULL;
$update_cnt++;
}
$settlement_record = NULL;
}
echo $update_cnt;
}
public function paypal_read_excel($filePath)
{
$tarr1=array();
$this->load->library('PHPExcel');
$PHPExcel = new PHPExcel();
$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);
foreach($currentSheet->getRowIterator() as $key1 => $row)
{
$row_tmp = array();
foreach($row->getCellIterator() as $key => $cell)
{
if ($key1 === 1) {
$col_titles[] = $cell->getCalculatedValue();
} elseif ($key === 1) {
$row_tmp[$col_titles[$key]] = PHPExcel_Style_NumberFormat::toFormattedString($cell->getCalculatedValue(), 'H:i:s');
} else {
$row_tmp[$col_titles[$key]] = $cell->getCalculatedValue();
}
}
$row_tmp ? $tarr1[] = $row_tmp : NULL;
}
return $tarr1;
}
public function paypal_get_token()
{
$header = array(
@ -352,19 +458,18 @@ class Report extends CI_Controller
return json_decode($reponse);
}
public function paypal_get_payment($payment_id)
public function paypal_get_payment($payment_id=NULL)
{
// $url = $this->config->item("payment_url") . "/" . $payment_id;
// $url = $this->config->item("sale_url") . "/" . $payment_id;
$url = $this->config->item("activities_url") . "?page_size=50&sort_by=create_time&sort_order=desc&start_time=2018-03-25T11:00:00Z&end_time=2018-03-28T11:00:00Z";
$url = $this->config->item("payment_url") . "?start_time=2018-03-28T11:00:00Z&end_time=2018-03-30T11:00:00Z";
// $url = $this->config->item("sale_url") . $payment_id;
$c = $this->call_paypal($url);
var_dump($c);
echo (json_encode($c));
return $c;
}
public function call_paypal($url, $body = false)
{
$token_info = $this->paypal_get_token();var_dump($token_info);
$token_info = $this->paypal_get_token();
// todo if no token
$access_token = $token_info->access_token;
$token_type = $token_info->token_type;

Loading…
Cancel
Save