paypal 导出指定总金额的收款记录. 自动计算,完全匹配目标金额

feature/trippest
lyt 6 years ago
parent bc43f8d1e8
commit e0399f409b

@ -10,6 +10,7 @@ class Index extends CI_Controller {
// $this->output->enable_profiler(TRUE); // $this->output->enable_profiler(TRUE);
$this->load->model('Paypal_model'); $this->load->model('Paypal_model');
$this->load->model('Note_model'); $this->load->model('Note_model');
bcscale(2);
} }
public function index() { public function index() {
@ -1004,12 +1005,28 @@ class Index extends CI_Controller {
$allmost_day = 30; $allmost_day = 30;
} }
$last_sn = null; $last_sn = null;
$last_notice_sn = null;
$last_notice_record = array();
if ( ! empty($last_record)) { if ( ! empty($last_record)) {
$last_sn = strstr($last_record, '@', TRUE); $selection_text = explode("@", $last_record);
$from_date = substr(strstr($last_record, '@'),1); $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']; $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) { if ($export_list == false) {
echo "Not found any records for export."; 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'])) { 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( $insert_db = array(
"TEL_transactionType" => 15002 "TEL_transactionType" => 15002
,"TEL_transactionNoticeId" => $all_list['last_flag']->pn_sn ,"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_transactionAmount" => $all_list['last_flag']->pn_mc_gross
,"TEL_transactionCurrency" => $all_list['last_flag']->pn_mc_currency ,"TEL_transactionCurrency" => $all_list['last_flag']->pn_mc_currency
,"TEL_orderId" => $all_list['last_flag']->pn_invoice ,"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') ,"TEL_exportDate" => date('Y-m-d H:i:s')
); );
$this->Note_model->export_record($insert_db); $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); $this->save_excel($export_list);
@ -1054,7 +1077,8 @@ class Index extends CI_Controller {
} }
$ret = array( $ret = array(
"last_flag" => $last_flag, "last_flag" => $last_flag,
"list" => $list "list" => $list,
"now_amount" => $now_amount
); );
if (empty($former_list)) { if (empty($former_list)) {
return $ret; return $ret;

@ -162,7 +162,7 @@ class Note_model extends CI_Model {
$search_sql .= " AND pn_mc_currency = '$currency' "; $search_sql .= " AND pn_mc_currency = '$currency' ";
} }
if ( ! empty($pn_sn)) { if ( ! empty($pn_sn)) {
$search_sql .= " AND pn_sn > $pn_sn "; $search_sql .= " AND pn_sn >= $pn_sn ";
} }
$this->search = $search_sql; $this->search = $search_sql;
$this->orderby = " order by pn.pn_sn asc"; $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); $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); $this->info = $this->load->database('INFO', TRUE);
$search_sql = $sn===0 ? "" : " and TEL_SN=$sn ";
$sql = "SELECT TOP 10 * $sql = "SELECT TOP 10 *
FROM [InfoManager].[dbo].[Transaction_Export_Log] FROM [InfoManager].[dbo].[Transaction_Export_Log]
WHERE 1=1
$search_sql
order by TEL_SN desc"; order by TEL_SN desc";
return $this->info->query($sql)->result(); return $this->info->query($sql)->result();
} }

@ -47,6 +47,7 @@
<style type="text/css"> <style type="text/css">
.export_form_area{display: inline-block;padding: 6px;border: 1px solid #ccc;background-color: #ccc;/*position: absolute;top: 0;left: 17%;*/} .export_form_area{display: inline-block;padding: 6px;border: 1px solid #ccc;background-color: #ccc;/*position: absolute;top: 0;left: 17%;*/}
.trigger_export_btn{position: absolute;top: 0;left: 17%;} .trigger_export_btn{position: absolute;top: 0;left: 17%;}
.modal-dialog{width: 1024px;}
</style> </style>
<!-- Button trigger modal --> <!-- Button trigger modal -->
<button type="button" class="btn btn-primary trigger_export_btn" data-toggle="modal" data-target="#exampleModal"> <button type="button" class="btn btn-primary trigger_export_btn" data-toggle="modal" data-target="#exampleModal">
@ -71,7 +72,12 @@
<option value="">选择一个开始记录</option> <option value="">选择一个开始记录</option>
<?php <?php
foreach ($record_flags as $kf => $vf) { foreach ($record_flags as $kf => $vf) {
echo "<option value=\"$vf->TEL_transactionNoticeId@" . strstr($vf->TEL_transactionDate, " ", true) . "\">" . substr($vf->TEL_transactionDate,0,16) . ' / '. $vf->TEL_orderId . ' / '. $vf->TEL_transactionAmount . ' / '. $vf->TEL_transactionCurrency . "</option>"; echo "<option value=\"$vf->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)
. "</option>";
} }
?> ?>
</select> </select>
@ -109,7 +115,7 @@ echo "<option value=\"$vf->TEL_transactionNoticeId@" . strstr($vf->TEL_transacti
<div class="form-group row"> <div class="form-group row">
<label for="set_amount" class="col-md-4">总金额(元)</label> <label for="set_amount" class="col-md-4">总金额(元)</label>
<div class="col-md-16"> <div class="col-md-16">
<input type="number" class="form-control" id="set_amount" name="set_amount" placeholder="总金额"> <input type="number" class="form-control" id="set_amount" name="set_amount" placeholder="总金额" onkeyup="set_target_amount(this)">
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">
@ -284,6 +290,15 @@ echo "<option value=\"$vf->TEL_transactionNoticeId@" . strstr($vf->TEL_transacti
$('#to_date').prop("readonly",true).parents('.form-group').hide(); $('#to_date').prop("readonly",true).parents('.form-group').hide();
$("#to_date" ).datepicker( "option", "disabled", true ); $("#to_date" ).datepicker( "option", "disabled", true );
$("#set_amount").prop("required", 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 );
} }
} }

Loading…
Cancel
Save