TreatController.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Models\Category;
  4. use App\Models\PolicyProperty;
  5. use App\Models\Treat;
  6. use App\Http\Controllers\Controller;
  7. use Encore\Admin\Controllers\HasResourceActions;
  8. use Encore\Admin\Facades\Admin;
  9. use Encore\Admin\Form;
  10. use Encore\Admin\Grid;
  11. use Encore\Admin\Layout\Content;
  12. use Encore\Admin\Show;
  13. use Illuminate\Http\Request;
  14. class TreatController extends Controller
  15. {
  16. use HasResourceActions;
  17. /**
  18. * Index interface.
  19. *
  20. * @param Content $content
  21. * @return Content
  22. */
  23. public function index(Content $content)
  24. {
  25. return $content
  26. ->header('待遇分类')
  27. ->description(' ')
  28. ->body($this->grid());
  29. }
  30. /**
  31. * Show interface.
  32. *
  33. * @param mixed $id
  34. * @param Content $content
  35. * @return Content
  36. */
  37. public function show($id, Content $content)
  38. {
  39. return $content
  40. ->header('待遇分类')
  41. ->description(' ')
  42. ->body($this->detail($id));
  43. }
  44. /**
  45. * Edit interface.
  46. *
  47. * @param mixed $id
  48. * @param Content $content
  49. * @return Content
  50. */
  51. public function edit($id, Content $content)
  52. {
  53. return $content
  54. ->header('待遇分类')
  55. ->description(' ')
  56. ->body($this->editForm($id)->edit($id));
  57. }
  58. /**
  59. * Create interface.
  60. *
  61. * @param Content $content
  62. * @return Content
  63. */
  64. public function create(Content $content)
  65. {
  66. return $content
  67. ->header('待遇分类')
  68. ->description(' ')
  69. ->body($this->form());
  70. }
  71. /**
  72. * Make a grid builder.
  73. *
  74. * @return Grid
  75. */
  76. protected function grid()
  77. {
  78. $grid = new Grid(new Treat);
  79. $grid->id('id');
  80. $grid->categorys()->demand('面向人才');
  81. $grid->title('分类名称');
  82. $grid->intro('简介');
  83. $grid->policyproperty()->categoryname('政策层级');
  84. $grid->sort('排序');
  85. $grid->disableCreateButton(false);
  86. $grid->actions(function ($actions) {
  87. $actions->disableEdit(false);
  88. $actions->disableDelete(false);
  89. });
  90. $grid->filter(function ($filter) {
  91. $filter->like('categorys.demand', '面向人才');
  92. $filter->like('title', '分类名称');
  93. });
  94. return $grid;
  95. }
  96. /**
  97. * Make a show builder.
  98. *
  99. * @param mixed $id
  100. * @return Show
  101. */
  102. protected function detail($id)
  103. {
  104. $show = new Show(Treat::findOrFail($id));
  105. $show->id('ID');
  106. $show->created_at('Created at');
  107. $show->updated_at('Updated at');
  108. return $show;
  109. }
  110. /**
  111. * Make a form builder.
  112. *
  113. * @return Form
  114. */
  115. protected function form()
  116. {
  117. $form = new Form(new Treat);
  118. $form->text('title', '待遇名称')->rules(['required'], ['required'=>'请填写待遇名称'])->setMustMark();
  119. $policyProperty = PolicyProperty::select()->pluck('categoryname', 'id');
  120. // $policyProperty[0] ='不限';
  121. $form->select('property_id', '政策层次')->options($policyProperty)->load('c_id', admin_base_path('/content/policys/treats/category'))->rules("required")->setMustMark();
  122. $form->select('c_id', '面向人才')->rules(['required'], ['required'=>'请填写面向人才'])->setMustMark();
  123. $form->text('intro', '待遇简介')->rules(['required'], ['required'=>'请填写待遇简介'])->setMustMark();
  124. $form->number('sort', '排序')->default(0)->min(0);
  125. $form->text('content', '待遇内容')->rules(['required'], ['required'=>'请填写待遇内容'])->setMustMark();
  126. return $form;
  127. }
  128. protected function editForm($id)
  129. {
  130. $form = new Form(new Treat);
  131. $treatData = Treat::where('id', $id)->select('property_id')->first()->toArray();
  132. $form->text('title', '待遇名称')->rules(['required'], ['required'=>'请填写待遇名称'])->setMustMark();
  133. $policyProperty = PolicyProperty::select()->pluck('categoryname', 'id');
  134. // $policyProperty[0] ='不限';
  135. $arr = array(
  136. '1' => 'RC_category_fj',
  137. '2' => 'RC_category_qz',
  138. '7' => '',
  139. '8' => 'RC_category'
  140. );
  141. $form->select('property_id', '政策层次')->options($policyProperty)->load('c_id', admin_base_path('/content/policys/treats/category'))->rules("required")->setMustMark();
  142. $form->select('c_id', '面向人才')->options(Category::categoryType($arr[$treatData['property_id']]))->rules(['required'], ['required'=>'请填写面向人才'])->setMustMark();
  143. $form->text('intro', '待遇简介')->rules(['required'], ['required'=>'请填写待遇简介'])->setMustMark();
  144. $form->number('sort', '排序')->default(0)->min(0);
  145. $form->text('content', '待遇内容')->rules(['required'], ['required'=>'请填写待遇内容'])->setMustMark();
  146. return $form;
  147. }
  148. public function category(Request $request)
  149. {
  150. $q = $request->get('q');
  151. $arr = array(
  152. '1' => 'RC_category_fj',
  153. '2' => 'RC_category_qz',
  154. '7' => 'RC_category_jj',
  155. '8' => 'RC_category'
  156. );
  157. return Category::where('alias', $arr[$q])->get(['id',"demand as text"]);
  158. }
  159. public function update($id)
  160. {
  161. return $this->editForm($id)->update($id);
  162. }
  163. }