| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- 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);
- if ($debtor) {
- // 获取还款记录
- $repaymentStmt = $pdo->prepare("SELECT * FROM Repayments WHERE debtor_name = :debtorName ORDER BY repayment_date DESC");
- $repaymentStmt->execute(['debtorName' => $debtorName]);
- $repayments = $repaymentStmt->fetchAll(PDO::FETCH_ASSOC);
- // 获取视图中的欠款信息
- $viewStmt = $pdo->prepare("SELECT * FROM DebtStatus WHERE 姓名 = :debtorName");
- $viewStmt->execute(['debtorName' => $debtorName]);
- $viewData = $viewStmt->fetch(PDO::FETCH_ASSOC);
- // 构建输出
- $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>";
- $output .= "<div class='repayment-section'>";
- $output .= "<h3>还款记录</h3>";
- if ($repayments) {
- $output .= "<div class='repayment-list'>";
- foreach ($repayments as $repayment) {
- $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'])) {
- $output .= "<div class='repayment-comment'><span class='label'>备注:</span> {$repayment['comments']}</div>";
- }
- $output .= "</div>";
- $output .= "</div>";
- }
- $output .= "</div>";
- } else {
- $output .= "<p class='no-repayments'>暂无还款记录</p>";
- }
- $output .= "</div>";
- $output .= "</div>";
- // 如果Redis可用,缓存结果
- if ($REDIS_ENABLED) {
- $redis->setex($cacheKey, 60, $output);
- }
- echo $output;
- } else {
- echo "<p class='no-result'>未找到相关记录</p>";
- }
- }
- ?>
|