diff --git a/app/admin/controller/Statistics.php b/app/admin/controller/Statistics.php index 9f67e36..b084652 100755 --- a/app/admin/controller/Statistics.php +++ b/app/admin/controller/Statistics.php @@ -620,7 +620,7 @@ class Statistics extends Base $productInfos = []; if (!empty($goodslistIds)) { $productInfos = GoodsList::where('id', 'in', $goodslistIds) - ->field('id, title, imgurl, price, money, sc_money, real_pro') + ->field('id, title, imgurl, price, money, sc_money, real_pro, shang_id') ->select() ->toArray(); } @@ -992,7 +992,7 @@ class Statistics extends Base $headers = [ 'ID', '盒子名称', '盒子类型', '状态', '单价', '抽奖次数', '收入(微信+钻石)', '出货价值', '已兑换达达卷', '已申请发货', - '利润', '利润率(%)' + '单盒子利润', '单盒子利润比(%)', '利润', '利润率(%)' ]; foreach ($headers as $col => $header) { @@ -1010,7 +1010,7 @@ class Statistics extends Base 'startColor' => ['rgb' => 'E0E0E0'], ], ]; - $sheet->getStyle('A1:L1')->applyFromArray($headerStyle); + $sheet->getStyle('A1:N1')->applyFromArray($headerStyle); // 填充数据 $row = 2; @@ -1027,6 +1027,14 @@ class Statistics extends Base default: $statusText = '自动下架'; break; } + // 计算单盒子利润和单盒子利润比 + $boxIncome = $item['price'] * $statsData['cj_count']; + $singleBoxProfit = $boxIncome - $statsData['sc_money']; + $singleBoxProfitRate = 0; + if ($boxIncome > 0) { + $singleBoxProfitRate = ($singleBoxProfit / $boxIncome) * 100; + } + // 填充一行数据 $sheet->setCellValue('A' . $row, $item['id']); $sheet->setCellValue('B' . $row, $item['title']); @@ -1038,12 +1046,14 @@ class Statistics extends Base $sheet->setCellValue('H' . $row, $statsData['sc_money']); $sheet->setCellValue('I' . $row, $statsData['re_money']); $sheet->setCellValue('J' . $row, $statsData['fh_money']); - $sheet->setCellValue('K' . $row, $statsData['profit']); - $sheet->setCellValue('L' . $row, $statsData['profit_rate']); + $sheet->setCellValue('K' . $row, $singleBoxProfit); + $sheet->setCellValue('L' . $row, round($singleBoxProfitRate, 2)); + $sheet->setCellValue('M' . $row, $statsData['profit']); + $sheet->setCellValue('N' . $row, $statsData['profit_rate']); // 设置负利润的行为红色背景 if ($statsData['profit'] < 0) { - $sheet->getStyle('A' . $row . ':L' . $row)->getFill() + $sheet->getStyle('A' . $row . ':N' . $row)->getFill() ->setFillType(Fill::FILL_SOLID) ->getStartColor()->setRGB('FFEBEE'); } @@ -1052,7 +1062,7 @@ class Statistics extends Base } // 调整列宽 - foreach (range('A', 'L') as $col) { + foreach (range('A', 'N') as $col) { $sheet->getColumnDimension($col)->setAutoSize(true); } @@ -1066,14 +1076,25 @@ class Statistics extends Base $sheet->setCellValue('H' . $row, $summaryData['totalCost']); $sheet->setCellValue('I' . $row, $summaryData['totalReMoney']); $sheet->setCellValue('J' . $row, $summaryData['totalFhMoney']); - $sheet->setCellValue('K' . $row, $summaryData['totalProfit']); + + // 计算汇总单盒子利润和利润比 + $totalSingleBoxProfit = $summaryData['totalIncome'] - $summaryData['totalCost']; + $sheet->setCellValue('K' . $row, $totalSingleBoxProfit); + + $totalSingleBoxProfitRate = 0; + if ($summaryData['totalIncome'] > 0) { + $totalSingleBoxProfitRate = ($totalSingleBoxProfit / $summaryData['totalIncome']) * 100; + } + $sheet->setCellValue('L' . $row, round($totalSingleBoxProfitRate, 2)); + + $sheet->setCellValue('M' . $row, $summaryData['totalProfit']); // 计算总体利润率 $profitRate = 0; if ($summaryData['totalIncome'] > 0) { $profitRate = ($summaryData['totalProfit'] / $summaryData['totalIncome']) * 100; } - $sheet->setCellValue('L' . $row, round($profitRate, 2)); + $sheet->setCellValue('N' . $row, round($profitRate, 2)); // 设置汇总行样式 $summaryStyle = [ @@ -1083,7 +1104,7 @@ class Statistics extends Base 'startColor' => ['rgb' => ($summaryData['totalProfit'] >= 0 ? 'E8F5E9' : 'FFEBEE')], ], ]; - $sheet->getStyle('A' . $row . ':L' . $row)->applyFromArray($summaryStyle); + $sheet->getStyle('A' . $row . ':N' . $row)->applyFromArray($summaryStyle); // 设置Excel文件属性 $spreadsheet->getProperties() diff --git a/app/admin/view/Statistics/productsOverview.html b/app/admin/view/Statistics/productsOverview.html index 8f74b6f..7a4c779 100644 --- a/app/admin/view/Statistics/productsOverview.html +++ b/app/admin/view/Statistics/productsOverview.html @@ -15,21 +15,108 @@ $totalValue = 0; foreach($list as $item) { $totalCount += isset($item['goods_count']) ? $item['goods_count'] : 0; - $sc_money = isset($item['sc_money']) ? $item['sc_money'] : 0; + $money = isset($item['money']) ? $item['money'] : 0; $goods_count = isset($item['goods_count']) ? $item['goods_count'] : 0; - $totalValue += $sc_money * $goods_count; + $totalValue += $money * $goods_count; } ?> + + + {if condition="!empty($list)"} +
+
统计摘要
+
+
+
+
+
总出货数量
+
+ {$totalCount} +
+
+
+
+
+
总出货价值
+
+ ¥ {$totalValue|round=2} +
+
+
+
+ + 0): ?> +
+
+
+
平均每次出货价值/盒子单价
+
+ ¥ / + +
+
+
+
+
+
平均出货价值/盒子单价
+
+ 0 ? round(($avgValue / $boxPrice), 2) : 0; + echo $ratio . ' 倍'; + ?> +
+
+
+
+
+
数据分析
+
+ $maxValue) { + $maxValue = $itemValue; + $maxItem = $item; + } + } + + if($maxItem) { + $goods_count = isset($maxItem['goods_count']) ? $maxItem['goods_count'] : 0; + $money = isset($maxItem['money']) ? $maxItem['money'] : 0; + $itemValue = $money * $goods_count; + echo "

出货金额最多的奖品: ".$maxItem['title']." (¥".round($itemValue, 2).")

"; + + // 计算占总金额的百分比 + $valuePercent = $totalValue > 0 ? round(($itemValue / $totalValue) * 100, 2) : 0; + echo "

占总出货金额的: ".$valuePercent."%

"; + } + ?> +
+
+
+
+ +
+
+ {/if} + + - @@ -40,6 +127,7 @@ {volist name="list" id="vo"} + - @@ -74,9 +161,9 @@ @@ -89,78 +176,6 @@ {/if}
奖品ID奖品类型 奖品名称 奖品图片 出货数量 奖品单价 兑换金额出货金额 理论概率 实际概率 概率偏差
{$vo.goodslist_id}{$vo.shang_id|default="0"} {$vo.title} @@ -49,7 +137,6 @@ ¥ {$vo.price|default="0"} ¥ {$vo.money|default="0"}¥ {$vo.sc_money|default="0"} {$vo.real_pro|default="0"}% ¥
- - - {if condition="!empty($list)"} -
-
统计摘要
-
-
-
-
-
总出货数量
-
- {$totalCount} -
-
-
-
-
-
总出货价值
-
- ¥ {$totalValue|round=2} -
-
-
-
- - 0): ?> -
-
-
-
平均每次出货价值
-
- ¥ -
-
-
-
-
-
数据分析
-
- $maxPercent) { - $maxPercent = $percent; - $maxItem = $item; - } - } - - if($maxItem) { - echo "

出货概率最高的奖品: ".$maxItem['title']." (".$maxPercent."%)

"; - $real_pro = isset($maxItem['real_pro']) ? $maxItem['real_pro'] : 0; - $diff = round($maxPercent - $real_pro, 2); - $diffText = $diff >= 0 ? "高于" : "低于"; - $absDiff = abs($diff); - $diffColor = $diff >= 0 ? "#5FB878" : "#FF5722"; - ?> -

与理论概率相比: 理论值 %

- -
-
-
-
- -
-
- {/if} diff --git a/app/admin/view/Statistics/profit.html b/app/admin/view/Statistics/profit.html index 407b9f8..79094de 100755 --- a/app/admin/view/Statistics/profit.html +++ b/app/admin/view/Statistics/profit.html @@ -217,7 +217,7 @@ }, cols: [[ { field: 'id', title: '盒子ID', width: 80, sort: true, fixed: 'left' }, - { field: 'title', title: '盒子名称', width: 200 }, + { field: 'title', title: '盒子名称', width: 180 }, { templet: function (d) { var statusHtml = ''; @@ -235,7 +235,7 @@ }, { field: 'price', title: '盒子单价', width: 100, templet: '
¥ {{d.price}}
' }, { - field: 'cj_count', title: '抽奖次数', width: 100, templet: function (d) { + field: 'cj_count', title: '抽奖次数', width: 90, templet: function (d) { if (!d.loaded) { return '
'; } @@ -243,7 +243,7 @@ } }, { - field: 'use_money', title: '收入 ', width: 150, templet: function (d) { + field: 'use_money', title: '收入 ', width: 140, templet: function (d) { if (!d.loaded) { return '
'; } @@ -251,7 +251,7 @@ } }, { - field: 'sc_money', title: '出货价值 ', width: 150, templet: function (d) { + field: 'sc_money', title: '出货价值 ', width: 140, templet: function (d) { if (!d.loaded) { return '
'; } @@ -259,7 +259,7 @@ } }, { - field: 're_money', title: '已兑换达达卷', width: 150, templet: function (d) { + field: 're_money', title: '已兑换达达卷', width: 120, templet: function (d) { if (!d.loaded) { return '
'; } @@ -274,6 +274,30 @@ return '
¥ ' + d.fh_money.toFixed(2) + '
'; } }, + { + field: 'single_box_profit', title: '单盒子利润 ', width: 120, templet: function (d) { + if (!d.loaded) { + return '
'; + } + // 计算公式:盒子单价x抽数-盒子出货总额 + var totalIncome = d.price * d.cj_count; + var singleBoxProfit = totalIncome - d.sc_money; + var colorClass = singleBoxProfit >= 0 ? 'layui-bg-green' : 'layui-bg-red'; + return '
¥ ' + singleBoxProfit.toFixed(2) + '
'; + } + }, + { + field: 'single_box_profit_rate', title: '单盒子利润比 ', width: 140, templet: function (d) { + if (!d.loaded) { + return '
'; + } + // 计算公式:(盒子单价x抽数-盒子出货总额)/(盒子单价x抽数) + var totalIncome = d.price * d.cj_count; + var singleBoxProfitRate = totalIncome > 0 ? ((totalIncome - d.sc_money) / totalIncome * 100) : 0; + var colorClass = singleBoxProfitRate >= 0 ? 'layui-bg-green' : 'layui-bg-red'; + return '
' + singleBoxProfitRate.toFixed(2) + '%
'; + } + }, { field: 'profit', title: '利润 ', width: 110, templet: function (d) { if (!d.loaded) { @@ -404,6 +428,17 @@ tr.find('td[data-field="fh_money"] div').html('¥ ' + data.fh_money.toFixed(2) + ''); tr.find('td[data-field="cj_count"] div').html(data.cj_count); + // 计算并更新单盒子利润 + var totalIncome = tableData[i].price * data.cj_count; + var singleBoxProfit = totalIncome - data.sc_money; + var singleBoxProfitClass = singleBoxProfit >= 0 ? 'layui-bg-green' : 'layui-bg-red'; + tr.find('td[data-field="single_box_profit"] div').html('¥ ' + singleBoxProfit.toFixed(2) + ''); + + // 计算并更新单盒子利润比 + var singleBoxProfitRate = totalIncome > 0 ? ((totalIncome - data.sc_money) / totalIncome * 100) : 0; + var singleBoxColorClass = singleBoxProfitRate >= 0 ? 'layui-bg-green' : 'layui-bg-red'; + tr.find('td[data-field="single_box_profit_rate"] div').html('' + singleBoxProfitRate.toFixed(2) + '%'); + var profitColorClass = data.profit >= 0 ? 'layui-bg-green' : 'layui-bg-red'; tr.find('td[data-field="profit"] div').html('¥ ' + data.profit.toFixed(2) + '');