column('id', 'ID')->sortable(); $grid->column('user_id', '用户ID'); $grid->column('group_id', '奖励组')->display(function ($groupId) { $group = GameRewardGroup::find($groupId); return $group ? "{$group->name} ({$group->code})" : "未知 ({$groupId})"; }); $grid->column('source_type', '来源类型')->display(function ($type) { return REWARD_SOURCE_TYPE::getName($type); }); $grid->column('source_id', '来源ID'); $grid->column('source_detail', '来源详情')->display(function () { $sourceInfo = RewardSourceResolver::resolve($this->source_type, $this->source_id); $text = $sourceInfo['name']; if ($sourceInfo['link']) { return "{$text}"; } return $text; }); $grid->column('reward_items', '奖励项')->display(function ($items) { // 由于模型中已设置了json cast,$items已经是数组,无需再次json_decode if (empty($items)) { return '无奖励项'; } $count = count($items); return "{$count}个奖励项"; }); $grid->column('created_at', '创建时间'); $grid->filter(function (Grid\Filter $filter) { $filter->equal('id', 'ID'); $filter->equal('user_id', '用户ID'); $filter->equal('group_id', '奖励组')->select( GameRewardGroup::pluck('name', 'id') ); $filter->equal('source_type', '来源类型')->select(REWARD_SOURCE_TYPE::getAll()); $filter->equal('source_id', '来源ID'); $filter->between('created_at', '创建时间')->datetime(); }); // 禁用创建按钮 $grid->disableCreateButton(); // 禁用编辑和删除 $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableEdit(); $actions->disableDelete(); }); }); } /** * 创建详情页 * * @param mixed $id * @return Show */ protected function detail($id) { return Show::make($id, new GameRewardLogRepository(), function (Show $show) { $show->field('id', 'ID'); $show->field('user_id', '用户ID'); $show->field('group_id', '奖励组')->as(function ($groupId) { $group = GameRewardGroup::find($groupId); return $group ? "{$group->name} ({$group->code})" : "未知 ({$groupId})"; }); $show->field('source_type', '来源类型')->as(function ($type) { return REWARD_SOURCE_TYPE::getName($type); }); $show->field('source_id', '来源ID'); // 显示详细的来源信息 $show->field('source_detail', '来源详情')->as(function () { $sourceInfo = RewardSourceResolver::resolve($this->source_type, $this->source_id); $html = "
"; $html .= "
{$sourceInfo['type']}: {$sourceInfo['name']}
"; $html .= "

{$sourceInfo['description']}

"; if ($sourceInfo['link']) { $html .= "

查看详情

"; } if (!empty($sourceInfo['extra'])) { $html .= "
"; $html .= "额外信息:
"; foreach ($sourceInfo['extra'] as $key => $value) { $html .= "{$key}: {$value}
"; } $html .= "
"; } $html .= "
"; return $html; })->unescape(); $show->field('created_at', '创建时间'); // 显示奖励项 $show->divider(); $show->field('奖励项')->as(function () { // 由于模型中已设置了json cast,reward_items已经是数组,无需再次json_decode $items = $this->reward_items; if (empty($items)) { return '无奖励项'; } $headers = ['奖励类型', '目标ID', '参数1', '参数2', '数量', '额外数据']; $rows = []; foreach ($items as $item) { $rows[] = [ REWARD_TYPE::getName($item['reward_type']), $item['target_id'], $item['param1'] ?? 0, $item['param2'] ?? 0, $item['quantity'], json_encode($item['extra_data'] ?? null) ]; } return Card::make( Table::make($headers, $rows) ); })->unescape(); }); } }