FarmHarvestLogController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Module\Farm\AdminControllers;
  3. use App\Module\Farm\AdminControllers\Helper\FilterHelper;
  4. use App\Module\Farm\AdminControllers\Helper\GridHelper;
  5. use App\Module\Farm\AdminControllers\Helper\ShowHelper;
  6. use App\Module\Farm\Repositories\FarmHarvestLogRepository;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use UCore\DcatAdmin\AdminController;
  10. use Spatie\RouteAttributes\Attributes\Resource;
  11. /**
  12. * 收获记录管理控制器
  13. */
  14. #[Resource('farm-harvest-logs', names: 'dcat.admin.farm-harvest-logs')]
  15. class FarmHarvestLogController extends AdminController
  16. {
  17. /**
  18. * 页面标题
  19. *
  20. * @var string
  21. */
  22. protected $title = '收获记录管理';
  23. /**
  24. * 页面描述
  25. *
  26. * @var string
  27. */
  28. protected $description = '查看用户的作物收获记录';
  29. /**
  30. * 构建表格
  31. *
  32. * @return Grid
  33. */
  34. protected function grid()
  35. {
  36. return Grid::make(new FarmHarvestLogRepository(), function (Grid $grid) {
  37. $helper = new GridHelper($grid, $this);
  38. $helper->columnId();
  39. $helper->columnUserId();
  40. $grid->column('land_id', '土地ID')->sortable();
  41. $grid->column('crop_id', '作物ID')->sortable();
  42. $grid->column('seed_id', '种子ID')->sortable();
  43. $grid->column('output_amount', '产出数量')->sortable();
  44. $grid->column('harvest_time', '收获时间')->sortable();
  45. $helper->columnCreatedAt();
  46. $grid->filter(function (Grid\Filter $filter) {
  47. $filterHelper = new FilterHelper($filter, $this);
  48. $filterHelper->equalId();
  49. $filterHelper->equalUserId();
  50. $filter->equal('land_id', '土地ID');
  51. $filter->equal('crop_id', '作物ID');
  52. $filter->equal('seed_id', '种子ID');
  53. $filterHelper->betweenDatetime('harvest_time', '收获时间');
  54. $filterHelper->betweenDatetime('created_at', '创建时间');
  55. });
  56. $grid->disableCreateButton();
  57. $grid->disableEditButton();
  58. $grid->actions(function (Grid\Displayers\Actions $actions) {
  59. $actions->disableDelete();
  60. $actions->disableEdit();
  61. });
  62. });
  63. }
  64. /**
  65. * 构建详情页
  66. *
  67. * @param mixed $id
  68. * @return Show
  69. */
  70. protected function detail($id)
  71. {
  72. return Show::make($id, new FarmHarvestLogRepository(), function (Show $show) {
  73. $helper = new ShowHelper($show, $this);
  74. $show->field('id', 'ID');
  75. $helper->fieldUserId('user_id', '用户ID');
  76. $show->field('land_id', '土地ID');
  77. $show->field('crop_id', '作物ID');
  78. $show->field('seed_id', '种子ID');
  79. $show->field('output_amount', '产出数量');
  80. $show->field('harvest_time', '收获时间');
  81. $show->field('created_at', '创建时间');
  82. });
  83. }
  84. }