Merge branch 'master' of gitee.com:hainatravel/information-system

feature/pay
cyc 6 years ago
commit f1c8819db3

@ -29,12 +29,14 @@ log_message('error','notify begin ----');
$response['return_msg'] = ''; $response['return_msg'] = '';
$GLOBALS['__WX_SITE_NAME__'] = $site; $GLOBALS['__WX_SITE_NAME__'] = $site;
$this->wx_site_config = $this->config->item($GLOBALS['__WX_SITE_NAME__'], 'wxpay'); $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); return $this->response_to_wx($response);
} }
//获取通知的数据 //获取通知的数据
$xml = $GLOBALS['HTTP_RAW_POST_DATA']; $xml = $raw_post_data;
$xml_arr = from_xml($xml); $xml_arr = from_xml($xml);
// log_message('error',var_export($xml_arr, 1)); // log_message('error',var_export($xml_arr, 1));
if ($this->check_sign($xml_arr) !== true) { if ($this->check_sign($xml_arr) !== true) {

@ -714,6 +714,7 @@ 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) {
$data = array(); $data = array();
$handpick = empty($pn_txn_id) ? false : TRUE;
//优先处理指定的交易号,用于修正交易号直接发送通知 //优先处理指定的交易号,用于修正交易号直接发送通知
if (!empty($pn_txn_id)) { if (!empty($pn_txn_id)) {
@ -755,6 +756,7 @@ class Index extends CI_Controller {
} }
//检测是否是APP订单,默认不处理 //检测是否是APP订单,默认不处理
// && $item->pn_payment_status !== 'Refunded'
if ( if (
( (strpos($item->pn_memo, 'China Train Booking') !== false) ( (strpos($item->pn_memo, 'China Train Booking') !== false)
|| (strpos($item->pn_memo, 'ChinaTrainBooking') !== false) || (strpos($item->pn_memo, 'ChinaTrainBooking') !== false)
@ -879,12 +881,133 @@ class Index extends CI_Controller {
//echo 'done!'; //echo 'done!';
} }
public function send_refund($item, $handpick, $old_ssje=NULL)
{
// 找到原始收款交易的订单
$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);
$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 {
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);
}
}
$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');
// TODO 通知财务, 如果已做账
//添加邮件发送记录 end
return $this->Note_model->update_send($item->pn_txn_id, 'send');
}
public function trippest_note($orderid_info, $paypal_msg) 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($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,
$paypal_msg->pn_mc_gross,
$paypal_msg->pn_payment_date,
mb_strtoupper($paypal_msg->pn_mc_currency),
$ssje,
$paypal_msg->pn_payment_date,
$paypal_msg->pn_payment_date,
$paypal_msg->pn_payment_date,
'',
$paypal_msg->pn_payer_email,
$paypal_msg->pn_txn_id,
$ht_memo
);
$opi_firstname = "David"; $opi_firstname = "David";
$opi_email = "david@trippest.com"; $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 : ''; $fromName = !empty($paypal_msg->pn_payer) ? $paypal_msg->pn_payer : '';
$fromEmail = !empty($paypal_msg->pn_payer_email) ? $paypal_msg->pn_payer_email : ''; $fromEmail = !empty($paypal_msg->pn_payer_email) ? $paypal_msg->pn_payer_email : '';
$toName = !empty($opi_firstname) ? $opi_firstname : ''; $toName = !empty($opi_firstname) ? $opi_firstname : '';

@ -212,7 +212,7 @@ class Paypal_model extends CI_Model {
,GAI_Memo ,GAI_Memo
,GAI_State ,GAI_State
,DeleteFlag ,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)); $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'); $insertid = $this->HT->last_id('BIZ_GroupAccountInfo');
return $query; return $query;
@ -602,4 +602,11 @@ class Paypal_model extends CI_Model {
); );
return $this->HT->insert("BIZ_OrderOperationLog", $db_column); 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();
}
} }

Loading…
Cancel
Save