From d1b78f0c62a61add390bcfe0484dfb3e37eb7b2b Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 19 Apr 2019 13:23:30 +0800 Subject: [PATCH 1/4] =?UTF-8?q?Trippest=E7=AB=99=E7=82=B9=E6=94=B6?= =?UTF-8?q?=E6=AC=BE=E8=87=AA=E5=8A=A8=E5=BD=95=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/paypal/controllers/index.php | 128 +++++++++++++++++- .../paypal/models/paypal_model.php | 9 +- 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index 545a94be..2dacf8a9 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -755,6 +755,7 @@ class Index extends CI_Controller { } //检测是否是APP订单,默认不处理 + // && $item->pn_payment_status !== 'Refunded' if ( ( (strpos($item->pn_memo, 'China Train Booking') !== false) || (strpos($item->pn_memo, 'ChinaTrainBooking') !== false) @@ -879,12 +880,135 @@ class Index extends CI_Controller { //echo 'done!'; } + public function send_refund($item) + { + // 找到原始收款交易的订单 + $parent_note = $this->note_modal->note($item->parent_txn_id); + if (empty($parent_note)) { + return false; + } + //订单号 + $orderid_info = $this->analysis_orderid($parent_note->pn_invoice); + + //找不到订单号,设置为发送失败标示 + if (empty($orderid_info)) { + $this->Note_model->update_send($item->pn_txn_id, 'sendfail'); + return false; + } + + // for trippest tourMaster 2018.05.28 + if ($orderid_info->ordertype == 'TP') { + $this->trippest_note($orderid_info, $item); + return false; + } + + //根据订单号查找外联信息 + $orderid_info = json_decode($orderid_info); + $handpick = empty($pn_txn_id) ? false : TRUE; + $advisor_info = $this->Paypal_model->get_order($orderid_info->orderid, false, $orderid_info->ordertype, $handpick); + + //查不到订单信息 + if (empty($advisor_info)) { + $this->Note_model->update_send($item->pn_txn_id, 'sendfail'); + return false; + } + + //更新正确的订单信息到记录中,以这个为主 + $this->Note_model->set_invoice($item->pn_txn_id, $orderid_info->orderid . '_' . $orderid_info->ordertype); + + //添加支付信息入库 + //没有分配订单之前先添加付款记录,这个过程可能会执行多次,必须在添加记录前查找是否有数据 + if (!empty($orderid_info)) { + $ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency)); + $ssje = $old_ssje===NULL ? $ssje : $old_ssje; + //更新还没有填的客邮和交易号de收款记录(商务订单) + if (isset($advisor_info->order_type) && $advisor_info->order_type == 0) { + $ht_memo = '退款交易号(自动录入):' . $item->pn_txn_id . "\n. "; + $ht_memo .= '原收款交易号(自动录入):' . $item->parent_txn_id; + $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; + //CHTAPP订单添加记录前判断是否有记录,以前的APP版本没有交易号,只能拿金额来判断 + if (substr($advisor_info->COLI_WebCode, 0, 6) == 'CHTAPP') {//只判断前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->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); + } else { + // 把订单状态设置为13-新订单已支付 + if (false == $this->Paypal_model->if_biz_gai_exists($item->pn_txn_id) ) { + $this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); + } + $this->Paypal_model->add_account_info($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); + } + } + //更新还没有填的客邮和交易号de收款记录(传统订单) + elseif (isset($advisor_info->order_type) && $advisor_info->order_type == 1) { + $ht_memo = '退款交易号(自动录入):' . $item->pn_txn_id . "\n. "; + $ht_memo .= '原收款交易号(自动录入):' . $item->parent_txn_id; + $GAI_COLI_SN = isset($advisor_info->COLI_SN) ? $advisor_info->COLI_SN : 0; + $gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $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); + //添加汉特的订单提醒 + $this->Paypal_model->update_coli_introduction($GAI_COLI_SN, '已退款 ' . mb_strtoupper($item->pn_mc_currency) . $item->pn_mc_gross); + // 添加HT任务 // todo 是否还需要 + $this->Paypal_model->exec_addToTask($gai_sn); + } + } + + + $opi_email = !empty($advisor_info->OPI_Email) ? $advisor_info->OPI_Email : ''; //lussie@chinahighlights.net + $opi_firstname = !empty($advisor_info->OPI_FirstName) ? $advisor_info->OPI_FirstName : !empty($advisor_info->OPI_Name) ? $advisor_info->OPI_Name : ''; //lussie + + //没有外联信息表示订单未分配 + if (empty($opi_email) || empty($opi_firstname)) { + $this->Note_model->update_send($item->pn_txn_id, 'sendfail'); + return false; + } + + //添加邮件发送记录 + //给外联发送通知邮件 + $fromName = !empty($item->pn_payer) ? $item->pn_payer : ''; + $fromEmail = !empty($item->pn_payer_email) ? $item->pn_payer_email : ''; + $toName = !empty($opi_firstname) ? $opi_firstname : ''; + $toEmail = !empty($opi_email) ? $opi_email : ''; + $subject = $orderid_info->orderid . '_' . $orderid_info->ordertype . ' / ' . $item->pn_mc_gross . $item->pn_mc_currency . ' / ' . $fromName; + $body = $this->load->view('mail_templete', $item, true); //$item->pn_memo; + $M_RelatedInfo = $item->pn_sn; + $M_AddTime = $item->pn_payment_date; + $M_State = 0; + $this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note'); + //添加邮件发送记录 end + + return $this->Note_model->update_send($item->pn_txn_id, 'send'); + } + public function trippest_note($orderid_info, $paypal_msg) { + $tp_orderid = "#" . substr($orderid_info->orderid, 10); + // 获取HT订单号 + $ht_tp_order = $this->Paypal_model->get_trippest_order($tp_orderid); + if (empty($ht_tp_order)) { + return $this->Note_model->update_send($paypal_msg->pn_txn_id, 'sendfail'); + } + //更新正确的订单信息到记录中,以这个为主 + $this->Note_model->set_invoice($item->pn_txn_id, $ht_tp_order->COLI_ID . '_B'); + $ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency)); + $ht_memo = '交易号(自动录入):' . $item->pn_txn_id; + $this->Paypal_model->add_account_info( + $ht_tp_order->COLI_SN, + $ht_tp_order->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 + ); + $opi_firstname = "David"; $opi_email = "david@trippest.com"; - $orderid_info->orderid = $orderid_info->orderid . "#" . substr($orderid_info->orderid, 10); - + $orderid_info->orderid = $orderid_info->orderid . "#" . $tp_orderid; $fromName = !empty($paypal_msg->pn_payer) ? $paypal_msg->pn_payer : ''; $fromEmail = !empty($paypal_msg->pn_payer_email) ? $paypal_msg->pn_payer_email : ''; $toName = !empty($opi_firstname) ? $opi_firstname : ''; diff --git a/webht/third_party/paypal/models/paypal_model.php b/webht/third_party/paypal/models/paypal_model.php index 5ee4b9ad..c32c7a05 100644 --- a/webht/third_party/paypal/models/paypal_model.php +++ b/webht/third_party/paypal/models/paypal_model.php @@ -212,7 +212,7 @@ class Paypal_model extends CI_Model { ,GAI_Memo ,GAI_State ,DeleteFlag - ) VALUES (?,?,15010,?,?,?,?,?,?,?,?,?,?,?,0,0)"; + ) VALUES (?,?,15002,?,?,?,?,?,?,?,?,?,?,?,0,0)"; $query = $this->HT->query($sql, array($GAI_AccreditNo, $GAI_COLI_SN, $GAI_COLI_ID, $GAI_SQJE, $GAI_SQDate, $GAI_SQJECurrency, $GAI_SSJE, $GAI_SSDate, $GAI_AccountDate, $GAI_SubmitDate, $GAI_CusName, $GAI_CusEmail, $GAI_AccreditNo, $GAI_Memo)); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo'); return $query; @@ -602,4 +602,11 @@ class Paypal_model extends CI_Model { ); return $this->HT->insert("BIZ_OrderOperationLog", $db_column); } + + public function get_trippest_order($tp_order) + { + $sql = "SELECT top 1 * from BIZ_ConfirmLineInfo + WHERE COLI_PriceMemo=? "; + return $this->HT->query($sql, array($tp_order))->row(); + } } From c25105bba8251977c3fc95d11a47863e3826f9d1 Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 19 Apr 2019 16:52:32 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E9=80=80=E6=AC=BE=E5=A4=84=E7=90=8630%?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webht/third_party/paypal/controllers/index.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index 2dacf8a9..e6ba1bd4 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -714,6 +714,7 @@ class Index extends CI_Controller { //找到没有发送的记录 public function send_note($pn_txn_id = false, $old_ssje=NULL) { $data = array(); + $handpick = empty($pn_txn_id) ? false : TRUE; //优先处理指定的交易号,用于修正交易号直接发送通知 if (!empty($pn_txn_id)) { @@ -880,7 +881,7 @@ class Index extends CI_Controller { //echo 'done!'; } - public function send_refund($item) + public function send_refund($item, $handpick, $old_ssje=NULL) { // 找到原始收款交易的订单 $parent_note = $this->note_modal->note($item->parent_txn_id); @@ -904,7 +905,6 @@ class Index extends CI_Controller { //根据订单号查找外联信息 $orderid_info = json_decode($orderid_info); - $handpick = empty($pn_txn_id) ? false : TRUE; $advisor_info = $this->Paypal_model->get_order($orderid_info->orderid, false, $orderid_info->ordertype, $handpick); //查不到订单信息 @@ -931,7 +931,6 @@ class Index extends CI_Controller { $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->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); } else { - // 把订单状态设置为13-新订单已支付 if (false == $this->Paypal_model->if_biz_gai_exists($item->pn_txn_id) ) { $this->Paypal_model->insert_biz_order_log($GAI_COLI_SN, 'Refunded'); } @@ -946,8 +945,6 @@ class Index extends CI_Controller { $gai_sn = $this->Paypal_model->add_tour_account_info($GAI_COLI_SN, $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); //添加汉特的订单提醒 $this->Paypal_model->update_coli_introduction($GAI_COLI_SN, '已退款 ' . mb_strtoupper($item->pn_mc_currency) . $item->pn_mc_gross); - // 添加HT任务 // todo 是否还需要 - $this->Paypal_model->exec_addToTask($gai_sn); } } @@ -973,8 +970,10 @@ class Index extends CI_Controller { $M_AddTime = $item->pn_payment_date; $M_State = 0; $this->Paypal_model->save_automail($fromName, $fromEmail, $toName, $toEmail, $subject, $body, $M_RelatedInfo, $M_State, $M_AddTime, 'paypal note'); + // TODO 通知财务, 如果已做账 //添加邮件发送记录 end + return $this->Note_model->update_send($item->pn_txn_id, 'send'); } From 51a7f9ef470875ca7d3344ac1689fb66dfb99b23 Mon Sep 17 00:00:00 2001 From: lyt Date: Mon, 22 Apr 2019 10:04:54 +0800 Subject: [PATCH 3/4] =?UTF-8?q?wxpay=20=E4=BF=AE=E6=94=B9=E8=AF=BB?= =?UTF-8?q?=E5=8F=96post=E6=95=B0=E6=8D=AE=E7=9A=84=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webht/third_party/pay/controllers/WxpayService.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webht/third_party/pay/controllers/WxpayService.php b/webht/third_party/pay/controllers/WxpayService.php index e073dbd1..5f7f8e74 100644 --- a/webht/third_party/pay/controllers/WxpayService.php +++ b/webht/third_party/pay/controllers/WxpayService.php @@ -29,12 +29,14 @@ log_message('error','notify begin ----'); $response['return_msg'] = ''; $GLOBALS['__WX_SITE_NAME__'] = $site; $this->wx_site_config = $this->config->item($GLOBALS['__WX_SITE_NAME__'], 'wxpay'); - if (!isset($GLOBALS['HTTP_RAW_POST_DATA'])) { + $raw_post_data = file_get_contents('php://input'); +// log_message('error',var_export($raw_post_data, 1)); + if (empty($raw_post_data) ){ # 如果没有数据,直接返回失败 return $this->response_to_wx($response); } //获取通知的数据 - $xml = $GLOBALS['HTTP_RAW_POST_DATA']; + $xml = $raw_post_data; $xml_arr = from_xml($xml); // log_message('error',var_export($xml_arr, 1)); if ($this->check_sign($xml_arr) !== true) { From a06156b1cb0757f556b9653b2a6fbd39abf15593 Mon Sep 17 00:00:00 2001 From: lyt Date: Mon, 22 Apr 2019 10:27:50 +0800 Subject: [PATCH 4/4] =?UTF-8?q?paypal=20Trippest=E7=AB=99=E7=9A=84?= =?UTF-8?q?=E6=94=B6=E6=AC=BE=E8=87=AA=E5=8A=A8=E5=BD=95=E5=85=A5=E8=AE=A2?= =?UTF-8?q?=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/paypal/controllers/index.php | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index e6ba1bd4..b844043f 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -986,22 +986,22 @@ class Index extends CI_Controller { return $this->Note_model->update_send($paypal_msg->pn_txn_id, 'sendfail'); } //更新正确的订单信息到记录中,以这个为主 - $this->Note_model->set_invoice($item->pn_txn_id, $ht_tp_order->COLI_ID . '_B'); - $ssje = $this->Paypal_model->get_ssje($item->pn_mc_gross, '15002', mb_strtoupper($item->pn_mc_currency)); - $ht_memo = '交易号(自动录入):' . $item->pn_txn_id; + $this->Note_model->set_invoice($paypal_msg->pn_txn_id, $ht_tp_order->COLI_ID . '_B'); + $ssje = $this->Paypal_model->get_ssje($paypal_msg->pn_mc_gross, '15002', mb_strtoupper($paypal_msg->pn_mc_currency)); + $ht_memo = '交易号(自动录入):' . $paypal_msg->pn_txn_id; $this->Paypal_model->add_account_info( $ht_tp_order->COLI_SN, $ht_tp_order->COLI_ID, - $item->pn_mc_gross, - $item->pn_payment_date, - mb_strtoupper($item->pn_mc_currency), + $paypal_msg->pn_mc_gross, + $paypal_msg->pn_payment_date, + mb_strtoupper($paypal_msg->pn_mc_currency), $ssje, - $item->pn_payment_date, - $item->pn_payment_date, - $item->pn_payment_date, + $paypal_msg->pn_payment_date, + $paypal_msg->pn_payment_date, + $paypal_msg->pn_payment_date, '', - $item->pn_payer_email, - $item->pn_txn_id, + $paypal_msg->pn_payer_email, + $paypal_msg->pn_txn_id, $ht_memo );