From 3f45e8fdfa31d7b764d60a7c0cb5dd11944ed418 Mon Sep 17 00:00:00 2001
From: 刘帅 <rr.iii@qq.com>
Date: 星期一, 21 九月 2026 23:38:59 +0800
Subject: [PATCH] bug:统计数据修正

---
 cloud-server-management/src/main/webapp/WEB-INF/view/system/dataStatistics/platformIncome.html |  117 ++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 73 insertions(+), 44 deletions(-)

diff --git a/cloud-server-management/src/main/webapp/WEB-INF/view/system/dataStatistics/platformIncome.html b/cloud-server-management/src/main/webapp/WEB-INF/view/system/dataStatistics/platformIncome.html
index 7dd965b..3d72dee 100644
--- a/cloud-server-management/src/main/webapp/WEB-INF/view/system/dataStatistics/platformIncome.html
+++ b/cloud-server-management/src/main/webapp/WEB-INF/view/system/dataStatistics/platformIncome.html
@@ -350,6 +350,17 @@
 <script src="${ctxPath}/modular/system/dataStatistics/echarts.min.js"></script>
 <script src="${ctxPath}/static/js/plugins/switchery/switchery.js"></script>
 <script>
+    // 仅格式化前端展示,接口返回的原始数值不作改动。
+    function formatStatisticNumber(value) {
+        var number = Number(value);
+        return isFinite(number) ? number.toFixed(2) : '0.00';
+    }
+    // 首次进入页面时,收入类型来自服务端模板变量;同样按两位小数展示。
+    $(function () {
+        $('#fee1, #fee2, #fee3, #fee4, #fee5, #fee7').each(function () {
+            $(this).text(formatStatisticNumber($(this).text()));
+        });
+    });
 	laydate.render({
 		elem: '#beginTime'
 		, trigger: 'click'
@@ -359,18 +370,20 @@
         var time =  $("#beginTime").val();
         // 营收卡片与收入类型卡片使用同一接口、同一时间范围,避免筛选后口径不一致。
         var incomeAjax = new $ax(Feng.ctxPath + "/data/getIncomeData", function(resp){
-            $("#totalIncome").text(resp.incomeStatistics.totalIncomeAmount || 0);
-            $("#netIncomeAmount").text(resp.incomeStatistics.netIncomeAmount || 0);
-            $("#couponDeductionAmount").text(resp.incomeStatistics.couponDeductionAmount || 0);
-            $("#refundAmount").text(resp.incomeStatistics.refundAmount || 0);
+            $("#totalIncome").text(formatStatisticNumber(resp.incomeStatistics.totalIncomeAmount));
+            $("#netIncomeAmount").text(formatStatisticNumber(resp.incomeStatistics.netIncomeAmount));
+            $("#couponDeductionAmount").text(formatStatisticNumber(resp.incomeStatistics.couponDeductionAmount));
+            $("#refundAmount").text(formatStatisticNumber(resp.incomeStatistics.refundAmount));
             var incomeTypeNet = resp.incomeTypeNet || {};
-            $("#fee1").text(incomeTypeNet[1] || 0);
-            $("#fee2").text(incomeTypeNet[2] || 0);
-            $("#fee3").text(incomeTypeNet[3] || 0);
-            $("#fee4").text(incomeTypeNet[4] || 0);
-            $("#fee5").text(incomeTypeNet[5] || 0);
-            $("#fee7").text(incomeTypeNet[6] || 0);
+            $("#fee1").text(formatStatisticNumber(incomeTypeNet[1]));
+            $("#fee2").text(formatStatisticNumber(incomeTypeNet[2]));
+            $("#fee3").text(formatStatisticNumber(incomeTypeNet[3]));
+            $("#fee4").text(formatStatisticNumber(incomeTypeNet[4]));
+            $("#fee5").text(formatStatisticNumber(incomeTypeNet[5]));
+            $("#fee7").text(formatStatisticNumber(incomeTypeNet[6]));
             renderTicketIncomeChart(resp.ticketIncome || {});
+            renderIncomeTypePieChart('cookieCourse', '课程收入', resp.courseData);
+            renderIncomeTypePieChart('cookieBooking', '订场收入', resp.siteData);
         });
         incomeAjax.set("time", time);
         incomeAjax.start();
@@ -399,6 +412,17 @@
             }]
         }, true);
     }
