@ -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)
@ -357,6 +357,12 @@ class AlipayTradeService extends CI_Controller
continue;
}
//检测是否是APP订单
if ((strpos($item->ALI_memo, 'China Train Booking') !== false) || (strpos($item->ALI_memo, 'ChinaTrainBooking') !== false)) {
$item->ALI_orderId .= "_A";
// $this->Alipay_note_model->update_send($item->ALI_dealId, 'send');
}
//退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理
if ($item->ALI_payType == 'refund') {
$this->send_refund($item);
@ -370,12 +376,6 @@ class AlipayTradeService extends CI_Controller
continue;
}
//检测是否是APP订单,默认不处理
// if ((strpos($item->pn_memo, 'China Train Booking') !== false) || (strpos($item->pn_memo, 'ChinaTrainBooking') !== false)) { //APP自动出票的订单不需要处理
// $this->Alipay_note_model->update_send($item->ALI_dealId, 'send');
// continue;
// }
//根据note信息找到订单号
$orderid_info = analysis_orderid($item->ALI_orderId);
@ -399,7 +399,7 @@ class AlipayTradeService extends CI_Controller
$this->Alipay_note_model->set_invoice($item->ALI_dealId, $orderid_info->orderid . '_' . $orderid_info->ordertype);
//检测是否是APP订单,默认不处理
if ($orderid_info->ordertype == 'A') { //APP自动出票的订单不需要处理
if ($orderid_info->ordertype == 'A' & & $item->ALI_payType == 'pay' ) { //APP自动出票的订单不需要处理
$this->Alipay_note_model->update_send($item->ALI_dealId, 'send');
continue;
}
@ -537,15 +537,15 @@ class AlipayTradeService extends CI_Controller
$parent_note = $this->Alipay_note_model->note($parent_trade_no);
// APP 组的退款查不到原始收款记录 todo
if (empty($parent_note) ) { # & & true === $this->Alipay_note_model->if_APP_order($parent_order) ) {
// $parent_note = $parent_payment ;
$parent_note = $item ;
// 补充字段
// $parent_note->IPL_orderId = $parent_order . '_B';
// $parent_note->IPL_currencyCode = $parent_payment->currencyCode;
// $parent_note->IPL_payerName = strval("''");
// $parent_note->IPL_payerEmail = strval("''");
$this->Alipay_note_model->update_send($item->ALI_dealId, 'sendfail');
return false;
// $this->Alipay_note_model->update_send($item->ALI_dealId, 'sendfail');
// return false;
}
//订单号
$orderid_info = analysis_orderid($parent_note->ALI_orderId);
@ -641,10 +641,10 @@ class AlipayTradeService extends CI_Controller
$this->Alipay_note_model->update_send($item->ALI_dealId, 'sendfail');
return false;
}
$send_email = ($item->ALI_completeTime>date('Y-m-d', strtotime("-1 day")));
//添加邮件发送记录
// if (true) { // test
if ($item->ALI_sent !== 'send' & & substr($item->ALI_sent, 0, 5) !== 'send-') {
if ($send_email===true & & $ item->ALI_sent !== 'send' & & substr($item->ALI_sent, 0, 5) !== 'send-') {
// 客人邮件中的外联落款
// $web_code = 'cht'; // 默认cht
$web_lgc = 1;
@ -701,11 +701,17 @@ class AlipayTradeService extends CI_Controller
$c_M_AddTime,
'ChinaHighlights refund receipt');
$this->Alipay_note_model->update_send($item->ALI_dealId, 'send-customer');
} else {
$this->Alipay_note_model->update_send($item->ALI_dealId, 'send');
}
//添加邮件发送记录 end
// TODO 如果已做账, 标记需要通知财务send-to-finance, 通知时间用订单日志记录
if ($this->payment_model->if_finance_exists($advisor_info->COLI_GRI_SN)===true) {
$this->Note_model->update_send($item->ALI_dealId, 'send-to-finance');
// 如果已做账, 标记需要通知财务send-to-finance, 通知时间用订单日志记录
// 更新是否需要发送财务
$refund_finance_day = 20;
$now_day = date('d');
$late_entry_date_set = $now_day< $refund_finance_day ? date('Y-m-01', strtotime("-1 month")) : date('Y-m-01');
if ($this->payment_model->if_finance_done($advisor_info->COLI_GRI_SN, $late_entry_date_set) === true) {
$this->Alipay_note_model->update_send($item->ALI_dealId, 'send-to-finance');
}
return ;
}
@ -779,19 +785,152 @@ 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']
,null,true
);
}
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"// 备注
);
}
/**
@ -872,7 +1011,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)