|
|
|
@ -54,6 +54,7 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
$this->load->model('Group_model');
|
|
|
|
|
$this->load->helper('payment');
|
|
|
|
|
$this->load->model('Online_payment_account_model', 'payment_model');
|
|
|
|
|
$this->load->model('Online_payment_note_model', 'online_note');
|
|
|
|
|
|
|
|
|
|
$this->set_merchant('cht');
|
|
|
|
|
|
|
|
|
@ -98,6 +99,15 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function get_fundsource($app_id)
|
|
|
|
|
{
|
|
|
|
|
$code_fundsource = array(
|
|
|
|
|
"2021004129643221" => "trippest",
|
|
|
|
|
"2017092108849921" => "cht", // "CHT",
|
|
|
|
|
);
|
|
|
|
|
return $app_id ? $code_fundsource[$app_id] : 'cht';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
|
{
|
|
|
|
|
$this->note_list();
|
|
|
|
@ -187,6 +197,38 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
// if (strcmp(strval($response->trade_status), "TRADE_SUCCESS") == 0) {
|
|
|
|
|
// $this->Alipay_note_model->update_query($response->trade_no,$response->buyer_logon_id);
|
|
|
|
|
// }
|
|
|
|
|
$fund_bill_list = json_decode($asyns_resp->data->fund_bill_list, true);
|
|
|
|
|
$to_online = [
|
|
|
|
|
'memo' => json_encode($asyns_resp->data,JSON_UNESCAPED_UNICODE),
|
|
|
|
|
'transaction_id' => strval($asyns_resp->data->trade_no),
|
|
|
|
|
'invoice_id' => strval($asyns_resp->data->out_trade_no),
|
|
|
|
|
'subject' => strval($asyns_resp->data->subject),
|
|
|
|
|
'remark' => strval($asyns_resp->data->body),
|
|
|
|
|
'buyer_id' => $buyer,
|
|
|
|
|
// 'custom_id' => $pn_custom,
|
|
|
|
|
'pay_amount' => strval($asyns_resp->data->total_amount),
|
|
|
|
|
'pay_currency' => 'CNY', // $pn_mc_currency,
|
|
|
|
|
'net_amount' => isset($asyns_resp->data->receipt_amount) ? strval($asyns_resp->data->receipt_amount) : null,
|
|
|
|
|
// 'pay_fee' => $post_data->mc_fee,
|
|
|
|
|
'transaction_status' => 'completed', // $transaction_status, // $pn_payment_status,
|
|
|
|
|
'payment_date' => strval($asyns_resp->data->gmt_create),
|
|
|
|
|
'complate_date' => strval($asyns_resp->data->gmt_payment),
|
|
|
|
|
'fund_source' => $this->get_fundsource($asyns_resp->data->app_id),
|
|
|
|
|
'fund_type' => $notify_type,
|
|
|
|
|
'event' => strval($asyns_resp->data->notify_type),
|
|
|
|
|
'event_result' => strval($asyns_resp->data->trade_status),
|
|
|
|
|
'payment_source' => isset($fund_bill_list[0]) ? $fund_bill_list[0]->fundChannel : null,
|
|
|
|
|
// 'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
|
|
|
|
|
];
|
|
|
|
|
if ($notify_type == "refund") {
|
|
|
|
|
$to_online['transaction_id'] = strval($asyns_resp->data->out_biz_no);
|
|
|
|
|
$to_online['pay_amount'] = "-" . strval($asyns_resp->data->refund_fee);
|
|
|
|
|
$to_online['net_amount'] = $to_online['pay_amount'];
|
|
|
|
|
$to_online['payment_date'] = strval($asyns_resp->data->gmt_refund);
|
|
|
|
|
$to_online['complate_date'] = strval($asyns_resp->data->notify_time);
|
|
|
|
|
$to_online['referer_id'] = strval($asyns_resp->data->trade_no);
|
|
|
|
|
}
|
|
|
|
|
$this->online_note->add_note_alipay($to_online);
|
|
|
|
|
}
|
|
|
|
|
// 返回状态码200
|
|
|
|
|
echo "success";
|
|
|
|
@ -868,24 +910,31 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
ignore_user_abort(true);
|
|
|
|
|
$request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
|
|
|
|
|
$date = $date===NULL ? date("Y-m-d", strtotime("-1 day")) : $date;
|
|
|
|
|
$request->setBizContent("{" .
|
|
|
|
|
"\"bill_type\":\"signcustomer\"," .
|
|
|
|
|
"\"bill_date\":\"$date\"" .
|
|
|
|
|
"}");
|
|
|
|
|
$response = $this->aopclientRequestExecute ($request);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
$resultCode = $response->$responseNode->code;
|
|
|
|
|
if(empty($resultCode) || strval($resultCode) !== "10000"){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$file = file_get_contents($response->$responseNode->bill_download_url);
|
|
|
|
|
$file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date . ".zip";
|
|
|
|
|
$target = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date ;
|
|
|
|
|
file_put_contents($file_name, $file);
|
|
|
|
|
if (file_exists($file_name)) {
|
|
|
|
|
// 已经下载, 直接读取
|
|
|
|
|
} else {
|
|
|
|
|
$request->setBizContent("{" .
|
|
|
|
|
"\"bill_type\":\"signcustomer\"," .
|
|
|
|
|
"\"bill_date\":\"$date\"" .
|
|
|
|
|
"}");
|
|
|
|
|
$response = $this->aopclientRequestExecute ($request);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
$resultCode = $response->$responseNode->code;
|
|
|
|
|
if(empty($resultCode) || strval($resultCode) !== "10000"){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
set_time_limit(0);
|
|
|
|
|
$file = file_get_contents($response->$responseNode->bill_download_url);
|
|
|
|
|
$file_name = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date . ".zip";
|
|
|
|
|
$target = FCPATH.'download_statement\settlement_files\alipay\\' . $this->merchant_account . $date ;
|
|
|
|
|
file_put_contents($file_name, $file);
|
|
|
|
|
}
|
|
|
|
|
$biz_detail_table = array();
|
|
|
|
|
$biz_data_title = $this->bill_data_title();
|
|
|
|
|
$finance_data_title = $this->finance_data_title();
|
|
|
|
|
$biz_data_rows = [];
|
|
|
|
|
$finance_data_rows = [];
|
|
|
|
|
$zip = zip_open($file_name);
|
|
|
|
|
if ($zip) {
|
|
|
|
|
while ($zip_entry = zip_read($zip)) {
|
|
|
|
@ -895,8 +944,10 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
$content_row = explode("\n", $content_convert);
|
|
|
|
|
if (stripos($content_row[0], "业务明细")) {
|
|
|
|
|
$data_title = $biz_data_title;
|
|
|
|
|
$this_rows = &$biz_data_rows;
|
|
|
|
|
} elseif (stripos($content_row[0], "账务明细")) {
|
|
|
|
|
$data_title = $finance_data_title;
|
|
|
|
|
$this_rows = &$finance_data_rows;
|
|
|
|
|
} else {
|
|
|
|
|
zip_entry_close($zip_entry);
|
|
|
|
|
continue;
|
|
|
|
@ -914,7 +965,8 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
$row_arr[$title] = trim($row[$key]);
|
|
|
|
|
}
|
|
|
|
|
$row_arr['app_id'] = $this->appid;
|
|
|
|
|
$biz_detail_table[] = $row_arr;
|
|
|
|
|
// $biz_detail_table[] = $row_arr;
|
|
|
|
|
array_push($this_rows, $row_arr);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zip_entry_close($zip_entry);
|
|
|
|
@ -922,11 +974,13 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
}
|
|
|
|
|
zip_close($zip);
|
|
|
|
|
}
|
|
|
|
|
$biz_detail_table = array_merge($biz_data_rows, $finance_data_rows);
|
|
|
|
|
if (empty($biz_detail_table)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
$to_online_arr = array();
|
|
|
|
|
foreach ($biz_detail_table as $key => $row) {
|
|
|
|
|
$total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null;
|
|
|
|
|
$total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null;$net_amount = '';
|
|
|
|
|
if (isset($row['finance_id'])) {
|
|
|
|
|
if ($row['biz_type'] !== '其它' && $row['biz_type'] !== '在线支付' && $row['biz_type'] !== '转账') {
|
|
|
|
|
continue;
|
|
|
|
@ -940,6 +994,7 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
$trade_no = $row['refund_id'];
|
|
|
|
|
} else {
|
|
|
|
|
$total_amount = ($row['total_amount']);
|
|
|
|
|
$net_amount = bcadd($row['total_amount'],$row['charge_fee']);
|
|
|
|
|
$trade_type = 'pay';
|
|
|
|
|
$trade_no = $row['trade_no'];
|
|
|
|
|
$has_charge = floatval($row['charge_fee'])==0 ? 1 : null;
|
|
|
|
@ -961,6 +1016,36 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
,$row['buyer_user_name']
|
|
|
|
|
,null,true
|
|
|
|
|
);
|
|
|
|
|
$to_online = [
|
|
|
|
|
'memo' => json_encode($row, JSON_UNESCAPED_UNICODE),
|
|
|
|
|
'transaction_id' => strval($trade_no),
|
|
|
|
|
'invoice_id' => strval($row['out_trade_no']),
|
|
|
|
|
'subject' => strval($row['subject']),
|
|
|
|
|
'remark' => isset($row['body']) ? strval($row['body']) : $row['remark'],
|
|
|
|
|
'buyer_email' => $row['buyer_user_name'],
|
|
|
|
|
// 'buyer_id' => $buyer,
|
|
|
|
|
// 'custom_id' => $pn_custom,
|
|
|
|
|
'pay_amount' => strval($total_amount),
|
|
|
|
|
'pay_currency' => 'CNY', // $pn_mc_currency,
|
|
|
|
|
'net_amount' => $net_amount === '' ? strval($total_amount) : strval($net_amount),
|
|
|
|
|
'pay_fee' => isset($row['charge_fee']) ? bcsub(0, $row['charge_fee']) : null,
|
|
|
|
|
'transaction_status' => 'completed', // $transaction_status, // $pn_payment_status,
|
|
|
|
|
'payment_date' => $row['complete_time'],
|
|
|
|
|
'complate_date' => $row['complete_time'],
|
|
|
|
|
'fund_source' => $this->get_fundsource($row['app_id']),
|
|
|
|
|
'fund_type' => $trade_type,
|
|
|
|
|
'event' => isset($row['biz_type']) ? strval($row['biz_type']) : $row['trade_type'],
|
|
|
|
|
'event_result' => 'TRADE_SUCCESS',
|
|
|
|
|
'payment_source' => isset($row['trading_channel']) ? $row['trading_channel'] : null,
|
|
|
|
|
// 'referer_id' => isset($post_data->parent_txn_id) ? $post_data->parent_txn_id : '',
|
|
|
|
|
];
|
|
|
|
|
if ($trade_type == "refund") {
|
|
|
|
|
$to_online['referer_id'] = strval($row['trade_no']);
|
|
|
|
|
}
|
|
|
|
|
$to_online_arr[] = $to_online;
|
|
|
|
|
}
|
|
|
|
|
foreach ($to_online_arr as $key => $item) {
|
|
|
|
|
$this->online_note->add_note_alipay($item, true);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|