+
+    function renderIncomeTypePieChart(elementId, title, data) {
+        var chartDom = document.getElementById(elementId);
+        var chart = echarts.getInstanceByDom(chartDom) || echarts.init(chartDom);
+        chart.setOption({
+            title: {text: title, left: 'center'},
+            tooltip: {trigger: 'item'},
+            series: [{name: title, type: 'pie', radius: '50%', data: data || []}]
+        }, true);
+    }
+
     // 创建一个日期对象
     var currentDate = new Date();
     // 获取当前日期的号数
@@ -432,18 +456,18 @@
 
     function renderIncomeStatistics(elementId, periodName, statistics) {
         document.getElementById(elementId).innerText = periodName + "统计:总营收金额 "
-            + statistics.totalIncomeAmount + ",净收入金额 " + statistics.netIncomeAmount
-            + ",优惠券抵扣金额 " + statistics.couponDeductionAmount + ",退款金额 "
-            + statistics.refundAmount;
+            + formatStatisticNumber(statistics.totalIncomeAmount) + ",净收入金额 " + formatStatisticNumber(statistics.netIncomeAmount)
+            + ",优惠券抵扣金额 " + formatStatisticNumber(statistics.couponDeductionAmount) + ",退款金额 "
+            + formatStatisticNumber(statistics.refundAmount);
     }
 
     function renderIncomeStatisticsList(elementId, title, labels, statistics) {
         var records = labels.map(function (label, index) {
             var item = statistics[index];
             return '<div class="income-period-record"><strong>' + label + '</strong>:总营收金额 '
-                + item.totalIncomeAmount + ',净收入金额 ' + item.netIncomeAmount
-                + ',优惠券抵扣金额 ' + item.couponDeductionAmount
-                + ',退款金额 ' + item.refundAmount + '</div>';
+                + formatStatisticNumber(item.totalIncomeAmount) + ',净收入金额 ' + formatStatisticNumber(item.netIncomeAmount)
+                + ',优惠券抵扣金额 ' + formatStatisticNumber(item.couponDeductionAmount)
+                + ',退款金额 ' + formatStatisticNumber(item.refundAmount) + '</div>';
         }).join('');
         document.getElementById(elementId).innerHTML = '<div class="income-period-title">' + title
             + '</div><div class="income-period-records">' + records + '</div>';
@@ -458,10 +482,10 @@
                 formatter: function (params) {
                     var item = params[0];
                     var detail = statistics[item.dataIndex];
-                    return labels[item.dataIndex] + '<br/>总营收:' + detail.totalIncomeAmount
-                        + '<br/>净收入:' + detail.netIncomeAmount
-                        + '<br/>优惠券抵扣:' + detail.couponDeductionAmount
-                        + '<br/>退款:' + detail.refundAmount;
+                    return labels[item.dataIndex] + '<br/>总营收:' + formatStatisticNumber(detail.totalIncomeAmount)
+                        + '<br/>净收入:' + formatStatisticNumber(detail.netIncomeAmount)
+                        + '<br/>优惠券抵扣:' + formatStatisticNumber(detail.couponDeductionAmount)
+                        + '<br/>退款:' + formatStatisticNumber(detail.refundAmount);
                 }
             },
             grid: {left: '5%', right: '4%', bottom: '18%', containLabel: true},
@@ -539,10 +563,10 @@
             var netIncomeAmount = document.getElementById("netIncomeAmount");
             var couponDeductionAmount = document.getElementById("couponDeductionAmount");
             var refundAmount = document.getElementById("refundAmount");
