123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- /**
- * 产品统计分析展示页面
- */
- require_once 'conn.php';
- require_once 'statistics_utils.php';
- require_once 'statistics_products.php';
- // 检查登录状态
- if (!isset($_SESSION['employee_id'])) {
- checkLogin();
- }
- // 获取日期范围参数
- $date_params = getDateRangeParams();
- $start_date = $date_params['start_date_sql'];
- $end_date = $date_params['end_date_sql'];
- $date_range = $date_params['date_range'];
- $period = $date_params['period'];
- // 特定产品过滤
- $product_id = isset($_GET['product_id']) ? intval($_GET['product_id']) : 0;
- // 页面头部
- include('header.php');
- ?>
- <div class="container-fluid px-4">
- <h1 class="mt-4">产品统计分析</h1>
- <ol class="breadcrumb mb-4">
- <li class="breadcrumb-item"><a href="index.php">控制台</a></li>
- <li class="breadcrumb-item active">产品统计</li>
- </ol>
-
- <!-- 日期筛选 -->
- <div class="card mb-4">
- <div class="card-header">
- <i class="fas fa-filter me-1"></i>
- 日期范围筛选
- </div>
- <div class="card-body">
- <form method="get" class="row g-3">
- <div class="col-md-3">
- <label for="date_range" class="form-label">选择日期范围</label>
- <select class="form-select" id="date_range" name="date_range" onchange="toggleCustomDates()">
- <option value="current_month" <?php echo $date_range == 'current_month' ? 'selected' : ''; ?>>本月</option>
- <option value="last_month" <?php echo $date_range == 'last_month' ? 'selected' : ''; ?>>上月</option>
- <option value="current_year" <?php echo $date_range == 'current_year' ? 'selected' : ''; ?>>今年</option>
- <option value="last_30_days" <?php echo $date_range == 'last_30_days' ? 'selected' : ''; ?>>最近30天</option>
- <option value="last_90_days" <?php echo $date_range == 'last_90_days' ? 'selected' : ''; ?>>最近90天</option>
- <option value="custom" <?php echo $date_range == 'custom' ? 'selected' : ''; ?>>自定义日期范围</option>
- </select>
- </div>
- <div class="col-md-2 custom-date" style="display: <?php echo $date_range == 'custom' ? 'block' : 'none'; ?>">
- <label for="start_date" class="form-label">开始日期</label>
- <input type="date" class="form-control" id="start_date" name="start_date" value="<?php echo $date_params['custom_start']; ?>">
- </div>
- <div class="col-md-2 custom-date" style="display: <?php echo $date_range == 'custom' ? 'block' : 'none'; ?>">
- <label for="end_date" class="form-label">结束日期</label>
- <input type="date" class="form-control" id="end_date" name="end_date" value="<?php echo $date_params['custom_end']; ?>">
- </div>
- <div class="col-md-3">
- <label for="period" class="form-label">时间粒度</label>
- <select class="form-select" id="period" name="period">
- <option value="day" <?php echo $period == 'day' ? 'selected' : ''; ?>>日</option>
- <option value="week" <?php echo $period == 'week' ? 'selected' : ''; ?>>周</option>
- <option value="month" <?php echo $period == 'month' ? 'selected' : ''; ?>>月</option>
- </select>
- </div>
- <div class="col-md-2 d-flex align-items-end">
- <button type="submit" class="btn btn-primary">应用筛选</button>
- </div>
- </form>
- </div>
- </div>
-
- <div class="row">
- <!-- 热门产品 -->
- <div class="col-lg-12 mb-4">
- <div class="card">
- <?php
- $top_products = getTopProducts($conn, $start_date, $end_date, 10);
- renderTopProductsTable($top_products);
- ?>
- </div>
- </div>
- </div>
-
- <div class="row">
- <!-- 产品销售趋势 -->
- <div class="col-lg-12 mb-4">
- <div class="card">
- <?php
- $product_trends = getProductSalesTrend($conn, $start_date, $end_date, $product_id, $period);
-
- $time_labels = [];
- $quantities = [];
- $revenues = [];
-
- while ($row = $product_trends->fetch_assoc()) {
- $time_labels[] = $row['time_period'];
- $quantities[] = $row['total_quantity'];
- $revenues[] = $row['total_revenue'];
- }
- renderProductSalesTrendChart($time_labels, $quantities, $revenues);
- ?>
- </div>
- </div>
- </div>
-
- <div class="row">
- <!-- 产品类别销售分布 -->
- <div class="col-lg-12 mb-4">
- <div class="card">
- <?php
- $category_sales = getProductCategorySales($conn, $start_date, $end_date);
-
- $categories = [];
- $category_quantities = [];
- $category_revenues = [];
-
- while ($row = $category_sales->fetch_assoc()) {
- $categories[] = $row['category_name'];
- $category_quantities[] = $row['total_quantity'];
- $category_revenues[] = $row['total_revenue'];
- }
- renderProductCategorySalesChart($categories, $category_quantities, $category_revenues);
- ?>
- </div>
- </div>
- </div>
-
- <div class="row">
- <!-- 产品地区关联分析 -->
- <div class="col-lg-12 mb-4">
- <div class="card">
- <?php
- $product_region_data = getProductRegionAnalysis($conn, $start_date, $end_date);
- renderProductRegionAnalysisTable($product_region_data);
- ?>
- </div>
- </div>
- </div>
- </div>
- <script>
- function toggleCustomDates() {
- const dateRange = document.getElementById('date_range').value;
- const customDates = document.querySelectorAll('.custom-date');
-
- if (dateRange === 'custom') {
- customDates.forEach(el => el.style.display = 'block');
- } else {
- customDates.forEach(el => el.style.display = 'none');
- }
- }
- </script>
- <?php
- // 页面底部
- include('footer.php');
- ?>
|