海南旅游SAAS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.3 KiB

  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Repositories\WaterfallAd;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class WaterfallAdController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new WaterfallAd(), function (Grid $grid) {
  19. $grid->disableFilterButton();
  20. $grid->model()->where('agent_id', Admin::user()->id);
  21. $grid->column('id')->sortable();
  22. $grid->column('picture');
  23. $grid->column('agent_product_id');
  24. $grid->column('created_at');
  25. $grid->column('updated_at')->sortable();
  26. $grid->filter(function (Grid\Filter $filter) {
  27. $filter->panel();
  28. $filter->equal('id');
  29. });
  30. });
  31. }
  32. /**
  33. * Make a show builder.
  34. *
  35. * @param mixed $id
  36. *
  37. * @return Show
  38. */
  39. protected function detail($id)
  40. {
  41. return Show::make($id, new WaterfallAd(), function (Show $show) {
  42. //不允许查看非自己的数据
  43. if ($show->model()->agent_id != Admin::user()->id) {
  44. Admin::exit('数据不存在');
  45. }
  46. $show->field('id');
  47. $show->field('picture');
  48. $show->field('agent_product_id');
  49. $show->field('created_at');
  50. $show->field('updated_at');
  51. });
  52. }
  53. /**
  54. * Make a form builder.
  55. *
  56. * @return Form
  57. */
  58. protected function form()
  59. {
  60. return Form::make(new WaterfallAd(), function (Form $form) {
  61. //不允许查看非自己的数据
  62. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  63. return $form->response()->error('数据不存在');
  64. }
  65. $form->display('id');
  66. $form->text('picture');
  67. $form->text('agent_product_id');
  68. })->saving(function (Form $form) {
  69. //不允许修改非自己的数据
  70. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  71. return $form->response()->error('数据不存在');
  72. }
  73. })->deleting(function (Form $form) {
  74. //不允许删除非自己的数据
  75. if ($form->model()[0]['agent_id'] != Admin::user()->id) {
  76. return $form->response()->error('数据不存在');
  77. }
  78. });
  79. }
  80. }