| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace App\Module\GameItems\AdminControllers;
- use App\Module\GameItems\Models\ItemChestOpenLog;
- use App\Module\GameItems\Models\ItemItem;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\AdminController;
- use Dcat\Admin\Layout\Content;
- use Spatie\RouteAttributes\Attributes\Resource;
- #[Resource('game-items-chest-open-logs', names: 'dcat.admin.game-items-chest-open-logs')]
- class ChestOpenLogController extends AdminController
- {
- /**
- * 标题
- *
- * @var string
- */
- protected $title = '宝箱开启记录';
- /**
- * 禁用创建按钮
- *
- * @var bool
- */
- protected $showCreateButton = false;
- /**
- * 列表页
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new ItemChestOpenLog(), function (Grid $grid) {
- // 禁用创建、编辑和删除按钮
- $grid->disableCreateButton();
- $grid->disableActions();
- $grid->disableBatchDelete();
- $grid->disableDeleteButton();
- $grid->disableEditButton();
- // 只保留详情按钮
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableDelete();
- $actions->disableEdit();
- $actions->disableQuickEdit();
- });
- $grid->column('id', 'ID')->sortable();
- $grid->column('user_id', '用户ID');
- $grid->column('chest.name', '宝箱名称');
- $grid->column('quantity', '开启数量');
- $grid->column('pity_triggered', '触发保底')->switch();
- $grid->column('pity_content_id', '保底内容ID');
- $grid->column('open_time', '开启时间')->sortable();
- $grid->column('ip_address', 'IP地址');
- $grid->column('created_at', '创建时间');
- // 筛选
- $grid->filter(function ($filter) {
- $filter->equal('id', 'ID');
- $filter->equal('user_id', '用户ID');
- $filter->equal('chest_id', '宝箱')->select(
- ItemItem::where('type', 5)->pluck('name', 'id')
- );
- $filter->equal('pity_triggered', '触发保底')->radio([
- 1 => '是',
- 0 => '否',
- ]);
- $filter->between('open_time', '开启时间')->datetime();
- });
- });
- }
- /**
- * 详情页
- *
- * @param mixed $id
- * @param Content $content
- * @return Content
- */
- public function show($id, Content $content)
- {
- return $content
- ->header($this->title)
- ->description('详情')
- ->body($this->detail($id));
- }
- /**
- * 详情页
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make(ItemChestOpenLog::findOrFail($id), function (Show $show) {
- // 禁用编辑和删除按钮
- $show->panel()->tools(function ($tools) {
- $tools->disableEdit();
- $tools->disableDelete();
- });
- $show->field('id', 'ID');
- $show->field('user_id', '用户ID');
- $show->field('chest.name', '宝箱名称');
- $show->field('quantity', '开启数量');
- $show->field('pity_triggered', '触发保底')->as(function ($value) {
- return $value ? '是' : '否';
- });
- $show->field('pity_content_id', '保底内容ID');
- // 显示开箱结果
- $show->field('results', '开箱结果')->as(function ($results) {
- if (empty($results)) {
- return '无';
- }
- if (is_string($results)) {
- $results = json_decode($results, true);
- }
- if (is_array($results)) {
- $html = '';
- foreach ($results as $index => $chestResult) {
- $html .= '<h4>第' . ($index + 1) . '次开箱</h4>';
- $html .= '<table class="table table-bordered">';
- $html .= '<thead><tr><th>物品ID</th><th>数量</th><th>是否保底</th></tr></thead>';
- $html .= '<tbody>';
- foreach ($chestResult as $item) {
- $itemInfo = ItemItem::find($item['item_id']);
- $itemName = $itemInfo ? $itemInfo->name : '未知物品';
- $html .= '<tr>';
- $html .= '<td>' . $item['item_id'] . ' (' . $itemName . ')</td>';
- $html .= '<td>' . $item['quantity'] . '</td>';
- $html .= '<td>' . (isset($item['is_pity']) && $item['is_pity'] ? '是' : '否') . '</td>';
- $html .= '</tr>';
- }
- $html .= '</tbody></table>';
- }
- return $html;
- }
- return $results;
- })->unescape();
- $show->field('open_time', '开启时间');
- $show->field('ip_address', 'IP地址');
- $show->field('device_info', '设备信息');
- $show->field('created_at', '创建时间');
- });
- }
- }
|