|
|
|
@ -611,6 +611,73 @@ class Index extends CI_Controller {
|
|
|
|
|
return ;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* [paypal_webhook description]
|
|
|
|
|
* @author LYT <lyt@hainatravel.com>
|
|
|
|
|
* @date 2019-05-23
|
|
|
|
|
* PAYMENT.SALE.COMPLETED 没有付款人信息
|
|
|
|
|
* * resource.id=txn_id
|
|
|
|
|
* * invoice_number=invoice_number
|
|
|
|
|
*/
|
|
|
|
|
public function paypal_webhook()
|
|
|
|
|
{
|
|
|
|
|
$raw_post = file_get_contents('php://input');
|
|
|
|
|
if (empty($raw_post)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$post_data = json_decode($raw_post);
|
|
|
|
|
if ($post_data->event_type != 'PAYMENT.SALE.COMPLETED') {
|
|
|
|
|
log_message('error',"paypal_webhook" . var_export($raw_post, 1));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
$pn_txn_id = $post_data->resource->id;
|
|
|
|
|
|
|
|
|
|
$pn_invoice = $post_data->resource->invoice_number;
|
|
|
|
|
|
|
|
|
|
$pn_mc_gross = $post_data->resource->amount->total;
|
|
|
|
|
|
|
|
|
|
// $pn_item_name = $this->input->post('item_name');
|
|
|
|
|
// if (empty($pn_item_name)) {
|
|
|
|
|
// $pn_item_name = $this->input->post('item_name1'); //APP用SDK支付的话会是item_name1
|
|
|
|
|
// empty($pn_item_name) ? $pn_item_name = '' : false;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// $pn_item_number = $this->input->post('item_number');
|
|
|
|
|
// if (empty($pn_item_number)) {
|
|
|
|
|
// $pn_item_number = $this->input->post('item_number1'); //APP用SDK支付的话会是item_number1
|
|
|
|
|
// empty($pn_item_number) ? $pn_item_number = '' : false;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
$pn_mc_currency = $post_data->resource->amount->currency;
|
|
|
|
|
$pn_payment_status = $post_data->resource->state;
|
|
|
|
|
$pn_payment_date = $post_data->resource->update_time;
|
|
|
|
|
// $pn_payer = $post_data->resource->amount->currency;
|
|
|
|
|
// $pn_payer_email = $post_data->resource->amount->currency;
|
|
|
|
|
$pn_memo = $raw_post;
|
|
|
|
|
if (!empty($pn_txn_id)) {
|
|
|
|
|
//把PDT时间转成GMT时间
|
|
|
|
|
$pn_payment_date = gmdate('Y-m-d H:i:s', strtotime($pn_payment_date));
|
|
|
|
|
$this->Note_model->save_paypal_note(
|
|
|
|
|
$pn_txn_id,
|
|
|
|
|
$pn_invoice,
|
|
|
|
|
"",
|
|
|
|
|
$pn_mc_gross,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
$pn_mc_currency,
|
|
|
|
|
$pn_payment_status,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
$pn_payment_date,
|
|
|
|
|
$pn_memo);
|
|
|
|
|
log_message('error','paypal-webhook-succeed ' . $pn_txn_id . ' # ' . $pn_invoice);
|
|
|
|
|
// echo 'ok';
|
|
|
|
|
} else {
|
|
|
|
|
// echo 'no';
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//解析出订单号
|
|
|
|
|
public function analysis_orderid($note_invoice_string) {
|
|
|
|
|
$data = array();
|
|
|
|
@ -718,13 +785,13 @@ class Index extends CI_Controller {
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
//找到没有发送的记录
|
|
|
|
|
public function send_note($pn_txn_id = false, $old_ssje=NULL) {
|
|
|
|
|
public function send_note($pn_txn_id = false, $old_ssje=NULL, $pn_sn=NULL) {
|
|
|
|
|
$data = array();
|
|
|
|
|
$handpick = empty($pn_txn_id) ? false : TRUE;
|
|
|
|
|
|
|
|
|
|
//优先处理指定的交易号,用于修正交易号直接发送通知
|
|
|
|
|
if (!empty($pn_txn_id)) {
|
|
|
|
|
$data['unsend_list'] = array($this->Note_model->note($pn_txn_id));
|
|
|
|
|
$data['unsend_list'] = array($this->Note_model->note($pn_txn_id, $pn_sn));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//找到处理过的的记录
|
|
|
|
@ -749,15 +816,32 @@ class Index extends CI_Controller {
|
|
|
|
|
if (empty($pn_txn_id)) {
|
|
|
|
|
echo ++$show_index . ' ' . $item->pn_txn_id . '<br/>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// webhook的跳过
|
|
|
|
|
$webhook_memo = json_decode($item->pn_memo);
|
|
|
|
|
$is_webhook = false;
|
|
|
|
|
if (isset($webhook_memo->id) && substr($webhook_memo->id, 0, 2)==="WH") {
|
|
|
|
|
$is_webhook = true;
|
|
|
|
|
}
|
|
|
|
|
if (true === $is_webhook) {
|
|
|
|
|
$this->Note_model->update_send($item->pn_txn_id, 'send', $item->pn_sn);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理
|
|
|
|
|
if ($item->pn_payment_status == 'Refunded') {
|
|
|
|
|
if (strtolower($item->pn_payment_status) == 'refunded') {
|
|
|
|
|
$this->send_refund($item, $handpick, $old_ssje);
|
|
|
|
|
// $this->Note_model->update_send($item->pn_txn_id, 'send');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
// 撤销付款:允许手动处理
|
|
|
|
|
if (strtolower($item->pn_payment_status) == 'reversed' && $handpick===true ) {
|
|
|
|
|
$this->send_refund($item, $handpick, $old_ssje);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//只处理完成状态,其他状态由陆燕处理
|
|
|
|
|
if ($item->pn_payment_status !== 'Completed') {
|
|
|
|
|
if (strtolower($item->pn_payment_status) !== 'completed') {
|
|
|
|
|
$this->Note_model->update_send($item->pn_txn_id, 'sendfail');
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
@ -785,7 +869,7 @@ class Index extends CI_Controller {
|
|
|
|
|
}
|
|
|
|
|
$orderid_info = json_decode($orderid_info);
|
|
|
|
|
// 仅自动程序发送提醒 false == $handpick &&
|
|
|
|
|
if ($item->pn_payment_status === 'Completed'
|
|
|
|
|
if (strtolower($item->pn_payment_status) === 'completed'
|
|
|
|
|
&& $orderid_info->ordertype == 'A' && strpos($get_order_no, 'China Train Booking') !== false) {
|
|
|
|
|
// APP 组的China Train Booking-开头的订单号
|
|
|
|
|
// 发送邮件提醒外联核对收款金额, 不写入收款记录
|
|
|
|
@ -841,7 +925,7 @@ class Index extends CI_Controller {
|
|
|
|
|
$GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0;
|
|
|
|
|
//CHTAPP订单添加记录前判断是否有记录,以前的APP版本没有交易号,只能拿金额来判断
|
|
|
|
|
if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP' && strstr($advisor_info->COLI_WebCode, "-") !== '-biz') {//只判断前6位字符,CHTAPP-fr CHTAPP-jp等各语种都属于APP订单
|
|
|
|
|
$this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, '', $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
|
|
|
|
|
$this->Paypal_model->add_account_info_forAPP($GAI_COLI_SN, $advisor_info->COLI_ID, $item->pn_mc_gross, $item->pn_payment_date, mb_strtoupper($item->pn_mc_currency), $ssje, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payment_date, $item->pn_payer, $item->pn_payer_email, $item->pn_txn_id, $ht_memo);
|
|
|
|
|
if ($advisor_info->COLI_WebCode == 'CHTAPP' && $advisor_info->COLI_State == 11) { //只修改APP组的订单状态,并且订单进度是我的订单
|
|
|
|
|
$this->Paypal_model->update_biz_coli_state($GAI_COLI_SN, 8); //把订单状态改为已付款
|
|
|
|
|
$this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'BS8');
|
|
|
|
@ -863,7 +947,7 @@ class Index extends CI_Controller {
|
|
|
|
|
$item->pn_payment_date,
|
|
|
|
|
$item->pn_payment_date,
|
|
|
|
|
$item->pn_payment_date,
|
|
|
|
|
'',
|
|
|
|
|
$item->pn_payer,
|
|
|
|
|
$item->pn_payer_email,
|
|
|
|
|
$item->pn_txn_id,
|
|
|
|
|
$ht_memo);
|
|
|
|
@ -893,9 +977,8 @@ class Index extends CI_Controller {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//添加邮件发送记录
|
|
|
|
|
if ($item->pn_send !== 'send') {
|
|
|
|
|
if ($item->pn_send !== 'send' && false===$is_webhook) {
|
|
|
|
|
//给外联发送通知邮件
|
|
|
|
|
$fromName = !empty($item->pn_payer) ? $item->pn_payer : '';
|
|
|
|
|
$fromEmail = !empty($item->pn_payer_email) ? $item->pn_payer_email : '';
|
|
|
|
@ -909,6 +992,8 @@ class Index extends CI_Controller {
|
|
|
|
|
$this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note');
|
|
|
|
|
//添加邮件发送记录 end
|
|
|
|
|
|
|
|
|
|
$this->Note_model->update_send($item->pn_txn_id, 'send');
|
|
|
|
|
} else {
|
|
|
|
|
$this->Note_model->update_send($item->pn_txn_id, 'send');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -1026,9 +1111,9 @@ class Index extends CI_Controller {
|
|
|
|
|
$this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note');
|
|
|
|
|
// 通知客人, 客人邮箱
|
|
|
|
|
$customer_detail = $this->Paypal_model->get_customer_detail($advisor_info->COLI_SN, $orderid_info->ordertype);
|
|
|
|
|
$c_fromName = $advisor_detail->fullname;
|
|
|
|
|
$c_fromName = $advisor_detail->fullname ? $advisor_detail->fullname : $opi_firstname;
|
|
|
|
|
$opi_email_list = explode(";", $advisor_detail->email); // 解析外联的邮件
|
|
|
|
|
$c_fromEmail = trim($opi_email_list[0]);
|
|
|
|
|
$c_fromEmail = isset($opi_email_list[0]) ? trim($opi_email_list[0]) : $opi_email;
|
|
|
|
|
$c_toName = $customer_detail->fullname;
|
|
|
|
|
$c_toEmail = $customer_detail->email;
|
|
|
|
|
$c_subject = $item->pn_mc_currency . " " . str_replace('-', '', $item->pn_mc_gross) . " Refunded to your account, booking number " . $item->pn_invoice;
|
|
|
|
@ -1236,7 +1321,7 @@ class Index extends CI_Controller {
|
|
|
|
|
$amount = $this->input->post("set_amount");
|
|
|
|
|
$last_record = $this->input->post("date_history");
|
|
|
|
|
if (empty($amount)) {
|
|
|
|
|
$export_list = $this->Note_model->date_range($from_date, $to_date, $currency);
|
|
|
|
|
$export_list = $this->Note_model->date_range($from_date, $to_date, $currency, null, false);
|
|
|
|
|
} else {
|
|
|
|
|
$allmost_day = intval(ceil($amount/10000));
|
|
|
|
|
if ( ! in_array($currency, array('CNY','USD'))) {
|
|
|
|
@ -1302,7 +1387,7 @@ class Index extends CI_Controller {
|
|
|
|
|
public function target_amount_recursive($currency, $target_amount, $now_amount, $from_date,$days=10,$list=array(), $last_sn=null, $last_flag=null)
|
|
|
|
|
{
|
|
|
|
|
$to_date = date('Y-m-d', strtotime("+$days days", strtotime($from_date)));
|
|
|
|
|
$former_list = $this->Note_model->date_range($from_date, $to_date, $currency, $last_sn);
|
|
|
|
|
$former_list = $this->Note_model->date_range($from_date, $to_date, $currency, $last_sn, false);
|
|
|
|
|
$list_index = 0;
|
|
|
|
|
$last_sn = $last_sn===null ? 0 : $last_sn;
|
|
|
|
|
$last_flag = $last_flag===null ? null : $last_flag;
|
|
|
|
|