merge from master

feature/pay
lyt 6 years ago
parent 108541cbf6
commit 67c7ca982b

@ -602,7 +602,9 @@ class IPayLinksService extends CI_Controller
$parent_dealId = $parent_payment->dealId;
$parent_note = $this->Note_model->note($parent_dealId);
// APP 组的退款查不到原始收款记录
if (empty($parent_note) && true === $this->IPayLinks_model->if_APP_order($parent_order) ) {
$pure_orderid = strstr($parent_order,"_",true);
$pure_orderid = $pure_orderid===false ? $parent_order : $pure_orderid;
if (empty($parent_note) && true === $this->IPayLinks_model->if_APP_order($pure_orderid) ) {
$parent_note = $parent_payment;
// 补充字段
$parent_note->IPL_orderId = $parent_order . '_B';

@ -218,7 +218,13 @@ class Note_model extends CI_Model {
1=1
$this->date
-- AND (IPL_noticeTime BETWEEN '2018-07-27 00:00:00' AND '2018-07-27 23:59:59' or IPL_sent<>'send')
or ((ISNULL(gaib.GAI_SN, 0)+ISNULL(gai.GAI_SN, 0))=0 and IPL_payType='pay' AND (IPL_sent<>'closeRecord') and COLI.COLI_ID is null)
or (
(
(ISNULL(gaib.GAI_SN, 0)+ISNULL(gai.GAI_SN, 0))=0 and COLI.COLI_ID is null
and IPL_sent not in ('send','closeRecord')
)
or ISNULL(IPL_sent,'') in ('sendfail','unsend','')
)
)
order by isRecord asc,ipl.IPL_sent desc,IPL_sn desc";
$query = $this->INFO->query($sql);

@ -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;

@ -24,7 +24,8 @@ class Note_model extends CI_Model {
$this->search = false;
$this->pn_payment_status = false;
$this->pn_txn_id = false;
$this->orderby = ' ORDER BY pn.pn_sn DESC ';
// $this->orderby = ' ORDER BY pn.pn_sn DESC ';
$this->orderby = ' ORDER BY pn_datetime desc,pn_payer desc ';
//$this->pn_payment_status=' AND pn_payment_status= ';
}
@ -45,7 +46,7 @@ class Note_model extends CI_Model {
public function search_date($date) {
$this->init();
$search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR pn_send not in ('send','closeRecord')) ";
$search_sql = " AND (pn.pn_datetime BETWEEN '$date 00:00:00' AND '$date 23:59:59' OR isnull(pn_send,'') in ('sendfail','unsend','')) ";
$this->search = $search_sql;
$this->orderby=" ORDER BY CASE pn.pn_send WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.pn_sn DESC ";
return $this->get_list();
@ -56,6 +57,7 @@ class Note_model extends CI_Model {
$this->topnum=1;
$this->pn_txn_id=" AND pn.pn_txn_id=".$this->HT->escape($pn_txn_id);
$this->pn_txn_id .= ($pn_sn===NULL) ? "" : " AND pn.pn_sn=".$this->HT->escape($pn_sn);
$this->orderby=" ORDER BY pn_payment_date, pn_payer desc ";
return $this->get_list();
}
@ -134,12 +136,13 @@ class Note_model extends CI_Model {
}
}
public function update_send($pn_txn_id, $pn_send) {
public function update_send($pn_txn_id, $pn_send, $pn_sn=NULL) {
$sql = "
UPDATE paypal_note
SET pn_send = ?
WHERE pn_txn_id = ?
";
$sql .= ($pn_sn===NULL) ? "" : " and pn_sn=$pn_sn ";
return $this->HT->query($sql, array($pn_send, $pn_txn_id));
}
@ -153,7 +156,7 @@ class Note_model extends CI_Model {
return $this->HT->query($sql, array($pn_invoice, $pn_txn_id));
}
public function date_range($from, $to, $currency=NULL, $pn_sn=NULL)
public function date_range($from, $to, $currency=NULL, $pn_sn=NULL, $includeWH=true)
{
$this->init();
$search_sql = " AND pn_payment_status in ('Completed','Refunded') ";
@ -164,6 +167,9 @@ class Note_model extends CI_Model {
if ( ! empty($pn_sn)) {
$search_sql .= " AND pn_sn >= $pn_sn ";
}
if (true !== $includeWH) {
$search_sql .= " AND isnull(pn_payer,'')<>'' and ISNULL(pn_payer_email,'')<>'' ";
}
$this->search = $search_sql;
$this->orderby = " order by pn.pn_sn asc";
return $this->get_list();

@ -213,7 +213,7 @@ echo "<option value=\"$vf->TEL_SN@" . strstr($vf->TEL_transactionDate, " ", true
$show_send = 'send';
} elseif ($item->pn_send == 'closeRecord') {
$show_send = $show_record = '已忽略';
} else if ($item->pn_payment_status == 'Completed') {
} else if (strtolower($item->pn_payment_status) == 'completed') {
$class_css = 'btn-danger';
$show_send = $item->pn_send;
} else {

Loading…
Cancel
Save