|
|
|
@ -130,7 +130,7 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
,NULL
|
|
|
|
|
,strval($asyns_resp->data->gmt_create)
|
|
|
|
|
,strval($asyns_resp->data->gmt_payment)
|
|
|
|
|
,json_encode($asyns_resp->data)
|
|
|
|
|
,json_encode($asyns_resp->data,JSON_UNESCAPED_UNICODE)
|
|
|
|
|
,$notify_type
|
|
|
|
|
,$code
|
|
|
|
|
,strval($asyns_resp->data->trade_status)
|
|
|
|
@ -147,7 +147,7 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
,NULL
|
|
|
|
|
,strval($asyns_resp->data->gmt_refund)
|
|
|
|
|
,strval($asyns_resp->data->notify_time)
|
|
|
|
|
,json_encode($asyns_resp->data)
|
|
|
|
|
,json_encode($asyns_resp->data,JSON_UNESCAPED_UNICODE)
|
|
|
|
|
,$notify_type
|
|
|
|
|
,$code
|
|
|
|
|
,strval($asyns_resp->data->trade_status)
|
|
|
|
@ -783,19 +783,151 @@ class AlipayTradeService extends CI_Controller
|
|
|
|
|
*/
|
|
|
|
|
public function get_billfile($date=NULL)
|
|
|
|
|
{
|
|
|
|
|
ignore_user_abort(true);
|
|
|
|
|
$request = new AlipayDataDataserviceBillDownloadurlQueryRequest();
|
|
|
|
|
$date = $date===NULL ? "2019-05-16" : $date;
|
|
|
|
|
$date = $date===NULL ? date("Y-m-d", strtotime("-1 day")) : $date;
|
|
|
|
|
$request->setBizContent("{" .
|
|
|
|
|
"\"bill_type\":\"signcustomer\"," .
|
|
|
|
|
"\"bill_date\":\"$date\"" .
|
|
|
|
|
"}");
|
|
|
|
|
$response = $this->aopclientRequestExecute ($request);
|
|
|
|
|
// var_dump($response);
|
|
|
|
|
$responseNode = str_replace(".", "_", $request->getApiMethodName()) . "_response";
|
|
|
|
|
var_dump($response->$responseNode);
|
|
|
|
|
// $resultCode = $result->$responseNode->code;
|
|
|
|
|
// if(!empty($resultCode)&&$resultCode == 10000){
|
|
|
|
|
// }
|
|
|
|
|
$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\\' . $date . ".zip";
|
|
|
|
|
$target = FCPATH.'download_statement\settlement_files\alipay\\' . $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();
|
|
|
|
|
$zip = zip_open($file_name);
|
|
|
|
|
if ($zip) {
|
|
|
|
|
while ($zip_entry = zip_read($zip)) {
|
|
|
|
|
if (zip_entry_open($zip, $zip_entry, "r")) {
|
|
|
|
|
$buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));
|
|
|
|
|
$content_convert = mb_convert_encoding($buf, 'UTF-8', 'GB2312');
|
|
|
|
|
$content_row = explode("\n", $content_convert);
|
|
|
|
|
if (stripos($content_row[0], "业务明细")) {
|
|
|
|
|
$data_title = $biz_data_title;
|
|
|
|
|
} elseif (stripos($content_row[0], "账务明细")) {
|
|
|
|
|
$data_title = $finance_data_title;
|
|
|
|
|
} else {
|
|
|
|
|
zip_entry_close($zip_entry);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
for ($i=5; $i < count($content_row); $i++) {
|
|
|
|
|
if (stripos($content_row[$i], "结束")) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
$row = explode(',',$content_row[$i]);
|
|
|
|
|
$row_arr = array();
|
|
|
|
|
foreach ($data_title as $key => $title) {
|
|
|
|
|
if ( ! isset($row[$key])) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$row_arr[$title] = trim($row[$key]);
|
|
|
|
|
}
|
|
|
|
|
$biz_detail_table[] = $row_arr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
zip_entry_close($zip_entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
zip_close($zip);
|
|
|
|
|
}
|
|
|
|
|
if (empty($biz_detail_table)) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
foreach ($biz_detail_table as $key => $row) {
|
|
|
|
|
$total_amount = 0;$trade_type='';$trade_no = '';$has_charge=null;
|
|
|
|
|
if (isset($row['finance_id'])) {
|
|
|
|
|
if ($row['biz_type'] !== '其它') {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
$total_amount = floatval($row['income'])>0 ? $row['income'] : $row['expenditure'];
|
|
|
|
|
$trade_type = floatval($total_amount)>0 ? 'pay' : 'refund';
|
|
|
|
|
$trade_no = $row['trade_no'];
|
|
|
|
|
} else if (!empty($row['refund_id'])) {
|
|
|
|
|
$total_amount = bcadd($row['total_amount'],$row['charge_fee']);
|
|
|
|
|
$trade_type = 'refund';
|
|
|
|
|
$trade_no = $row['refund_id'];
|
|
|
|
|
} else {
|
|
|
|
|
$total_amount = ($row['total_amount']);
|
|
|
|
|
$trade_type = 'pay';
|
|
|
|
|
$trade_no = $row['trade_no'];
|
|
|
|
|
$has_charge = floatval($row['charge_fee'])==0 ? 1 : null;
|
|
|
|
|
}
|
|
|
|
|
$this->Alipay_note_model->save_alipay(
|
|
|
|
|
$trade_no
|
|
|
|
|
,strval($row['out_trade_no'])
|
|
|
|
|
,"CNY"
|
|
|
|
|
,strval($total_amount)
|
|
|
|
|
,NULL
|
|
|
|
|
,$has_charge
|
|
|
|
|
,strval($row['complete_time'])
|
|
|
|
|
,strval($row['complete_time'])
|
|
|
|
|
,json_encode($row,JSON_UNESCAPED_UNICODE)
|
|
|
|
|
,$trade_type
|
|
|
|
|
,null
|
|
|
|
|
,'TRADE_SUCCESS'
|
|
|
|
|
,NULL
|
|
|
|
|
,$row['buyer_user_name']
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function bill_data_title()
|
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
"trade_no", // 支付宝交易号
|
|
|
|
|
"out_trade_no", // 商户订单号
|
|
|
|
|
"trade_type", // 业务类型
|
|
|
|
|
"subject", // 商品名称
|
|
|
|
|
"create_time", // 创建时间
|
|
|
|
|
"complete_time", // 完成时间
|
|
|
|
|
"store_id", // 门店编号
|
|
|
|
|
"store_name", // 门店名称
|
|
|
|
|
"operator", // 操作员
|
|
|
|
|
"terminal_id", // 终端号
|
|
|
|
|
"buyer_user_name", // 对方账户
|
|
|
|
|
"total_amount", // 订单金额(元)
|
|
|
|
|
"receipt_amount", // 商家实收(元)
|
|
|
|
|
"coupon_amount", // 支付宝红包(元)
|
|
|
|
|
"point_amount", // 集分宝(元)
|
|
|
|
|
"alipayaccount_amount", // 支付宝优惠(元)
|
|
|
|
|
"mdiscount_amount", // 商家优惠(元)
|
|
|
|
|
"discount_amount", // 券核销金额(元)
|
|
|
|
|
"discount_name", // 券名称
|
|
|
|
|
"mcoupon_amount", // 商家红包消费金额(元)
|
|
|
|
|
"pcard_amount", // 卡消费金额(元)
|
|
|
|
|
"refund_id", // 退款批次号/请求号
|
|
|
|
|
"charge_fee", // 服务费(元)
|
|
|
|
|
"royalty_fee", // 分润(元)
|
|
|
|
|
"body" // 备注
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function finance_data_title()
|
|
|
|
|
{
|
|
|
|
|
return array(
|
|
|
|
|
"finance_id",// 账务流水号
|
|
|
|
|
"trade_no",// 业务流水号
|
|
|
|
|
"out_trade_no",// 商户订单号
|
|
|
|
|
"subject",// 商品名称
|
|
|
|
|
"complete_time",// 发生时间
|
|
|
|
|
"buyer_user_name",// 对方账号
|
|
|
|
|
"income",// 收入金额(+元)
|
|
|
|
|
"expenditure",// 支出金额(-元)
|
|
|
|
|
"balance",// 账户余额(元)
|
|
|
|
|
"trading_channel",// 交易渠道
|
|
|
|
|
"biz_type",// 业务类型:交易退款,在线支付,收费,其它
|
|
|
|
|
"remark"// 备注
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -876,7 +1008,7 @@ var_dump($response->$responseNode);
|
|
|
|
|
,1 // 此处1表示通过收款码进来的, 不收手续费, 后续录入时分别处理
|
|
|
|
|
,strval($query_pay->send_pay_date)
|
|
|
|
|
,strval($query_pay->send_pay_date)
|
|
|
|
|
,json_encode($query_pay)
|
|
|
|
|
,json_encode($query_pay,JSON_UNESCAPED_UNICODE)
|
|
|
|
|
,$pay_type
|
|
|
|
|
,NULL
|
|
|
|
|
,strval($query_pay->trade_status)
|
|
|
|
|