支付宝记账本
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.

96 lines
2.5 KiB

5 months ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\MchApp;
  4. use App\Models\Merchant;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class MerchantController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Merchant(), function (Grid $grid) {
  19. $grid->model()->orderBy('id', 'desc');
  20. $grid->column('id')->sortable();
  21. $grid->column('mch_no')->width('20%');
  22. $grid->column('mch_name')->width('28%');
  23. $grid->column('created_at');
  24. $grid->column('updated_at')->sortable();
  25. $grid->enableDialogCreate();
  26. $grid->showQuickEditButton();
  27. $grid->disableEditButton();
  28. $grid->filter(function (Grid\Filter $filter) {
  29. $filter->equal('mch_no')->width(3);
  30. $filter->like('mch_name')->width(3);
  31. });
  32. });
  33. }
  34. /**
  35. * Make a show builder.
  36. *
  37. * @param mixed $id
  38. *
  39. * @return Show
  40. */
  41. protected function detail($id)
  42. {
  43. return Show::make($id, new Merchant(), function (Show $show) {
  44. $show->field('id');
  45. $show->field('mch_no');
  46. $show->field('mch_name');
  47. $show->field('created_at');
  48. $show->field('updated_at');
  49. });
  50. }
  51. /**
  52. * Make a form builder.
  53. *
  54. * @return Form
  55. */
  56. protected function form()
  57. {
  58. return Form::make(new Merchant(), function (Form $form) {
  59. $form->display('id');
  60. if ($form->isCreating()) {
  61. $form->hidden('mch_no');
  62. } else {
  63. $form->display('mch_no');
  64. }
  65. $form->text('mch_name')->required();
  66. $form->display('created_at');
  67. $form->display('updated_at');
  68. $form->saving(function (Form $form) {
  69. if ($form->isCreating()) {
  70. $form->mch_no = 'M'.time();
  71. }
  72. });
  73. $form->deleting(function (Form $form) {
  74. $data = $form->model()->toArray();
  75. foreach ($data as $k => $v) {
  76. if (MchApp::where('mch_no', $v['mch_no'])->count() > 0) {
  77. return $form->response()->error("商户号{$v['mch_no']}已创建应用,请先删除应用");
  78. }
  79. }
  80. });
  81. });
  82. }
  83. }