From e0399f409ba5429f3abdd757b6c29437c90a46e2 Mon Sep 17 00:00:00 2001 From: lyt Date: Fri, 1 Mar 2019 15:42:56 +0800 Subject: [PATCH] =?UTF-8?q?paypal=20=E5=AF=BC=E5=87=BA=E6=8C=87=E5=AE=9A?= =?UTF-8?q?=E6=80=BB=E9=87=91=E9=A2=9D=E7=9A=84=E6=94=B6=E6=AC=BE=E8=AE=B0?= =?UTF-8?q?=E5=BD=95.=20=E8=87=AA=E5=8A=A8=E8=AE=A1=E7=AE=97,=E5=AE=8C?= =?UTF-8?q?=E5=85=A8=E5=8C=B9=E9=85=8D=E7=9B=AE=E6=A0=87=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../third_party/paypal/controllers/index.php | 34 ++++++++++++++++--- .../third_party/paypal/models/note_model.php | 7 ++-- webht/third_party/paypal/views/note_list.php | 19 +++++++++-- 3 files changed, 51 insertions(+), 9 deletions(-) diff --git a/webht/third_party/paypal/controllers/index.php b/webht/third_party/paypal/controllers/index.php index d2adc6f4..ec3f6458 100644 --- a/webht/third_party/paypal/controllers/index.php +++ b/webht/third_party/paypal/controllers/index.php @@ -10,6 +10,7 @@ class Index extends CI_Controller { // $this->output->enable_profiler(TRUE); $this->load->model('Paypal_model'); $this->load->model('Note_model'); + bcscale(2); } public function index() { @@ -1004,12 +1005,28 @@ class Index extends CI_Controller { $allmost_day = 30; } $last_sn = null; + $last_notice_sn = null; + $last_notice_record = array(); if ( ! empty($last_record)) { - $last_sn = strstr($last_record, '@', TRUE); - $from_date = substr(strstr($last_record, '@'),1); + $selection_text = explode("@", $last_record); + $last_sn = $selection_text[0]; + $last_notice_record = $this->Note_model->list_export_record($last_sn); + if ( ! empty($last_notice_record[0])) { + $last_notice_sn = $last_notice_record[0]->TEL_transactionNoticeId; + // 查询导出记录时包含上次导出的最后一条. + // 因此目标金额设为本次的目标+上次已导出的部分 + // 得到结果集之后会把本次的第一条的金额重新计算,即减去上次已导出金额.下述 + $amount = bcadd($amount, $last_notice_record[0]->TEL_exportAmount); + $from_date = strstr($last_notice_record[0]->TEL_transactionDate, " ", TRUE); + $currency = $last_notice_record[0]->TEL_transactionCurrency; + } } - $all_list = $this->target_amount_recursive($currency, $amount, 0, $from_date, $allmost_day, array(), $last_sn); + $all_list = $this->target_amount_recursive($currency, $amount, 0, $from_date, $allmost_day, array(), $last_notice_sn); $export_list = $all_list['list']; + // 修改导出的第一条记录, 金额改为剩余金额 + if ( ! empty($last_notice_record[0]) && $last_notice_record[0]->TEL_transactionNoticeId==$export_list[0]->pn_sn) { + $export_list[0]->pn_mc_gross = bcsub($last_notice_record[0]->TEL_transactionAmount, $last_notice_record[0]->TEL_exportAmount); + } } if ($export_list == false) { echo "Not found any records for export."; @@ -1017,6 +1034,8 @@ class Index extends CI_Controller { } // 记录这次导出的最后一条 if (isset($all_list['last_flag']) && ! empty($all_list['last_flag'])) { + $balance_diff = bcsub($all_list['now_amount'], $amount); + $last_record_export = bcsub($all_list['last_flag']->pn_mc_gross, $balance_diff); $insert_db = array( "TEL_transactionType" => 15002 ,"TEL_transactionNoticeId" => $all_list['last_flag']->pn_sn @@ -1025,10 +1044,14 @@ class Index extends CI_Controller { ,"TEL_transactionAmount" => $all_list['last_flag']->pn_mc_gross ,"TEL_transactionCurrency" => $all_list['last_flag']->pn_mc_currency ,"TEL_orderId" => $all_list['last_flag']->pn_invoice - ,"TEL_exportAmount" => $all_list['last_flag']->pn_mc_gross + ,"TEL_exportAmount" => $last_record_export ,"TEL_exportDate" => date('Y-m-d H:i:s') ); $this->Note_model->export_record($insert_db); + // 修改导出的最后一条 + array_pop($export_list); + $all_list['last_flag']->pn_mc_gross = $last_record_export; + array_push($export_list, $all_list['last_flag']); } $this->save_excel($export_list); @@ -1054,7 +1077,8 @@ class Index extends CI_Controller { } $ret = array( "last_flag" => $last_flag, - "list" => $list + "list" => $list, + "now_amount" => $now_amount ); if (empty($former_list)) { return $ret; diff --git a/webht/third_party/paypal/models/note_model.php b/webht/third_party/paypal/models/note_model.php index 04938ef1..43662870 100644 --- a/webht/third_party/paypal/models/note_model.php +++ b/webht/third_party/paypal/models/note_model.php @@ -162,7 +162,7 @@ class Note_model extends CI_Model { $search_sql .= " AND pn_mc_currency = '$currency' "; } if ( ! empty($pn_sn)) { - $search_sql .= " AND pn_sn > $pn_sn "; + $search_sql .= " AND pn_sn >= $pn_sn "; } $this->search = $search_sql; $this->orderby = " order by pn.pn_sn asc"; @@ -179,11 +179,14 @@ class Note_model extends CI_Model { $this->info->insert('Transaction_Export_Log', $db); } - public function list_export_record() + public function list_export_record($sn=0) { $this->info = $this->load->database('INFO', TRUE); + $search_sql = $sn===0 ? "" : " and TEL_SN=$sn "; $sql = "SELECT TOP 10 * FROM [InfoManager].[dbo].[Transaction_Export_Log] + WHERE 1=1 + $search_sql order by TEL_SN desc"; return $this->info->query($sql)->result(); } diff --git a/webht/third_party/paypal/views/note_list.php b/webht/third_party/paypal/views/note_list.php index 0a957caa..d8c83858 100644 --- a/webht/third_party/paypal/views/note_list.php +++ b/webht/third_party/paypal/views/note_list.php @@ -47,6 +47,7 @@