diff --git a/webht/third_party/pay/controllers/AlipayTradeService.php b/webht/third_party/pay/controllers/AlipayTradeService.php index c5e9cd3c..7ee6a3d9 100644 --- a/webht/third_party/pay/controllers/AlipayTradeService.php +++ b/webht/third_party/pay/controllers/AlipayTradeService.php @@ -330,7 +330,7 @@ class AlipayTradeService extends CI_Controller * 处理异步通知: 解析订单号, 邮件外联/客人; 插入付款记录 * @author LYT */ - public function send_alipay($pn_txn_id = false) + public function send_alipay($pn_txn_id = false, $old_ssje=null) { $data = array(); $int = 0; @@ -365,7 +365,7 @@ class AlipayTradeService extends CI_Controller //退款状态默认为已经处理,陆燕在退款前手动通知外联了,系统跳过处理 if ($item->ALI_payType == 'refund') { - $this->send_refund($item); + $this->send_refund($item, $old_ssje); // $this->Alipay_note_model->update_send($item->ALI_dealId, 'send'); continue; } @@ -411,6 +411,7 @@ class AlipayTradeService extends CI_Controller if (intval($item->ALI_stateCode)!==1) { $ssje = $this->Alipay_model->get_ssje($item->ALI_orderAmount, $currencyCode); } + $ssje = $old_ssje===null ? $ssje : $old_ssje; $USD_amount = $this->Alipay_model->get_USD($item->ALI_orderAmount, $currencyCode); //更新还没有填的客邮和交易号de收款记录(商务订单) if (isset($advisor_info->order_type) && $advisor_info->order_type == 0) { @@ -528,7 +529,7 @@ class AlipayTradeService extends CI_Controller * @date 2019-05-09 * * TODO 线下收款之后产生的退款没有通知 */ - public function send_refund($item) + public function send_refund($item, $old_ssje=null) { // raw $raw = json_decode($item->ALI_memo); @@ -566,6 +567,7 @@ class AlipayTradeService extends CI_Controller $currencyCode = str_replace("CNY", "RMB", trim(mb_strtoupper($item->ALI_currencyCode))); $currencyCode = mb_strtoupper(trim($currencyCode)); $ssje = $this->Alipay_model->get_ssje($item->ALI_orderAmount, $currencyCode, '15015'); + $ssje = $old_ssje===null ? $ssje : $old_ssje; $USD_amount = $this->Alipay_model->get_USD($item->ALI_orderAmount, $currencyCode); //更新还没有填的客邮和交易号de收款记录(商务订单) if (isset($advisor_info->order_type) && $advisor_info->order_type == 0) { @@ -1051,29 +1053,55 @@ class AlipayTradeService extends CI_Controller //获取note详情,以便后续修改各项数据 public function note_modal($pn_txn_id = false, $pn_invoice = false ,$notice_time = false) { + // $this->permission->is_admin(true); + // $data = array(); + // $data['IPL_orderId'] = $pn_invoice; + // if (!empty($pn_txn_id)) { + // $data['note'] = $this->Alipay_note_model->note($pn_txn_id); + // if (!empty($data['note'])) { + // if (!empty($pn_invoice)) { + // $orderid_info = analysis_orderid($pn_invoice); + // } else { + // $orderid_info = analysis_orderid($data['note']->IPL_orderId); + // } + // if (!empty($orderid_info)) { + // $orderid_info = json_decode($orderid_info); + // $data['order_info'] = $this->Alipay_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype); + // } + // $data["paytext"] = $this->payment_status(); + // echo json_encode($this->load->view('alipay_note_setting', $data, true)); + // return true; + // } + // } + // echo json_encode('没找到数据!'); + // return; + $this->permission->is_admin(true); $data = array(); - $data['IPL_orderId'] = $pn_invoice; - if (!empty($pn_txn_id)) { - $data['note'] = $this->Alipay_note_model->note($pn_txn_id); - if (!empty($data['note'])) { - if (!empty($pn_invoice)) { - $orderid_info = analysis_orderid($pn_invoice); - } else { - $orderid_info = analysis_orderid($data['note']->IPL_orderId); - } - if (!empty($orderid_info)) { - $orderid_info = json_decode($orderid_info); - $data['order_info'] = $this->Alipay_model->get_order($orderid_info->orderid, true, $orderid_info->ordertype); - } - $data["paytext"] = $this->payment_status(); - echo json_encode($this->load->view('alipay_note_setting', $data, true)); - return true; + $data['note'] = $this->Alipay_note_model->note($pn_txn_id); + $orderid_info = analysis_orderid($data['note']->ALI_orderId); + if (!empty($orderid_info)) { + $orderid_info = json_decode($orderid_info); + if ($orderid_info->ordertype === 'T') { + $data['gai_info'] = $this->Alipay_model->get_money_t($pn_txn_id); + } elseif ($orderid_info->ordertype === 'B') { + $data['gai_info'] = $this->Alipay_model->get_money_b($pn_txn_id); } } - echo json_encode('没找到数据!'); - return; + $data['old_order'] = $data['note']->ALI_orderId; + $data['new_order'] = $pn_invoice; + $data['order_info'] = null; + if ($pn_invoice !== null) { + $neworder_id = analysis_orderid($pn_invoice); + $neworder_id = json_decode($neworder_id); + if ( ! empty($neworder_id)) { + $data['order_info'] = $this->Alipay_model->get_order($neworder_id->orderid, true, $neworder_id->ordertype); + } + } + $data["paytext"] = $this->payment_status(); + echo json_encode($this->load->view('alipay_note_setting', $data, true)); } + public function note_order_modal($old_order,$pn_invoice = false ,$notice_time = false) { $data = array(); $data['IPL_orderId'] = $pn_invoice; @@ -1112,13 +1140,38 @@ class AlipayTradeService extends CI_Controller } //修改订单名 - // TODO 支持转移功能 public function note_modal_save() { $data = array(); + $old_ssje = null; $pn_txn_id = $this->input->post('pn_txn_id'); $pn_invoice = $this->input->post('pn_invoice'); + $data['note'] = $this->Alipay_note_model->note($pn_txn_id); + $orderid_info = analysis_orderid($data['note']->ALI_orderId); + // if (empty($orderid_info) && $data['note']->ALI_payType == 'refund' + // && true === $this->Alipay_model->if_APP_order($data['note']->ALI_orderId) + // ) { + // // APP 组的退款订单是没有后缀的 + // $orderid_info = analysis_orderid($data['note']->ALI_orderId . '_B'); + // } + if (!empty($orderid_info)) { + $orderid_info = json_decode($orderid_info); + if ($orderid_info->ordertype === 'T') { + $data['gai_info'] = $this->Alipay_model->get_money_t(substr($pn_txn_id,0,30)); + if ( ! empty($data['gai_info'])) { + $old_ssje = $data['gai_info'][0]->GAI_SSJE; + $this->Alipay_model->delete_money_t(substr($pn_txn_id,0,30)); + } + } elseif ($orderid_info->ordertype === 'B' || $orderid_info->ordertype === 'A') { + $data['gai_info'] = $this->Alipay_model->get_money_b(substr($pn_txn_id,0,30)); + if ( ! empty($data['gai_info'])) { + $old_ssje = $data['gai_info'][0]->GAI_SSJE; + $this->Alipay_model->delete_money_b(substr($pn_txn_id,0,30)); + } + } + } + if (!empty($pn_txn_id) && !empty($pn_invoice)) { $orderid_info = analysis_orderid($pn_invoice); if (!empty($orderid_info)) { @@ -1126,7 +1179,7 @@ class AlipayTradeService extends CI_Controller $advisor_info = $this->Alipay_model->get_order($orderid_info->orderid, false, $orderid_info->ordertype); if (!empty($advisor_info)) { $this->Alipay_note_model->set_invoice($pn_txn_id, $pn_invoice); - $this->send_alipay($pn_txn_id); + $this->send_alipay($pn_txn_id, $old_ssje); echo json_encode('修改成功!'); return true; } diff --git a/webht/third_party/pay/models/Alipay_model.php b/webht/third_party/pay/models/Alipay_model.php index a6d8322f..075cb669 100644 --- a/webht/third_party/pay/models/Alipay_model.php +++ b/webht/third_party/pay/models/Alipay_model.php @@ -155,7 +155,7 @@ class Alipay_model extends CI_Model { IF NOT EXISTS( SELECT TOP 1 1 FROM BIZ_GroupAccountInfo - WHERE GAI_COLI_SN = ? AND GAI_SQJE=? and GAI_Type=15015 + WHERE GAI_COLI_SN = ? AND GAI_SQJE=? and GAI_Type=15015 and DeleteFlag=0 ) INSERT INTO BIZ_GroupAccountInfo ( GAI_COLI_SN @@ -188,7 +188,7 @@ class Alipay_model extends CI_Model { IF NOT EXISTS( SELECT TOP 1 1 FROM BIZ_GroupAccountInfo - WHERE GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%' + WHERE (GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%') and DeleteFlag=0 ) INSERT INTO BIZ_GroupAccountInfo ( GAI_COLI_SN @@ -222,7 +222,7 @@ class Alipay_model extends CI_Model { IF NOT EXISTS( SELECT TOP 1 1 FROM GroupAccountInfo - WHERE GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%' + WHERE (GAI_AccreditNo = ? OR GAI_Memo LIKE '%$GAI_AccreditNo%') and DeleteFlag=0 ) INSERT INTO GroupAccountInfo ( GAI_COLI_SN @@ -413,4 +413,44 @@ class Alipay_model extends CI_Model { return $this->HT->query($sql, $COLI_SN)->row(); } } + + //根据交易号获取收款记录(传统订单) + public function get_money_t($pn_invoice) { + $like = $this->HT->escape_like_str($pn_invoice); + $sql = "SELECT COLI_ID,GroupAccountInfo.* + from GroupAccountInfo + inner join ConfirmLineInfo coli on COLI_SN=GAI_COLI_SN + where GAI_Type='15015' and GroupAccountInfo.DeleteFlag=0 and (GAI_AccreditNo=? or GAI_Memo like '%$like%') + "; + $query = $this->HT->query($sql, array($pn_invoice)); + $result = $query->result(); + return $result; + } + //根据交易号获取收款记录(商务订单) + public function get_money_b($pn_invoice) { + $like = $this->HT->escape_like_str($pn_invoice); + $sql = "SELECT COLI_ID,BIZ_GroupAccountInfo.* + from BIZ_GroupAccountInfo + inner join BIZ_ConfirmLineInfo on COLI_SN=GAI_COLI_SN + where GAI_Type='15015' and BIZ_GroupAccountInfo.DeleteFlag=0 and (GAI_AccreditNo=? or GAI_Memo like '%$like%') + "; + $query = $this->HT->query($sql, array($pn_invoice)); + $result = $query->result(); + return $result; + } + + /** 删除收款记录 */ + public function delete_money_t($deadId) + { + $sql = "UPDATE GroupAccountInfo SET DeleteFlag=1 WHERE GAI_Type='15015' and GAI_AccreditNo=?"; + $query = $this->HT->query($sql, array($deadId)); + return $query; + } + public function delete_money_b($deadId) + { + $sql = "UPDATE BIZ_GroupAccountInfo SET DeleteFlag=1 WHERE GAI_Type='15015' and GAI_AccreditNo=?"; + $query = $this->HT->query($sql, array($deadId)); + return $query; + } + } diff --git a/webht/third_party/pay/models/Alipay_note_model.php b/webht/third_party/pay/models/Alipay_note_model.php index ef99b7e4..040a16a7 100644 --- a/webht/third_party/pay/models/Alipay_note_model.php +++ b/webht/third_party/pay/models/Alipay_note_model.php @@ -42,7 +42,8 @@ class Alipay_note_model extends CI_Model { public function search_date($date) { $this->init(); - $search_sql = " AND pn.ALI_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' "; + $search_sql = " AND pn.ALI_noticeTime BETWEEN '$date 00:00:00' AND '$date 23:59:59' + OR isnull(ALI_sent,'') in ('sendfail','unsend','') "; $this->search = $search_sql; $this->orderby=" ORDER BY CASE pn.ALI_sent WHEN 'sendfail' THEN 1 ELSE 2 END ,pn.ALI_sn DESC "; return $this->get_list(); @@ -198,4 +199,5 @@ class Alipay_note_model extends CI_Model { return $this->INFO->query($sql, array($payer,$dealId)); } + } diff --git a/webht/third_party/pay/views/alipay_note_setting.php b/webht/third_party/pay/views/alipay_note_setting.php index d5ab442f..a7cdfde2 100644 --- a/webht/third_party/pay/views/alipay_note_setting.php +++ b/webht/third_party/pay/views/alipay_note_setting.php @@ -1,5 +1,22 @@
- + +

已录入订单

+ + + + + + + $value) { ?> + + + + + + +
订单号申请金额/币种实收金额
GAI_COLI_ID; ?>GAI_SQJE; ?> GAI_SQJECurrency; ?>GAI_SSJE; ?> CNY
+

撤回以上订单收款记录, 并转移到订单: (手动录入的不会撤回)

+
交易号
ALI_dealId ?> ( ALI_resultMsg))].".".$note->ALI_resultMsg; ?> )
@@ -12,22 +29,18 @@
付款时间
ALI_acquiringTime; ?>
- +
-
订单号
-
- +
-
-
订单详细内容
-
+

订单详细内容

-
-
原始数据
-
+

原始数据 »

+