Trippest站点收款自动录入

feature/pay
lyt 6 years ago
parent df00c0823d
commit d1b78f0c62

@ -755,6 +755,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 +880,135 @@ class Index extends CI_Controller {
//echo 'done!'; //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) 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_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