|
@@ -89,109 +89,32 @@ include('statistics_header.php');
|
|
|
renderKeyMetricsCard($kpi_data);
|
|
|
?>
|
|
|
</div>
|
|
|
- <div class="stats-grid" style="display: none;">
|
|
|
- <!-- 客户类型分布 -->
|
|
|
- <div class="stat-card">
|
|
|
- <?php
|
|
|
- $customer_type_result = getCustomerTypeDistribution($conn);
|
|
|
- $type_labels = [];
|
|
|
- $type_data = [];
|
|
|
-
|
|
|
- while ($row = $customer_type_result->fetch_assoc()) {
|
|
|
- $type_labels[] = $row['businessType'];
|
|
|
- $type_data[] = $row['customer_count'];
|
|
|
- }
|
|
|
- renderCustomerTypeChart($type_labels, $type_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 成交阶段分布 -->
|
|
|
- <div class="stat-card">
|
|
|
- <?php
|
|
|
- $deal_stage_result = getDealStageDistribution($conn);
|
|
|
- $stage_labels = [];
|
|
|
- $stage_data = [];
|
|
|
-
|
|
|
- while ($row = $deal_stage_result->fetch_assoc()) {
|
|
|
- $stage_labels[] = $row['stage_name'];
|
|
|
- $stage_data[] = $row['customer_count'];
|
|
|
- }
|
|
|
- renderDealStageChart($stage_labels, $stage_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
|
|
|
- <!-- 客户增长趋势 -->
|
|
|
- <div class="chart-container" style="display:none;">
|
|
|
+ <!-- 新增客户列表 -->
|
|
|
+ <div class="customer-section">
|
|
|
+ <div class="section-title">
|
|
|
+ <h2>新增客户明细</h2>
|
|
|
+ </div>
|
|
|
<?php
|
|
|
- $growth_result = getCustomerGrowthTrend($conn);
|
|
|
- $growth_labels = [];
|
|
|
- $growth_data = [];
|
|
|
+ // 获取新增客户详细数据
|
|
|
+ $new_customers_details = getNewCustomersDetails($conn, $start_date, $end_date);
|
|
|
|
|
|
- while ($row = $growth_result->fetch_assoc()) {
|
|
|
- $growth_labels[] = $row['month'];
|
|
|
- $growth_data[] = $row['new_customers'];
|
|
|
- }
|
|
|
- renderCustomerGrowthChart($growth_labels, $growth_data);
|
|
|
+ // 渲染新增客户图表
|
|
|
+ renderNewCustomersChart($new_customers_details);
|
|
|
?>
|
|
|
</div>
|
|
|
|
|
|
- <!-- 新老客户分析 -->
|
|
|
- <div class="chart-container" style="display:none;">
|
|
|
- <?php
|
|
|
- $new_vs_returning = getNewVsReturningCustomerOrders($conn, $start_date, $end_date);
|
|
|
- renderNewVsReturningCustomersChart($new_vs_returning);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 客户价值分布 -->
|
|
|
- <div class="chart-container" style="display: none">
|
|
|
- <?php
|
|
|
- $value_distribution = getCustomerValueDistribution($conn, $start_date, $end_date);
|
|
|
- renderCustomerValueCharts($value_distribution);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 客户转化漏斗 -->
|
|
|
- <div class="chart-container" style="display: none">
|
|
|
- <?php
|
|
|
- $funnel_data = getCustomerConversionFunnel($conn, $start_date, $end_date);
|
|
|
- renderCustomerFunnelChart($funnel_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 客户活跃度分析 -->
|
|
|
- <div class="chart-container" style="display: none">
|
|
|
- <?php
|
|
|
- $activity_data = getCustomerActivityAnalysis($conn, $end_date);
|
|
|
- renderCustomerActivityChart($activity_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 客户流失风险分析 -->
|
|
|
- <div class="chart-container" style="display: none">
|
|
|
- <?php
|
|
|
- $risk_data = getCustomerChurnRiskAnalysis($conn, $end_date);
|
|
|
- renderCustomerChurnRiskChart($risk_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 客户来源分析 -->
|
|
|
- <div class="chart-container" style="display: none">
|
|
|
- <?php
|
|
|
- $source_data = getCustomerSourceAnalysis($conn);
|
|
|
- renderCustomerSourceChart($source_data);
|
|
|
- ?>
|
|
|
- </div>
|
|
|
-
|
|
|
- <!-- 销售转化率分析 -->
|
|
|
- <div class="chart-container">
|
|
|
- <div class="chart-header">
|
|
|
- <h2 class="chart-title">销售转化率分析</h2>
|
|
|
+ <!-- 业务员新增客户统计 -->
|
|
|
+ <div class="employee-section">
|
|
|
+ <div class="section-title">
|
|
|
+ <h2>业务员新增客户统计</h2>
|
|
|
</div>
|
|
|
<?php
|
|
|
- $conversion_stats = getOrderConversionStats($conn, $start_date, $end_date);
|
|
|
- renderConversionAnalysis($conversion_stats);
|
|
|
+ // 获取各业务员新增客户数据
|
|
|
+ $employee_new_customers = getNewCustomersByEmployee($conn, $start_date, $end_date);
|
|
|
+
|
|
|
+ // 渲染业务员新增客户图表
|
|
|
+ renderNewCustomersByEmployeeChart($employee_new_customers);
|
|
|
?>
|
|
|
</div>
|
|
|
</div>
|
|
@@ -212,4 +135,285 @@ function toggleCustomDates() {
|
|
|
<?php
|
|
|
// 页面底部
|
|
|
include('statistics_footer.php');
|
|
|
-?>
|
|
|
+?>
|
|
|
+
|
|
|
+<?php
|
|
|
+/**
|
|
|
+ * 获取新增客户详细信息
|
|
|
+ *
|
|
|
+ * @param mysqli $conn 数据库连接
|
|
|
+ * @param string $start_date 开始日期
|
|
|
+ * @param string $end_date 结束日期
|
|
|
+ * @return array 新增客户详细数据
|
|
|
+ */
|
|
|
+function getNewCustomersDetails($conn, $start_date, $end_date) {
|
|
|
+ $sql = "SELECT
|
|
|
+ c.id,
|
|
|
+ c.cs_company as company_name,
|
|
|
+ c.cs_code as customer_code,
|
|
|
+ co.countryName as country,
|
|
|
+ ct.businessType as customer_type,
|
|
|
+ e.em_user as employee_name,
|
|
|
+ c.cs_addtime as add_date
|
|
|
+ FROM customer c
|
|
|
+ LEFT JOIN country co ON c.cs_country = co.id
|
|
|
+ LEFT JOIN clienttype ct ON c.cs_type = ct.id
|
|
|
+ LEFT JOIN employee e ON c.cs_belong = e.id
|
|
|
+ WHERE c.cs_addtime BETWEEN ? AND ?
|
|
|
+ ORDER BY c.cs_addtime DESC
|
|
|
+ LIMIT 30";
|
|
|
+
|
|
|
+ $stmt = $conn->prepare($sql);
|
|
|
+ $stmt->bind_param("ss", $start_date, $end_date);
|
|
|
+ $stmt->execute();
|
|
|
+
|
|
|
+ $result = $stmt->get_result();
|
|
|
+ $customers = [];
|
|
|
+
|
|
|
+ while ($row = $result->fetch_assoc()) {
|
|
|
+ $customers[] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $customers;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 获取各业务员新增客户统计
|
|
|
+ *
|
|
|
+ * @param mysqli $conn 数据库连接
|
|
|
+ * @param string $start_date 开始日期
|
|
|
+ * @param string $end_date 结束日期
|
|
|
+ * @return array 业务员新增客户统计数据
|
|
|
+ */
|
|
|
+function getNewCustomersByEmployee($conn, $start_date, $end_date) {
|
|
|
+ $sql = "SELECT
|
|
|
+ e.id as employee_id,
|
|
|
+ e.em_user as employee_name,
|
|
|
+ COUNT(c.id) as customer_count
|
|
|
+ FROM employee e
|
|
|
+ LEFT JOIN customer c ON e.id = c.cs_belong AND c.cs_addtime BETWEEN ? AND ?
|
|
|
+ WHERE e.em_role IS NOT NULL
|
|
|
+ GROUP BY e.id
|
|
|
+ ORDER BY customer_count DESC";
|
|
|
+
|
|
|
+ $stmt = $conn->prepare($sql);
|
|
|
+ $stmt->bind_param("ss", $start_date, $end_date);
|
|
|
+ $stmt->execute();
|
|
|
+
|
|
|
+ $result = $stmt->get_result();
|
|
|
+ $data = [];
|
|
|
+
|
|
|
+ while ($row = $result->fetch_assoc()) {
|
|
|
+ $data[] = $row;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 渲染新增客户图表
|
|
|
+ *
|
|
|
+ * @param array $customers 新增客户数据
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+function renderNewCustomersChart($customers) {
|
|
|
+ if (empty($customers)) {
|
|
|
+ echo '<div class="alert alert-info">该时间段内没有新增客户数据</div>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+ <div class="chart-container">
|
|
|
+ <div class="table-responsive">
|
|
|
+ <table class="data-table">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>客户名称</th>
|
|
|
+ <th>客户编码</th>
|
|
|
+ <th>国家/地区</th>
|
|
|
+ <th>客户类型</th>
|
|
|
+ <th>负责业务员</th>
|
|
|
+ <th>添加日期</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <?php foreach ($customers as $customer): ?>
|
|
|
+ <tr>
|
|
|
+ <td><?php echo htmlspecialchars($customer['company_name']); ?></td>
|
|
|
+ <td><?php echo htmlspecialchars($customer['customer_code']); ?></td>
|
|
|
+ <td><?php echo htmlspecialchars($customer['country']); ?></td>
|
|
|
+ <td><?php echo htmlspecialchars($customer['customer_type'] ?: '未分类'); ?></td>
|
|
|
+ <td><?php echo htmlspecialchars($customer['employee_name']); ?></td>
|
|
|
+ <td><?php echo date('Y-m-d', strtotime($customer['add_date'])); ?></td>
|
|
|
+ </tr>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 新增客户添加时间分布图 -->
|
|
|
+ <div class="chart-container">
|
|
|
+ <div>
|
|
|
+ <canvas id="newCustomersChart"></canvas>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <script>
|
|
|
+ // 准备图表数据
|
|
|
+ <?php
|
|
|
+ // 按日期分组客户数量
|
|
|
+ $dates = [];
|
|
|
+ $counts = [];
|
|
|
+ $dateGroups = [];
|
|
|
+
|
|
|
+ foreach ($customers as $customer) {
|
|
|
+ $date = date('Y-m-d', strtotime($customer['add_date']));
|
|
|
+ if (!isset($dateGroups[$date])) {
|
|
|
+ $dateGroups[$date] = 0;
|
|
|
+ }
|
|
|
+ $dateGroups[$date]++;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 排序日期
|
|
|
+ ksort($dateGroups);
|
|
|
+
|
|
|
+ foreach ($dateGroups as $date => $count) {
|
|
|
+ $dates[] = $date;
|
|
|
+ $counts[] = $count;
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+
|
|
|
+ var newCustomersCtx = document.getElementById('newCustomersChart').getContext('2d');
|
|
|
+ new Chart(newCustomersCtx, {
|
|
|
+ type: 'bar',
|
|
|
+ data: {
|
|
|
+ labels: <?php echo json_encode($dates); ?>,
|
|
|
+ datasets: [{
|
|
|
+ label: '新增客户数量',
|
|
|
+ data: <?php echo json_encode($counts); ?>,
|
|
|
+ backgroundColor: 'rgba(54, 162, 235, 0.5)',
|
|
|
+ borderColor: 'rgba(54, 162, 235, 1)',
|
|
|
+ borderWidth: 1
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ responsive: true,
|
|
|
+ scales: {
|
|
|
+ y: {
|
|
|
+ beginAtZero: true,
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: '客户数量'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ x: {
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: '日期'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins: {
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: '新增客户时间分布'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+ <?php
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 渲染业务员新增客户图表
|
|
|
+ *
|
|
|
+ * @param array $employee_data 业务员新增客户数据
|
|
|
+ * @return void
|
|
|
+ */
|
|
|
+function renderNewCustomersByEmployeeChart($employee_data) {
|
|
|
+ if (empty($employee_data)) {
|
|
|
+ echo '<div class="alert alert-info">该时间段内没有业务员新增客户数据</div>';
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 准备图表数据
|
|
|
+ $employee_names = [];
|
|
|
+ $customer_counts = [];
|
|
|
+
|
|
|
+ foreach ($employee_data as $row) {
|
|
|
+ $employee_names[] = $row['employee_name'];
|
|
|
+ $customer_counts[] = $row['customer_count'];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成图表背景色
|
|
|
+ $colors = generateChartColors(count($employee_data));
|
|
|
+ $backgroundColors = [];
|
|
|
+ $borderColors = [];
|
|
|
+
|
|
|
+ foreach ($colors as $color) {
|
|
|
+ $backgroundColors[] = $color[0];
|
|
|
+ $borderColors[] = $color[1];
|
|
|
+ }
|
|
|
+ ?>
|
|
|
+
|
|
|
+ <div class="analysis-grid">
|
|
|
+ <div>
|
|
|
+ <canvas id="employeeNewCustomersChart"></canvas>
|
|
|
+ </div>
|
|
|
+ <div class="table-responsive">
|
|
|
+ <table class="data-table">
|
|
|
+ <thead>
|
|
|
+ <tr>
|
|
|
+ <th>业务员</th>
|
|
|
+ <th>新增客户数量</th>
|
|
|
+ </tr>
|
|
|
+ </thead>
|
|
|
+ <tbody>
|
|
|
+ <?php foreach ($employee_data as $row): ?>
|
|
|
+ <tr>
|
|
|
+ <td><?php echo htmlspecialchars($row['employee_name']); ?></td>
|
|
|
+ <td><?php echo number_format($row['customer_count']); ?></td>
|
|
|
+ </tr>
|
|
|
+ <?php endforeach; ?>
|
|
|
+ </tbody>
|
|
|
+ </table>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <script>
|
|
|
+ var employeeNewCustomersCtx = document.getElementById('employeeNewCustomersChart').getContext('2d');
|
|
|
+ new Chart(employeeNewCustomersCtx, {
|
|
|
+ type: 'bar',
|
|
|
+ data: {
|
|
|
+ labels: <?php echo json_encode($employee_names); ?>,
|
|
|
+ datasets: [{
|
|
|
+ label: '新增客户数量',
|
|
|
+ data: <?php echo json_encode($customer_counts); ?>,
|
|
|
+ backgroundColor: <?php echo json_encode($backgroundColors); ?>,
|
|
|
+ borderColor: <?php echo json_encode($borderColors); ?>,
|
|
|
+ borderWidth: 1
|
|
|
+ }]
|
|
|
+ },
|
|
|
+ options: {
|
|
|
+ responsive: true,
|
|
|
+ scales: {
|
|
|
+ y: {
|
|
|
+ beginAtZero: true,
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: '客户数量'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ plugins: {
|
|
|
+ title: {
|
|
|
+ display: true,
|
|
|
+ text: '业务员新增客户统计'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ </script>
|
|
|
+ <?php
|
|
|
+}
|