|
@@ -319,7 +319,7 @@ include('statistics_header.php');
|
|
|
</div>
|
|
|
|
|
|
<!-- 订单金额下降客户列表 -->
|
|
|
- <div class="warning-section">
|
|
|
+ <div class="warning-section" id="decreasing-customers">
|
|
|
<div class="section-header">
|
|
|
<h2>订单金额下降客户</h2>
|
|
|
<p>与上一周期相比,订单金额显著下降的客户</p>
|
|
@@ -328,6 +328,7 @@ include('statistics_header.php');
|
|
|
<table class="data-table">
|
|
|
<thead>
|
|
|
<tr>
|
|
|
+ <th>客户编码</th>
|
|
|
<th>本期订单金额</th>
|
|
|
<th>上期订单金额</th>
|
|
|
<th>变化百分比</th>
|
|
@@ -338,6 +339,30 @@ include('statistics_header.php');
|
|
|
</thead>
|
|
|
<tbody>
|
|
|
<?php
|
|
|
+ // 获取分页参数
|
|
|
+ $decreasing_page = isset($_GET['decreasing_page']) ? intval($_GET['decreasing_page']) : 1;
|
|
|
+ $decreasing_page_size = 10; // 每页显示10条记录
|
|
|
+
|
|
|
+ // 获取总记录数
|
|
|
+ $total_decreasing = getDecreasingOrderAmountCustomers(
|
|
|
+ $conn,
|
|
|
+ $current_start_date,
|
|
|
+ $current_end_date,
|
|
|
+ $previous_start_date,
|
|
|
+ $previous_end_date,
|
|
|
+ $order_amount_decrease_threshold,
|
|
|
+ true,
|
|
|
+ $query_employee_filter
|
|
|
+ );
|
|
|
+
|
|
|
+ // 计算总页数
|
|
|
+ $decreasing_total_pages = ceil($total_decreasing / $decreasing_page_size);
|
|
|
+
|
|
|
+ // 确保页码合法
|
|
|
+ if ($decreasing_page < 1) $decreasing_page = 1;
|
|
|
+ if ($decreasing_page > $decreasing_total_pages && $decreasing_total_pages > 0) $decreasing_page = $decreasing_total_pages;
|
|
|
+
|
|
|
+ // 获取当页数据
|
|
|
$decreasing_customers = getDecreasingOrderAmountCustomers(
|
|
|
$conn,
|
|
|
$current_start_date,
|
|
@@ -346,7 +371,9 @@ include('statistics_header.php');
|
|
|
$previous_end_date,
|
|
|
$order_amount_decrease_threshold,
|
|
|
false,
|
|
|
- $query_employee_filter
|
|
|
+ $query_employee_filter,
|
|
|
+ $decreasing_page,
|
|
|
+ $decreasing_page_size
|
|
|
);
|
|
|
|
|
|
while ($customer = $decreasing_customers->fetch_assoc()) {
|
|
@@ -354,6 +381,7 @@ include('statistics_header.php');
|
|
|
$change_class = $change_percent < -20 ? 'text-danger' : 'text-warning';
|
|
|
|
|
|
echo "<tr>";
|
|
|
+ echo "<td title='{$customer['cs_code']}'>" . htmlspecialcharsFix($customer['cs_code']) . "</td>";
|
|
|
echo "<td>¥" . number_format($customer['current_amount'], 2) . "</td>";
|
|
|
echo "<td>¥" . number_format($customer['previous_amount'], 2) . "</td>";
|
|
|
echo "<td class='{$change_class}'>" . $change_percent . "%</td>";
|
|
@@ -364,11 +392,71 @@ include('statistics_header.php');
|
|
|
}
|
|
|
|
|
|
if ($decreasing_customers->num_rows == 0) {
|
|
|
- echo "<tr><td colspan='6' class='text-center'>没有发现订单金额下降的客户</td></tr>";
|
|
|
+ echo "<tr><td colspan='7' class='text-center'>没有发现订单金额下降的客户</td></tr>";
|
|
|
}
|
|
|
?>
|
|
|
</tbody>
|
|
|
</table>
|
|
|
+
|
|
|
+ <!-- 分页控件 -->
|
|
|
+ <?php if ($decreasing_total_pages > 1): ?>
|
|
|
+ <div class="pagination-container">
|
|
|
+ <ul class="pagination">
|
|
|
+ <?php
|
|
|
+ // 生成分页链接的基础URL
|
|
|
+ $base_url = '?';
|
|
|
+ foreach ($_GET as $key => $value) {
|
|
|
+ if ($key != 'decreasing_page') {
|
|
|
+ $base_url .= $key . '=' . urlencode($value) . '&';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 上一页链接
|
|
|
+ if ($decreasing_page > 1) {
|
|
|
+ echo "<li class='pager-item'><a class='pager-link' href='{$base_url}decreasing_page=" . ($decreasing_page - 1) . "#decreasing-customers'>上一页</a></li>";
|
|
|
+ } else {
|
|
|
+ echo "<li class='pager-item disabled'><a class='pager-link' href='#decreasing-customers'>上一页</a></li>";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 页码链接
|
|
|
+ $start_page = max(1, $decreasing_page - 2);
|
|
|
+ $end_page = min($decreasing_total_pages, $decreasing_page + 2);
|
|
|
+
|
|
|
+ if ($start_page > 1) {
|
|
|
+ echo "<li class='pager-item'><a class='pager-link' href='{$base_url}decreasing_page=1#decreasing-customers'>1</a></li>";
|
|
|
+ if ($start_page > 2) {
|
|
|
+ echo "<li class='pager-item disabled'><a class='pager-link' href='#decreasing-customers'>...</a></li>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for ($i = $start_page; $i <= $end_page; $i++) {
|
|
|
+ if ($i == $decreasing_page) {
|
|
|
+ echo "<li class='pager-item active'><a class='pager-link' href='#decreasing-customers'>{$i}</a></li>";
|
|
|
+ } else {
|
|
|
+ echo "<li class='pager-item'><a class='pager-link' href='{$base_url}decreasing_page={$i}#decreasing-customers'>{$i}</a></li>";
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($end_page < $decreasing_total_pages) {
|
|
|
+ if ($end_page < $decreasing_total_pages - 1) {
|
|
|
+ echo "<li class='pager-item disabled'><a class='pager-link' href='#decreasing-customers'>...</a></li>";
|
|
|
+ }
|
|
|
+ echo "<li class='pager-item'><a class='pager-link' href='{$base_url}decreasing_page={$decreasing_total_pages}#decreasing-customers'>{$decreasing_total_pages}</a></li>";
|
|
|
+ }
|
|
|
+
|
|
|
+ // 下一页链接
|
|
|
+ if ($decreasing_page < $decreasing_total_pages) {
|
|
|
+ echo "<li class='pager-item'><a class='pager-link' href='{$base_url}decreasing_page=" . ($decreasing_page + 1) . "#decreasing-customers'>下一页</a></li>";
|
|
|
+ } else {
|
|
|
+ echo "<li class='pager-item disabled'><a class='pager-link' href='#decreasing-customers'>下一页</a></li>";
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ </ul>
|
|
|
+ <div class="pagination-info">
|
|
|
+ 共 <?php echo $total_decreasing; ?> 条记录,当前显示第 <?php echo $decreasing_page; ?> 页,共 <?php echo $decreasing_total_pages; ?> 页
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <?php endif; ?>
|
|
|
</div>
|
|
|
|
|
|
<!-- 复购周期异常客户列表 -->
|
|
@@ -1139,7 +1227,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
|
/**
|
|
|
* 获取订单金额下降的客户
|
|
|
*/
|
|
|
-function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end, $previous_start, $previous_end, $threshold, $count_only = false, $selected_employee = 0) {
|
|
|
+function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end, $previous_start, $previous_end, $threshold, $count_only = false, $selected_employee = 0, $page = 1, $page_size = 10) {
|
|
|
// 构建业务员筛选条件
|
|
|
$employee_filter = "";
|
|
|
if (!empty($selected_employee)) {
|
|
@@ -1178,10 +1266,14 @@ function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end,
|
|
|
return $row['count'];
|
|
|
}
|
|
|
|
|
|
+ // 计算分页
|
|
|
+ $offset = ($page - 1) * $page_size;
|
|
|
+
|
|
|
// 如果需要详细数据
|
|
|
$sql = "SELECT
|
|
|
c.id,
|
|
|
c.cs_company,
|
|
|
+ c.cs_code,
|
|
|
IFNULL(current_period.amount, 0) as current_amount,
|
|
|
previous_period.amount as previous_amount,
|
|
|
e.em_user,
|
|
@@ -1200,10 +1292,17 @@ function getDecreasingOrderAmountCustomers($conn, $current_start, $current_end,
|
|
|
GROUP BY customer_id
|
|
|
) previous_period ON c.id = previous_period.customer_id
|
|
|
JOIN employee e ON c.cs_belong = e.id
|
|
|
+ LEFT JOIN (
|
|
|
+ SELECT customer_id, MAX(order_date) as last_order_date
|
|
|
+ FROM orders
|
|
|
+ WHERE is_deleted = 0
|
|
|
+ GROUP BY customer_id
|
|
|
+ ) last_order ON c.id = last_order.customer_id
|
|
|
WHERE previous_period.amount > 0
|
|
|
AND (current_period.amount IS NULL OR (current_period.amount / previous_period.amount - 1) * 100 <= {$threshold})
|
|
|
AND c.cs_deal = 3{$employee_filter}
|
|
|
- ORDER BY (current_period.amount / previous_period.amount) ASC";
|
|
|
+ ORDER BY last_order.last_order_date DESC
|
|
|
+ LIMIT {$offset}, {$page_size}";
|
|
|
|
|
|
return $conn->query($sql);
|
|
|
}
|