ActivityController.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Activity;
  4. use App\Models\ActivityRange;
  5. use App\Models\ActivityWorkStation;
  6. use Encore\Admin\Controllers\AdminController;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Show;
  11. class ActivityController extends AdminController
  12. {
  13. /**
  14. * Title for current resource.
  15. *
  16. * @var string
  17. */
  18. protected $title = '六进活动';
  19. /**
  20. * Make a grid builder.
  21. *
  22. * @return Grid
  23. */
  24. protected function grid()
  25. {
  26. $grid = new Grid(new Activity());
  27. //权限
  28. $grid->actions(function ($actions) {
  29. // 没有`delete-image`权限的角色不显示删除按钮
  30. if (!Admin::user()->can('delete-activite')) {
  31. $actions->disableDelete();
  32. }
  33. });
  34. $grid->filter(function($filter){
  35. $filter->disableIdFilter();
  36. // $filter->where(function($query){
  37. // $query->where('activity_range_id=' . $_GET['activity_range_id']);
  38. // },'hidden');
  39. // 在这里添加字段过滤器
  40. $filter->like('title', '活动标题');
  41. $filter->equal('organiz_type', '机关类型')->select([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
  42. $filter->expand();
  43. // $filter->equal('activity_range_id', '活动区域');
  44. });
  45. //单个区域查询条件
  46. if(isset($_GET['belong'])) {
  47. $grid->model()->where('belong', '=', $_GET['belong']);
  48. }
  49. $grid->column('id', __('Id'));
  50. $grid->column('workstation.name', __('开展单位'));
  51. $grid->column('organiz_type', __('单位类型'))->using([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
  52. $grid->column('range.name', __('活动区域'));
  53. $grid->column('title', __('活动标题'));
  54. $grid->column('organiz_name', __('单位名称'));
  55. $grid->column('member_num', __('参加人数'));
  56. // $grid->column('content', __('活动内容'));
  57. // $grid->column('ext', __('附件资料'));
  58. $grid->column('active_time', __('活动时间'));
  59. $grid->column('creater.name', __('创建者'));
  60. $grid->column('updater.name', __('修改者'));
  61. // $grid->column('created_at', __('创建时间'));
  62. // $grid->column('updated_at', __('修改时间'));
  63. return $grid;
  64. }
  65. /**
  66. * Make a show builder.
  67. *
  68. * @param mixed $id
  69. * @return Show
  70. */
  71. protected function detail($id)
  72. {
  73. $show = new Show(Activity::findOrFail($id));
  74. $show->field('id', __('Id'));
  75. $show->field('workstation.name', __('开展单位'));
  76. $show->field('organiz_type', __('单位类型'))->using([1=>'党政机关', 2=>'学校', 3=>'企业', 4=>'公共场所', 5=>'社区', 6=>'农村']);
  77. $show->field('range.name', __('开展区域'));
  78. $show->field('title', __('活动标题'));
  79. $show->field('active_time', __('活动时间'));
  80. $show->field('organiz_name', __('单位名称'));
  81. $show->field('member_num', __('参加人数'));
  82. $show->field('content', __('活动内容'));
  83. $show->field('ext', __('附件资料'));
  84. $show->field('creater.name', __('创建者'));
  85. $show->field('updator.name', __('更新者'));
  86. // $show->field('created_at', __('Created at'));
  87. // $show->field('updated_at', __('Updated at'));
  88. return $show;
  89. }
  90. /**
  91. * Make a form builder.
  92. *
  93. * @return Form
  94. */
  95. protected function form()
  96. {
  97. $form = new Form(new Activity());
  98. $form->tools(function (Form\Tools $tools) {
  99. // 去掉`列表`按钮
  100. $tools->disableList();
  101. // // 去掉`删除`按钮
  102. // $tools->disableDelete();
  103. // // 去掉`查看`按钮
  104. // $tools->disableView();
  105. });
  106. $form->select('belong', __('开展单位'))->options(function(){
  107. $ret = [];
  108. $stations = ActivityWorkStation::select(['work_station_id as id', 'name'])->get();
  109. if($stations){
  110. foreach($stations as $v){
  111. $ret[$v->id] = $v->name;
  112. }
  113. }
  114. return $ret;
  115. })->required();
  116. $form->select('organiz_type', __('被开展单位类型'))->options([1=>'党政机关', 2=>'学校', 3=>'企事业单位', 4=>'公共场所', 5=>'社区', 6=>'农村'])->required();
  117. $form->select('activity_range_id', __('活动区域'))->options(function(){
  118. $ret = [];
  119. $range = ActivityRange::select(['id', 'name'])->get();
  120. if($range){
  121. foreach($range as $v){
  122. $ret[$v->id] = $v->name;
  123. }
  124. }
  125. return $ret;
  126. })->required();
  127. $form->datetime('active_time', __('活动时间'))->required();
  128. $form->text('title', __('活动标题'))->required();
  129. $form->text('organiz_name', __('单位名称'))->required();
  130. $form->text('member_num', __('参加人数'))->required();
  131. $form->text('member', __('主要参加人员'))->required();
  132. $form->textarea('content', __('活动内容'));
  133. // 多文件
  134. $form->multipleFile('ext', __('附件资料'))->removable();
  135. // $form->number('creater', __('Creater'));
  136. // $form->number('updator', __('Updator'));
  137. return $form;
  138. }
  139. }