| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace App\Module\Game\AdminRepositories;
- use App\Module\Game\Models\GameRewardGroup;
- use App\Module\Game\Models\GameRewardGroupPityCount;
- use App\Module\Game\Models\GameRewardItem;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\GridHelper;
- use UCore\DcatAdmin\ShowHelper;
- use UCore\DcatAdmin\FormHelper;
- use UCore\DcatAdmin\FilterHelper;
- /**
- * 奖励组保底计数仓库
- */
- class GameRewardGroupPityCountRepository
- {
- /**
- * 列表页面
- *
- * @return Grid
- */
- public function grid(): Grid
- {
- return Grid::make(GameRewardGroupPityCount::with(['user', 'rewardGroup', 'rewardItem']), function (Grid $grid) {
- $grid->column('id', 'ID')->sortable();
-
- $grid->column('user.username', '用户名')
- ->link(function ($value) {
- return admin_url("users/{$this->user_id}");
- });
-
- $grid->column('user_id', '用户ID')->sortable();
-
- $grid->column('rewardGroup.name', '奖励组')
- ->link(function ($value) {
- return admin_url("game/reward-groups/{$this->reward_group_id}");
- });
-
- $grid->column('rewardItem.name', '奖励项')
- ->display(function () {
- if ($this->rewardItem) {
- return $this->rewardItem->name;
- }
- return '未知奖励项';
- });
-
- $grid->column('count', '当前计数')
- ->display(function ($value) {
- $threshold = $this->pity_threshold;
- $percentage = $threshold > 0 ? round(($value / $threshold) * 100, 1) : 0;
- $color = $percentage >= 80 ? 'danger' : ($percentage >= 50 ? 'warning' : 'success');
- return "<span class='badge badge-{$color}'>{$value} ({$percentage}%)</span>";
- });
-
- $grid->column('pity_threshold', '保底阈值')->sortable();
-
- $grid->column('progress', '保底进度')
- ->display(function () {
- if ($this->pity_threshold <= 0) {
- return '<span class="text-muted">未启用</span>';
- }
-
- $percentage = round(($this->count / $this->pity_threshold) * 100, 1);
- $color = $percentage >= 100 ? 'success' : ($percentage >= 80 ? 'warning' : 'info');
-
- return "<div class='progress' style='height: 20px;'>
- <div class='progress-bar bg-{$color}' style='width: {$percentage}%'>
- {$percentage}%
- </div>
- </div>";
- });
-
- $grid->column('last_attempt_at', '最后尝试时间')
- ->display(function ($value) {
- return $value ? $value->format('Y-m-d H:i:s') : '-';
- });
-
- $grid->column('last_hit_at', '最后命中时间')
- ->display(function ($value) {
- return $value ? $value->format('Y-m-d H:i:s') : '-';
- });
-
- $grid->column('created_at', '创建时间')->sortable();
- $grid->column('updated_at', '更新时间')->sortable();
- // 筛选器
- $grid->filter(function (Grid\Filter $filter) {
- FilterHelper::defaultDateRange($filter);
-
- $filter->equal('user_id', '用户ID');
- $filter->like('user.username', '用户名');
-
- $filter->equal('reward_group_id', '奖励组')
- ->select(GameRewardGroup::pluck('name', 'id'));
-
- $filter->between('count', '当前计数');
- $filter->between('pity_threshold', '保底阈值');
-
- $filter->where(function ($query) {
- $query->whereRaw('count >= pity_threshold');
- }, '已达保底', 'reached_pity')->checkbox();
- });
- // 工具栏
- GridHelper::defaultToolbar($grid);
-
- // 禁用新增和编辑(这些记录由系统自动管理)
- $grid->disableCreateButton();
- $grid->disableEditButton();
-
- // 只允许查看详情
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableEdit();
- $actions->disableDelete();
- });
- // 排序
- $grid->model()->orderBy('updated_at', 'desc');
- });
- }
- /**
- * 详情页面
- *
- * @param mixed $id
- * @return Show
- */
- public function detail($id): Show
- {
- return Show::make($id, GameRewardGroupPityCount::with(['user', 'rewardGroup', 'rewardItem']), function (Show $show) {
- ShowHelper::defaultShow($show);
- $show->field('id', 'ID');
-
- $show->field('user.username', '用户名')
- ->link(function ($value) {
- return admin_url("users/{$this->user_id}");
- });
-
- $show->field('user_id', '用户ID');
-
- $show->field('rewardGroup.name', '奖励组')
- ->link(function ($value) {
- return admin_url("game/reward-groups/{$this->reward_group_id}");
- });
-
- $show->field('rewardItem.name', '奖励项');
-
- $show->field('count', '当前计数');
- $show->field('pity_threshold', '保底阈值');
-
- $show->field('progress', '保底进度')
- ->as(function () {
- if ($this->pity_threshold <= 0) {
- return '未启用保底机制';
- }
-
- $percentage = round(($this->count / $this->pity_threshold) * 100, 1);
- $status = $percentage >= 100 ? '已达保底' : '未达保底';
-
- return "{$percentage}% ({$status})";
- });
-
- $show->field('last_attempt_at', '最后尝试时间');
- $show->field('last_hit_at', '最后命中时间');
- $show->field('created_at', '创建时间');
- $show->field('updated_at', '更新时间');
- // 禁用编辑和删除
- $show->disableEditButton();
- $show->disableDeleteButton();
- });
- }
- /**
- * 表单页面(仅用于查看,不允许编辑)
- *
- * @return Form
- */
- public function form(): Form
- {
- return Form::make(GameRewardGroupPityCount::class, function (Form $form) {
- FormHelper::defaultForm($form);
- $form->display('id', 'ID');
- $form->display('user_id', '用户ID');
- $form->display('reward_group_id', '奖励组ID');
- $form->display('reward_item_id', '奖励项ID');
- $form->display('count', '当前计数');
- $form->display('pity_threshold', '保底阈值');
- $form->display('last_attempt_at', '最后尝试时间');
- $form->display('last_hit_at', '最后命中时间');
- $form->display('created_at', '创建时间');
- $form->display('updated_at', '更新时间');
- // 禁用所有操作
- $form->disableCreatingCheck();
- $form->disableEditingCheck();
- $form->disableViewCheck();
- });
- }
- }
|