-            t1.innerText = list[0] || 0;
-            netIncomeAmount.innerText = resp.incomeStatistics.netIncomeAmount || 0;
-            couponDeductionAmount.innerText = resp.incomeStatistics.couponDeductionAmount || 0;
-            refundAmount.innerText = resp.incomeStatistics.refundAmount || 0;
+            t1.innerText = formatStatisticNumber(list[0]);
+            netIncomeAmount.innerText = formatStatisticNumber(resp.incomeStatistics.netIncomeAmount);
+            couponDeductionAmount.innerText = formatStatisticNumber(resp.incomeStatistics.couponDeductionAmount);
+            refundAmount.innerText = formatStatisticNumber(resp.incomeStatistics.refundAmount);
             renderIncomeStatisticsList("yearIncomeStatistics", "历年营收明细", resp.yearLabels, resp.yearIncomeStatistics);
             renderIncomeStatisticsList("monthIncomeStatistics", "本年各月营收明细", resp.monthLabels, resp.monthIncomeStatistics);
             renderIncomeStatisticsList("weekIncomeStatistics", "近四周营收明细", resp.weekLabels, resp.weekIncomeStatistics);
@@ -551,11 +575,14 @@
             renderIncomeTrendChart("incomeMonthChart", "本年各月营收趋势", resp.monthLabels, resp.monthIncomeStatistics);
             renderIncomeTrendChart("incomeWeekChart", "近四周营收趋势", resp.weekLabels, resp.weekIncomeStatistics);
             renderIncomeTrendChart("incomeDayChart", "近七日营收趋势", resp.dayLabels, resp.dayIncomeStatistics);
-            $("#back1").text(resp.yearIncomeStatistics[resp.yearIncomeStatistics.length - 1].refundAmount || 0);
-            $("#back2").text(resp.monthIncomeStatistics[new Date().getMonth()].refundAmount || 0);
-            $("#back3").text(resp.weekIncomeStatistics[resp.weekIncomeStatistics.length - 1].refundAmount || 0);
-            $("#back4").text(resp.dayIncomeStatistics[resp.dayIncomeStatistics.length - 1].refundAmount || 0);
+            $("#back1").text(formatStatisticNumber(resp.yearIncomeStatistics[resp.yearIncomeStatistics.length - 1].refundAmount));
+            $("#back2").text(formatStatisticNumber(resp.monthIncomeStatistics[new Date().getMonth()].refundAmount));
+            $("#back3").text(formatStatisticNumber(resp.weekIncomeStatistics[resp.weekIncomeStatistics.length - 1].refundAmount));
+            $("#back4").text(formatStatisticNumber(resp.dayIncomeStatistics[resp.dayIncomeStatistics.length - 1].refundAmount));
             renderRefundChart(myChart1, resp);
+            renderTicketIncomeChart(resp.ticketIncome || {});
+            renderIncomeTypePieChart('cookieCourse', '课程收入', resp.courseData);
+            renderIncomeTypePieChart('cookieBooking', '订场收入', resp.siteData);
         });
         ajax.set("type",1);
         ajax.start();
@@ -1476,15 +1503,16 @@
         courseData = courseData.split('},')
 
         var a=[];
-        for (let j = 0; j <courseData.length; j++) {
-            if(j<courseData.length-1){
-                var d = courseData[j].replace("{","").replace("}","").split(",")
-                    let obj ={
-                        name:d[0].split("=")[1],
-                        value:d[1].split("=")[1]
-                    }
-                    a.push(obj)
+        for (let j = 0; j < courseData.length; j++) {
+            var d = courseData[j].replace("{", "").replace("}", "").split(",");
+            if (d.length < 2) {
+                continue;
             }
+            let obj = {
+                name: d[0].split("=")[1],
+                value: d[1].split("=")[1]
+            };
+            a.push(obj);
         }
         var chartDom = document.getElementById('cookieCourse');
         var myChart = echarts.init(chartDom)
@@ -1525,15 +1553,16 @@
         courseData = courseData.split('},')
 
         var a=[];
-        for (let j = 0; j <courseData.length; j++) {
-            if(j<courseData.length-1){
-                var d = courseData[j].replace("{","").replace("}","").split(",")
-                let obj ={
-                    name:d[0].split("=")[1],
-                    value:d[1].split("=")[1]
-                }
-                a.push(obj)
+        for (let j = 0; j < courseData.length; j++) {
+            var d = courseData[j].replace("{", "").replace("}", "").split(",");
+            if (d.length < 2) {
+                continue;
             }
+            let obj = {
+                name: d[0].split("=")[1],
+                value: d[1].split("=")[1]
+            };
+            a.push(obj);
         }
         var chartDom = document.getElementById('cookieBooking');
         var myChart = echarts.init(chartDom);

--
Gitblit v1.7.1