tools([ new RefreshCheckTool($status['should_display']), new SyncFarmHouseJsonTool($status['should_display']) ]); $helper = new GridHelper($grid, $this); $helper->columnId(); $grid->column('level', '等级')->sortable(); $grid->column('output_bonus', '产出加成')->display(function ($value) { return $value . '%'; })->sortable(); $grid->column('special_land_limit', '特殊土地上限')->sortable(); $grid->column('upgrade_materials', '升级所需消耗组')->display(function ($materialsGroupId) { if (!$materialsGroupId) { return '未设置'; } $consumeGroup = GameConsumeGroup::find($materialsGroupId); return $consumeGroup ? "{$consumeGroup->name} ({$consumeGroup->code})" : "未知 ({$materialsGroupId})"; }); $grid->column('downgrade_days', '降级天数')->sortable(); $helper->columnCreatedAt(); $helper->columnUpdatedAt(); $grid->filter(function (Grid\Filter $filter) { $filterHelper = new FilterHelper($filter, $this); $filterHelper->equalId(); $filter->equal('level', '等级'); $filterHelper->betweenDatetime('created_at', '创建时间'); }); $grid->actions(function (Grid\Displayers\Actions $actions) { $actions->disableDelete(); }); }); } /** * 构建详情页 * * @param mixed $id * @return Show */ protected function detail($id) { return Show::make($id, new FarmHouseConfigRepository(), function (Show $show) { new ShowHelper($show, $this); $show->field('id', 'ID'); $show->field('level', '等级'); $show->field('output_bonus', '产出加成')->as(function ($value) { return $value . '%'; }); $show->field('special_land_limit', '特殊土地上限'); $show->field('upgrade_materials', '升级所需消耗组')->as(function ($materialsGroupId) { if (!$materialsGroupId) { return '未设置消耗组'; } $consumeGroup = GameConsumeGroup::find($materialsGroupId); return $consumeGroup ? "{$consumeGroup->name} ({$consumeGroup->code})" : "未知 ({$materialsGroupId})"; }); $show->field('downgrade_days', '降级天数'); $show->field('created_at', '创建时间'); $show->field('updated_at', '更新时间'); }); } /** * 构建表单 * * @return Form */ protected function form() { return Form::make(new FarmHouseConfigRepository(), function (Form $form) { new FormHelper($form, $this); $form->display('id', 'ID'); $form->number('level', '等级')->min(1)->max(12)->required(); $form->number('output_bonus', '产出加成') ->min(0)->max(100)->required()->help('输入百分比数值,如15表示15%的加成'); $form->number('special_land_limit', '特殊土地上限')->min(0)->default(0)->required(); // 添加消耗组选择(使用表格选择器) $consumeGroupTable = GameConsumeGroupLazyRenderable::make(); $form->selectTable('upgrade_materials', '升级所需消耗组') ->from($consumeGroupTable) ->title('选择消耗组') ->model($consumeGroupTable->getModel(), $consumeGroupTable->getModelSelectId(), $consumeGroupTable->getModelViewName()) ->help('选择消耗组后,将使用消耗组中的消耗项作为升级所需材料'); $form->number('downgrade_days', '降级天数')->min(1)->help('留空表示不降级'); $form->display('created_at', '创建时间'); $form->display('updated_at', '更新时间'); }); } }