| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- <?php
- namespace App\Module\Farm\AdminControllers;
- use App\Module\Farm\AdminControllers\Helper\FilterHelper;
- use App\Module\Farm\AdminControllers\Helper\GridHelper;
- use App\Module\Farm\AdminControllers\Helper\ShowHelper;
- use App\Module\Farm\Repositories\FarmHarvestLogRepository;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use UCore\DcatAdmin\AdminController;
- use Spatie\RouteAttributes\Attributes\Resource;
- /**
- * 收获记录管理控制器
- */
- #[Resource('farm-harvest-logs', names: 'dcat.admin.farm-harvest-logs')]
- class FarmHarvestLogController extends AdminController
- {
- /**
- * 页面标题
- *
- * @var string
- */
- protected $title = '收获记录管理';
- /**
- * 页面描述
- *
- * @var string
- */
- protected $description = '查看用户的作物收获记录';
- /**
- * 构建表格
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new FarmHarvestLogRepository(), function (Grid $grid) {
- $helper = new GridHelper($grid, $this);
- $helper->columnId();
- $helper->columnUserId();
- $grid->column('land_id', '土地ID')->sortable();
- $grid->column('crop_id', '作物ID')->sortable();
- $grid->column('seed_id', '种子ID')->sortable();
- $grid->column('output_amount', '产出数量')->sortable();
- $grid->column('harvest_time', '收获时间')->sortable();
- $helper->columnCreatedAt();
- $grid->filter(function (Grid\Filter $filter) {
- $filterHelper = new FilterHelper($filter, $this);
- $filterHelper->equalId();
- $filterHelper->equalUserId();
- $filter->equal('land_id', '土地ID');
- $filter->equal('crop_id', '作物ID');
- $filter->equal('seed_id', '种子ID');
- $filterHelper->betweenDatetime('harvest_time', '收获时间');
- $filterHelper->betweenDatetime('created_at', '创建时间');
- });
- $grid->disableCreateButton();
- $grid->disableEditButton();
- $grid->actions(function (Grid\Displayers\Actions $actions) {
- $actions->disableDelete();
- $actions->disableEdit();
- });
- });
- }
- /**
- * 构建详情页
- *
- * @param mixed $id
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new FarmHarvestLogRepository(), function (Show $show) {
- $helper = new ShowHelper($show, $this);
- $show->field('id', 'ID');
- $helper->fieldUserId('user_id', '用户ID');
- $show->field('land_id', '土地ID');
- $show->field('crop_id', '作物ID');
- $show->field('seed_id', '种子ID');
- $show->field('output_amount', '产出数量');
- $show->field('harvest_time', '收获时间');
- $show->field('created_at', '创建时间');
- });
- }
- }
|