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)"} +
出货金额最多的奖品: ".$maxItem['title']." (¥".round($itemValue, 2).")
"; + + // 计算占总金额的百分比 + $valuePercent = $totalValue > 0 ? round(($itemValue / $totalValue) * 100, 2) : 0; + echo "占总出货金额的: ".$valuePercent."%
"; + } + ?> +| 奖品ID | +奖品类型 | 奖品名称 | 奖品图片 | 出货数量 | 奖品单价 | 兑换金额 | -出货金额 | 理论概率 | 实际概率 | 概率偏差 | @@ -40,6 +127,7 @@ {volist name="list" id="vo"}
|---|---|---|---|---|---|---|---|---|---|---|
| {$vo.goodslist_id} | +{$vo.shang_id|default="0"} | {$vo.title} |
|
¥ {$vo.price|default="0"} | ¥ {$vo.money|default="0"} | -¥ {$vo.sc_money|default="0"} | {$vo.real_pro|default="0"}% | @@ -74,9 +161,9 @@¥ | @@ -89,78 +176,6 @@ {/if}
出货概率最高的奖品: ".$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"; - ?> -与理论概率相比: 理论值 %
- -