columnId(); $grid->column('land_id', '土地ID')->sortable(); $helper->columnUserId(); $grid->column('seed_id', '种子ID')->sortable(); $grid->column('plant_time', '种植时间')->sortable(); $helper->columnUseingEnmu('growth_stage', \App\Module\Farm\Enums\GROWTH_STAGE::class,'生长阶段'); $grid->column('stage_end_time', '阶段结束时间')->sortable(); // 添加产出相关字段 $grid->column('final_output_item_id', '产出物品ID')->sortable()->display(function ($value) { if ($value) { return "{$value}"; } return "未确定"; }); $grid->column('final_output_amount', '预定产量')->sortable()->display(function ($value) { if ($value) { return "{$value}"; } return "未确定"; }); // 添加数据完整性状态列 $grid->column('data_status', '数据状态')->display(function () { $hasItemId = !empty($this->final_output_item_id); $hasAmount = !empty($this->final_output_amount); $isMature = $this->growth_stage == GROWTH_STAGE::MATURE->value; if ($isMature) { if ($hasItemId && $hasAmount) { return "完整"; } elseif ($hasItemId) { return "缺少产量"; } else { return "缺少产出物品"; } } else { if ($hasItemId) { return "已确定产出物品"; } else { return "未确定"; } } }); $helper->columnFertilized(); $helper->columnCreatedAt(); $helper->columnUpdatedAt(); // 添加批量操作 $grid->tools(function (Grid\Tools $tools) { $tools->append(' 修复成熟期产量 '); $tools->append(''); }); $grid->filter(function (Grid\Filter $filter) { $filterHelper = new FilterHelper($filter, $this); $filterHelper->equalId(); $filter->equal('land_id', '土地ID'); $filterHelper->equalUserId(); $filter->equal('seed_id', '种子ID'); $filterHelper->equalGrowthStage(); $filterHelper->betweenDatetime('plant_time', '种植时间'); $filterHelper->betweenDatetime('stage_end_time', '阶段结束时间'); // 添加产出相关过滤器 $filter->equal('final_output_item_id', '产出物品ID'); $filter->where('final_output_amount', '产量状态', function ($query) { $value = $this->input; if ($value == 'has_amount') { $query->whereNotNull('final_output_amount'); } elseif ($value == 'no_amount') { $query->whereNull('final_output_amount'); } })->select([ 'has_amount' => '已确定产量', 'no_amount' => '未确定产量' ]); // 添加数据完整性过滤器 $filter->where('data_completeness', '数据完整性', function ($query) { $value = $this->input; if ($value == 'complete') { $query->whereNotNull('final_output_item_id') ->whereNotNull('final_output_amount') ->where('growth_stage', GROWTH_STAGE::MATURE->value); } elseif ($value == 'incomplete_mature') { $query->where('growth_stage', GROWTH_STAGE::MATURE->value) ->where(function ($q) { $q->whereNull('final_output_item_id') ->orWhereNull('final_output_amount'); }); } elseif ($value == 'missing_amount') { $query->whereNotNull('final_output_item_id') ->whereNull('final_output_amount'); } })->select([ 'complete' => '数据完整(成熟期)', 'incomplete_mature' => '数据不完整(成熟期)', 'missing_amount' => '缺少产量' ]); $filterHelper->equalFertilized(); $filterHelper->betweenDatetime('created_at', '创建时间'); }); }); } /** * 构建详情页 * * @param mixed $id * @return Show */ protected function detail($id) { return Show::make($id, new FarmCropRepository(), function (Show $show) { $helper = new ShowHelper($show, $this); $show->field('id', 'ID'); $show->field('land_id', '土地ID'); $helper->fieldUserId('user_id', '用户ID'); $show->field('seed_id', '种子ID'); $show->field('plant_time', '种植时间'); $helper->fieldGrowthStage('growth_stage', '生长阶段'); $show->field('stage_end_time', '阶段结束时间'); // 添加产出相关字段(增强版本) $show->field('final_output_item_id', '产出物品ID')->as(function ($value) { return $value ? "{$value}" : "未确定"; }); $show->field('final_output_amount', '预定产量')->as(function ($value) { return $value ? "{$value}" : "未确定"; }); // 添加数据完整性状态 $show->field('data_status', '数据状态')->as(function () { $hasItemId = !empty($this->final_output_item_id); $hasAmount = !empty($this->final_output_amount); $isMature = $this->growth_stage == GROWTH_STAGE::MATURE->value; if ($isMature) { if ($hasItemId && $hasAmount) { return "数据完整,可正常收获"; } elseif ($hasItemId) { return "缺少产量,需要修复"; } else { return "缺少产出物品ID,严重错误"; } } else { if ($hasItemId) { return "已确定产出物品,等待成熟期确定产量"; } else { return "等待发芽期确定产出物品"; } } }); // 使用新的灾害显示方法 $show->fieldModelCatsJson2('disasters', '灾害情况'); $helper->fieldFertilized('fertilized', '已施肥'); $show->field('created_at', '创建时间'); $show->field('updated_at', '更新时间'); }); } /** * 构建表单 * * @return Form */ protected function form() { return Form::make(new FarmCropRepository(), function (Form $form) { $helper = new FormHelper($form, $this); $form->display('id', 'ID'); $form->text('land_id', '土地ID')->required()->rules('required|integer'); $helper->display('user_id', '用户ID'); // 获取所有种子选项 $form->display('seed_id', '种子ID'); $form->datetime('plant_time', '种植时间')->required(); $helper->selectOptionCast('growth_stage', '生长阶段'); $form->datetime('stage_end_time', '阶段结束时间'); // 添加产出相关字段 $form->number('final_output_item_id', '产出物品ID') ->help('发芽期自动确定,也可手动设置'); $form->number('final_output_amount', '预定产量') ->min(1) ->help('成熟期自动计算,也可手动设置。注意:手动设置后收获时会直接使用此产量'); // 添加数据状态提示 $form->html('
php artisan farm:fix-crop-mature-output