setWorkingDirectory(base_path()); $process->run(); if (!$process->isSuccessful()) { return response()->json([ 'status' => 'error', 'message' => 'JSON生成失败: ' . $process->getErrorOutput() ]); } return response()->json([ 'status' => 'success', 'message' => 'JSON生成成功' ]); } catch (\Exception $e) { return response()->json([ 'status' => 'error', 'message' => 'JSON生成失败: ' . $e->getMessage() ]); } } /** * 页面标题 * * @var string */ protected $title = '房屋等级配置管理'; /** * 页面描述 * * @var string */ protected $description = '管理房屋等级的配置信息'; /** * 构建表格 * * @return Grid */ protected function grid() { return Grid::make(new FarmHouseConfigRepository(), function (Grid $grid) { // 检查配置表状态 $status = RefreshCheckTool::checkSyncStatus(); if ($status['is_synced']) { admin_success('JSON配置表状态', $status['message']); } else { admin_warning('JSON配置表状态', $status['message']); } // 添加工具按钮 $grid->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 * 100) . '%'; })->sortable(); $grid->column('special_land_limit', '特殊土地上限')->sortable(); $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) { $helper = new ShowHelper($show, $this); $show->field('id', 'ID'); $show->field('level', '等级'); $show->field('output_bonus', '产出加成')->as(function ($value) { return ($value * 100) . '%'; }); $show->field('special_land_limit', '特殊土地上限'); $helper->fieldModelCatsJson('upgrade_materials', '升级所需材料'); $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) { $helper = new FormHelper($form, $this); $form->display('id', 'ID'); $form->number('level', '等级')->min(1)->max(12)->required(); $form->rate('output_bonus', '产出加成')->max(1)->step(0.05)->required(); $form->number('special_land_limit', '特殊土地上限')->min(0)->default(0)->required(); $helper->tableMaterials('upgrade_materials', '升级所需材料'); $form->number('downgrade_days', '降级天数')->min(1)->help('留空表示不降级'); $form->display('created_at', '创建时间'); $form->display('updated_at', '更新时间'); }); } }