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 @@ @@ -71,7 +72,12 @@ 选择一个开始记录 $vf) { -echo "TEL_transactionNoticeId@" . strstr($vf->TEL_transactionDate, " ", true) . "\">" . substr($vf->TEL_transactionDate,0,16) . ' / '. $vf->TEL_orderId . ' / '. $vf->TEL_transactionAmount . ' / '. $vf->TEL_transactionCurrency . ""; +echo "TEL_SN@" . strstr($vf->TEL_transactionDate, " ", true) . "@" . $vf->TEL_transactionCurrency . "\">" + . " [" . strstr($vf->TEL_exportDate, " ", true) . "] " + . $vf->TEL_transactionCurrency . " " . $vf->TEL_transactionAmount . ' - '. $vf->TEL_exportAmount + . " / " . $vf->TEL_orderId . ' / ' + . substr($vf->TEL_transactionDate,0,16) + . ""; } ?> @@ -109,7 +115,7 @@ echo "TEL_transactionNoticeId@" . strstr($vf->TEL_transacti 总金额(元) - + @@ -284,6 +290,15 @@ echo "TEL_transactionNoticeId@" . strstr($vf->TEL_transacti $('#to_date').prop("readonly",true).parents('.form-group').hide(); $("#to_date" ).datepicker( "option", "disabled", true ); $("#set_amount").prop("required", true); + $("#currency option[value='" + select.value.split('@')[2] + "']").prop("selected", true); + $("#currency").prop("disabled", true); + } + } + + function set_target_amount(obj) { + if (parseFloat(obj.value) > 0) { + $('#to_date').prop("readonly",true).parents('.form-group').hide(); + $("#to_date" ).datepicker( "option", "disabled", true ); } }