|
|
@@ -0,0 +1,206 @@
|
|
|
+<?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();
|
|
|
+ });
|
|
|
+ }
|
|
|
+}
|