PersonalServiceStickController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <?php
  2. namespace App\Admin\Controllers\Person;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\PersonalServiceStick;
  5. use App\Models\PersonalServiceTag;
  6. use Encore\Admin\Controllers\HasResourceActions;
  7. use Encore\Admin\Facades\Admin;
  8. use Encore\Admin\Form;
  9. use Encore\Admin\Grid;
  10. use Encore\Admin\Layout\Content;
  11. use Encore\Admin\Show;
  12. use Encore\Admin\Widgets\Tab;
  13. use Encore\Admin\Widgets\Table;
  14. use Illuminate\Validation\Rule;
  15. class PersonalServiceStickController extends Controller
  16. {
  17. use HasResourceActions;
  18. /**
  19. * Index interface.
  20. *
  21. * @param Content $content
  22. * @return Content
  23. */
  24. public function index(Content $content)
  25. {
  26. return $content
  27. ->header('简历置顶')
  28. ->description(' ')
  29. ->body($this->grid());
  30. }
  31. public function indexs(Content $content, int $type_id, int $tab_id = 0)
  32. {
  33. $tab = new Tab();
  34. if ($type_id=='1') {
  35. $services = PersonalServiceStick::all();
  36. $header = '简历置顶';
  37. } else {
  38. $services = PersonalServiceTag::all();
  39. $header = '醒目标签';
  40. }
  41. $headers = ['Id', 'Email', 'Name', 'Company'];
  42. $rows = [
  43. [1, 'labore21@yahoo.com', 'Ms. Clotilde Gibson', 'Goodwin-Watsica'],
  44. [2, 'omnis.in@hotmail.com', 'Allie Kuhic', 'Murphy, Koepp and Morar'],
  45. [3, 'quia65@hotmail.com', 'Prof. Drew Heller', 'Kihn LLC'],
  46. [4, 'xet@yahoo.com', 'William Koss', 'Becker-Raynor'],
  47. [5, 'ipsa.aut@gmail.com', 'Ms. Antonietta Kozey Jr.'],
  48. ];
  49. $table = new Table($headers, $rows);
  50. $tab->add('置顶', '置顶')->render();
  51. $tab->add('醒目标签', $table)->render();
  52. //return $tab->render();
  53. //$tab->add('站内信', $this->grid()->setResource('/content/sysmessage/index')->render());
  54. //$tab->add('弹窗消息', $this->grid()->setResource('/content/explain/index')->render());
  55. return $content
  56. ->header($header)
  57. ->description(' ')
  58. ->body($tab);
  59. }
  60. /**
  61. * Show interface.
  62. *
  63. * @param mixed $id
  64. * @param Content $content
  65. * @return Content
  66. */
  67. public function show($id, Content $content)
  68. {
  69. return $content
  70. ->header('简历置顶')
  71. ->description(' ')
  72. ->body($this->detail($id));
  73. }
  74. /**
  75. * Edit interface.
  76. *
  77. * @param mixed $id
  78. * @param Content $content
  79. * @return Content
  80. */
  81. public function edit($id, Content $content)
  82. {
  83. return $content
  84. ->header('简历置顶')
  85. ->description(' ')
  86. ->body($this->editForm($id)->edit($id));
  87. }
  88. /**
  89. * Create interface.
  90. *
  91. * @param Content $content
  92. * @return Content
  93. */
  94. public function create(Content $content)
  95. {
  96. return $content
  97. ->header('简历置顶')
  98. ->description('添加简历置顶推广')
  99. ->body($this->form());
  100. }
  101. /**
  102. * Make a grid builder.
  103. *
  104. * @return Grid
  105. */
  106. protected function grid()
  107. {
  108. $grid = new Grid(new PersonalServiceStick);
  109. $grid->model()->orderBy('list_order', 'desc');
  110. $grid->id('ID');
  111. $grid->days('服务名称')->display(function () {
  112. return '置顶 '.$this->days.' 天';
  113. })->width(150);
  114. $grid->column('类型')->display(function () {
  115. return '置顶';
  116. });
  117. $grid->points('服务价')->display(function () {
  118. return $this->points.'积分';
  119. })->width(200);
  120. $grid->list_order('排序')->width(200);
  121. $grid->created_at('添加时间');
  122. $grid->updated_at('更新时间');
  123. if (Admin::user()->can('person_resume_stick_add')) {
  124. $grid->disableCreateButton(false);
  125. }
  126. $grid->actions(function ($actions) {
  127. if (Admin::user()->can('person_resume_stick_edit')) {
  128. $actions->disableEdit(false);
  129. }
  130. if (Admin::user()->can('person_resume_stick_delete')) {
  131. $actions->disableDelete(false);
  132. }
  133. });
  134. $grid->disableFilter();
  135. return $grid;
  136. }
  137. /**
  138. * Make a show builder.
  139. *
  140. * @param mixed $id
  141. * @return Show
  142. */
  143. protected function detail($id)
  144. {
  145. $show = new Show(PersonalServiceStick::findOrFail($id));
  146. $show->id('ID');
  147. $show->days('置顶时间')->as(function ($days) {
  148. return $days.'天';
  149. });
  150. $show->points('所需积分')->as(function ($points) {
  151. return $points.'点';
  152. });
  153. $show->list_order('排序');
  154. $show->created_at('添加时间');
  155. $show->updated_at('更新时间');
  156. return $show;
  157. }
  158. protected function editForm($id)
  159. {
  160. $form = new Form(new PersonalServiceStick);
  161. $form->text('days', '置顶时间')
  162. ->rules(
  163. [
  164. 'required',
  165. Rule::unique('personal_service_sticks')->ignore($id),
  166. ],
  167. [
  168. 'required' => '置顶时间不能为空',
  169. 'unique' => '置顶时间已存在',
  170. ]
  171. )
  172. ->setWidth(2)->setMustMark()
  173. ->append('天')
  174. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"));
  175. $form->text('points', '所需积分')
  176. ->rules('required', array('required'=>'所需积分不能为空。'))
  177. ->setWidth(2)->setMustMark()
  178. ->append('点')
  179. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"));
  180. $form->number('list_order', '排序')->default(0)->min(0)
  181. ->rules('required|numeric', array('required'=>'排序不能为空。','numeric'=>'排序只能填写数字。'))
  182. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"))
  183. ->help('(数字越大越靠前)');
  184. return $form;
  185. }
  186. public function update($id)
  187. {
  188. return $this->editForm($id)->update($id);
  189. }
  190. /**
  191. * Make a form builder.
  192. *
  193. * @return Form
  194. */
  195. protected function form()
  196. {
  197. $form = new Form(new PersonalServiceStick);
  198. $form->text('days', '置顶时间')
  199. ->rules(
  200. [
  201. 'required',
  202. Rule::unique('personal_service_sticks')->where(function ($query){
  203. $query->where('deleted_at',null);
  204. }),
  205. ],
  206. [
  207. 'required' => '置顶时间不能为空',
  208. 'unique' => '置顶时间已存在',
  209. ]
  210. )
  211. ->setWidth(2)->setMustMark()
  212. ->append('天')
  213. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"));
  214. $form->text('points', '所需积分')
  215. ->rules('required', array('required'=>'所需积分不能为空。'))
  216. ->setWidth(2)->setMustMark()
  217. ->append('点')
  218. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"));
  219. $form->number('list_order', '排序')->default(0)->min(0)
  220. ->rules('required|numeric', array('required'=>'排序不能为空。','numeric'=>'排序只能填写数字。'))
  221. ->attribute(array('maxlength'=>'10','onkeyup'=>'if(event.keyCode !=37 && event.keyCode != 39) value=value.replace(/\D/g,\'\');','onbeforepaste'=>"clipboardData.setData('text',clipboardData.getData('text').replace(/\D/g,''))"))
  222. ->help('(数字越大越靠前)');
  223. return $form;
  224. }
  225. }