|
|
@@ -3,8 +3,19 @@ require 'config.php';
|
|
|
|
|
|
if (isset($_GET['debtorName'])) {
|
|
|
$debtorName = $_GET['debtorName'];
|
|
|
-
|
|
|
- // 检查总欠款数据库中是否存在该姓名
|
|
|
+
|
|
|
+ // 先尝试从Redis获取缓存
|
|
|
+ if ($REDIS_ENABLED) {
|
|
|
+ $cacheKey = "debt_info:" . $debtorName;
|
|
|
+ $cachedResult = $redis->get($cacheKey);
|
|
|
+
|
|
|
+ if ($cachedResult) {
|
|
|
+ echo $cachedResult;
|
|
|
+ exit;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有缓存,则查询数据库
|
|
|
$stmt = $pdo->prepare("SELECT * FROM Debtors WHERE debtor_name = :debtorName");
|
|
|
$stmt->execute(['debtorName' => $debtorName]);
|
|
|
$debtor = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
@@ -20,41 +31,45 @@ if (isset($_GET['debtorName'])) {
|
|
|
$viewStmt->execute(['debtorName' => $debtorName]);
|
|
|
$viewData = $viewStmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
|
|
- echo "<div class='search-result'>";
|
|
|
-
|
|
|
- // 更新后的输出格式
|
|
|
- echo "<div class='result-header'>";
|
|
|
- echo "<h2 class='debtor-name'>{$debtor['debtor_name']}</h2>";
|
|
|
- echo "<p class='remaining-debt'>当前欠款余额: <span class='amount'>¥{$viewData['剩余欠款金额']}</span></p>";
|
|
|
- echo "</div>";
|
|
|
+ // 构建输出
|
|
|
+ $output = "<div class='search-result'>";
|
|
|
+ $output .= "<div class='result-header'>";
|
|
|
+ $output .= "<h2 class='debtor-name'>{$debtor['debtor_name']}</h2>";
|
|
|
+ $output .= "<p class='remaining-debt'>当前欠款余额: <span class='amount'>¥{$viewData['剩余欠款金额']}</span></p>";
|
|
|
+ $output .= "</div>";
|
|
|
|
|
|
- echo "<div class='repayment-section'>";
|
|
|
- echo "<h3>还款记录</h3>";
|
|
|
+ $output .= "<div class='repayment-section'>";
|
|
|
+ $output .= "<h3>还款记录</h3>";
|
|
|
|
|
|
if ($repayments) {
|
|
|
- echo "<div class='repayment-list'>";
|
|
|
+ $output .= "<div class='repayment-list'>";
|
|
|
foreach ($repayments as $repayment) {
|
|
|
- echo "<div class='repayment-item'>";
|
|
|
- echo "<div class='repayment-date'><span class='label'>日期:</span> {$repayment['repayment_date']}</div>";
|
|
|
- echo "<div class='repayment-details'>";
|
|
|
- echo "<div class='repayment-amount'><span class='label'>金额:</span> ¥{$repayment['repayment_amount']}</div>";
|
|
|
- echo "<div class='repayment-method'><span class='label'>支付方式:</span> {$repayment['repayment_method']}</div>";
|
|
|
+ $output .= "<div class='repayment-item'>";
|
|
|
+ $output .= "<div class='repayment-date'><span class='label'>日期:</span> {$repayment['repayment_date']}</div>";
|
|
|
+ $output .= "<div class='repayment-details'>";
|
|
|
+ $output .= "<div class='repayment-amount'><span class='label'>金额:</span> ¥{$repayment['repayment_amount']}</div>";
|
|
|
+ $output .= "<div class='repayment-method'><span class='label'>支付方式:</span> {$repayment['repayment_method']}</div>";
|
|
|
if (!empty($repayment['comments'])) {
|
|
|
- echo "<div class='repayment-comment'><span class='label'>备注:</span> {$repayment['comments']}</div>";
|
|
|
+ $output .= "<div class='repayment-comment'><span class='label'>备注:</span> {$repayment['comments']}</div>";
|
|
|
}
|
|
|
- echo "</div>";
|
|
|
- echo "</div>";
|
|
|
+ $output .= "</div>";
|
|
|
+ $output .= "</div>";
|
|
|
}
|
|
|
- echo "</div>";
|
|
|
+ $output .= "</div>";
|
|
|
} else {
|
|
|
- echo "<p class='no-repayments'>暂无还款记录</p>";
|
|
|
+ $output .= "<p class='no-repayments'>暂无还款记录</p>";
|
|
|
}
|
|
|
- echo "</div>";
|
|
|
- echo "</div>";
|
|
|
+ $output .= "</div>";
|
|
|
+ $output .= "</div>";
|
|
|
+
|
|
|
+ // 如果Redis可用,缓存结果
|
|
|
+ if ($REDIS_ENABLED) {
|
|
|
+ $redis->setex($cacheKey, 60, $output);
|
|
|
+ }
|
|
|
+
|
|
|
+ echo $output;
|
|
|
} else {
|
|
|
- echo "<div class='no-result'><i class='fas fa-exclamation-circle'></i> 未找到相关记录</div>";
|
|
|
+ echo "<p class='no-result'>未找到相关记录</p>";
|
|
|
}
|
|
|
-} else {
|
|
|
- echo "<div class='no-input'><i class='fas fa-info-circle'></i> 请输入姓名进行查询</div>";
|
|
|
}
|
|
|
?>
|