| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- <?php
- namespace App\Module\Point\AdminControllers;
- use App\Module\Point\Repositorys\PointRepository;
- use App\Module\Point\Repositorys\PointLogRepository;
- use App\Module\Point\Repositorys\PointAdminRepository;
- use App\Module\Point\Repositorys\PointCirculationRepository;
- use App\Module\Point\Repositorys\PointTransferRepository;
- use App\Module\Point\Repositorys\PointOrderRepository;
- use Dcat\Admin\Layout\Content;
- use Dcat\Admin\Widgets\Card;
- use Dcat\Admin\Widgets\InfoBox;
- use Spatie\RouteAttributes\Attributes\Get;
- use UCore\DcatAdmin\AdminController;
- /**
- * 种植点数统计仪表板控制器
- *
- * 路由: /admin/point/dashboard
- * 菜单: 积分管理 -> 统计仪表板
- * 功能: 展示种植点数系统的统计数据和分析图表
- */
- class PointDashboardController extends AdminController
- {
- /**
- * 页面标题
- */
- protected $title = '种植点数统计仪表板';
- /**
- * 仪表板页面
- */
- #[Get('point/dashboard', name: 'admin.point.dashboard.index')]
- public function index(Content $content)
- {
- return $content
- ->title($this->title)
- ->description('积分系统数据统计')
- ->body($this->overview())
- ->body($this->pointTypeStats())
- ->body($this->recentActivity());
- }
- /**
- * 概览统计
- */
- protected function overview()
- {
- $pointRepo = new PointRepository();
- $logRepo = new PointLogRepository();
- $adminRepo = new PointAdminRepository();
- $circulationRepo = new PointCirculationRepository();
- $transferRepo = new PointTransferRepository();
- $orderRepo = new PointOrderRepository();
- // 基础统计
- $totalAccounts = $pointRepo->model()->count();
- $totalLogs = $logRepo->model()->count();
- $totalAdminOps = $adminRepo->model()->count();
- $totalCirculations = $circulationRepo->model()->count();
- $totalTransfers = $transferRepo->model()->count();
- $totalOrders = $orderRepo->model()->count();
- // 今日统计
- $todayStart = strtotime('today');
- $todayLogs = $logRepo->model()->where('create_time', '>=', $todayStart)->count();
- $todayAdminOps = $adminRepo->model()->where('create_time', '>=', $todayStart)->count();
- return new Card('系统概览', [
- new InfoBox('积分账户总数', 'users', 'aqua', route('admin.point.index'), $totalAccounts),
- new InfoBox('积分日志总数', 'file-text-o', 'green', route('admin.point-log.index'), $totalLogs),
- new InfoBox('管理员操作', 'cog', 'yellow', route('admin.point-admin.index'), $totalAdminOps),
- new InfoBox('今日日志', 'calendar', 'red', route('admin.point-log.index'), $todayLogs),
- ]);
- }
- /**
- * 积分类型统计
- */
- protected function pointTypeStats()
- {
- $pointRepo = new PointRepository();
- $stats = $pointRepo->getPointTypeStats();
- $pointTypes = [
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ];
- $html = '<div class="row">';
- foreach ($stats as $stat) {
- $pointId = $stat['point_id'];
- $typeName = $pointTypes[$pointId] ?? "积分{$pointId}";
- $userCount = $stat['user_count'];
- $totalBalance = number_format($stat['total_balance']);
- $avgBalance = number_format($stat['avg_balance'], 2);
- $html .= "
- <div class='col-md-4'>
- <div class='info-box'>
- <span class='info-box-icon bg-blue'><i class='fa fa-star'></i></span>
- <div class='info-box-content'>
- <span class='info-box-text'>{$typeName}</span>
- <span class='info-box-number'>{$userCount} 用户</span>
- <div class='progress'>
- <div class='progress-bar' style='width: 70%'></div>
- </div>
- <span class='progress-description'>
- 总积分: {$totalBalance} | 平均: {$avgBalance}
- </span>
- </div>
- </div>
- </div>
- ";
- }
- $html .= '</div>';
- return new Card('积分类型统计', $html);
- }
- /**
- * 最近活动
- */
- protected function recentActivity()
- {
- $logRepo = new PointLogRepository();
- $recentLogs = $logRepo->model()
- ->orderBy('create_time', 'desc')
- ->limit(10)
- ->get();
- $pointTypes = [
- 1 => '经验积分',
- 2 => '成就积分',
- 3 => '活动积分',
- 4 => '签到积分',
- 5 => '推荐积分',
- ];
- $html = '<div class="table-responsive"><table class="table table-striped">';
- $html .= '<thead><tr><th>时间</th><th>用户</th><th>积分类型</th><th>变更</th><th>备注</th></tr></thead>';
- $html .= '<tbody>';
- foreach ($recentLogs as $log) {
- $time = date('m-d H:i', $log->create_time);
- $pointType = $pointTypes[$log->point_id] ?? "积分{$log->point_id}";
- $amount = $log->amount > 0 ? "+{$log->amount}" : $log->amount;
- $amountClass = $log->amount > 0 ? 'text-success' : 'text-danger';
- $remark = mb_substr($log->remark, 0, 20) . (mb_strlen($log->remark) > 20 ? '...' : '');
- $html .= "
- <tr>
- <td>{$time}</td>
- <td>用户{$log->user_id}</td>
- <td>{$pointType}</td>
- <td class='{$amountClass}'>{$amount}</td>
- <td>{$remark}</td>
- </tr>
- ";
- }
- $html .= '</tbody></table></div>';
- return new Card('最近活动', $html);
- }
- }
|