WithdrawController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\User;
  4. use App\Models\Withdraw;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class WithdrawController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Withdraw(), function (Grid $grid) {
  19. $grid->model()->with('userData')->orderByDesc('id');
  20. $grid->column('id')->sortable();
  21. $grid->column('userData.name', '昵称')->sortable();
  22. $grid->column('userData.avatar', '昵称')->image('', 40, 40);
  23. $grid->column('userData.mobile', '手机号')->sortable();
  24. $grid->column('type')->using(Withdraw::$label)
  25. ->dot(
  26. [
  27. 2 => 'primary',
  28. 1 => 'success',
  29. 3 => 'danger',
  30. ],
  31. 'danger' // 第二个参数为默认值
  32. );
  33. $grid->column('bank_name');
  34. $grid->column('name');
  35. $grid->column('number');
  36. $grid->column('state')->using(Withdraw::$state)
  37. ->dot(
  38. [
  39. 0 => 'primary',
  40. 1 => 'success',
  41. 2 => 'danger',
  42. ],
  43. 'danger' // 第二个参数为默认值
  44. );
  45. // $grid->column('user_id');
  46. $grid->column('amount');
  47. $grid->column('procedure');
  48. $grid->column('practical_amount');
  49. $grid->column('not_desc');
  50. $grid->column('created_at');
  51. $grid->column('updated_at')->sortable();
  52. $grid->disableDeleteButton();
  53. $grid->disableCreateButton();
  54. $grid->disableViewButton();
  55. $grid->filter(function (Grid\Filter $filter) {
  56. $filter->panel();
  57. $filter->equal('state')->select(Withdraw::$state);
  58. $filter->between('created_at')->datetime();
  59. });
  60. });
  61. }
  62. /**
  63. * Make a show builder.
  64. *
  65. * @return Show
  66. */
  67. protected function detail($id)
  68. {
  69. return Show::make($id, new Withdraw(), function (Show $show) {
  70. $show->field('id');
  71. $show->field('type');
  72. $show->field('bank_name');
  73. $show->field('name');
  74. $show->field('number');
  75. $show->field('state');
  76. $show->field('user_id');
  77. $show->field('amount');
  78. $show->field('procedure');
  79. $show->field('practical_amount');
  80. $show->field('not_desc');
  81. $show->field('created_at');
  82. $show->field('updated_at');
  83. });
  84. }
  85. /**
  86. * Make a form builder.
  87. *
  88. * @return Form
  89. */
  90. protected function form()
  91. {
  92. return Form::make(new Withdraw(), function (Form $form) {
  93. $state = Withdraw::$state;
  94. // unset($state[0]);
  95. $form->display('id');
  96. $form->hidden('user_id');
  97. // $form->select('type')->options(Withdraw::$label)->disable();
  98. $form->select('state')
  99. ->when(2, function (Form $form) {
  100. $form->textarea('not_desc');
  101. })
  102. ->options($state)->saving(function ($item) use(&$form){
  103. if ($item == 2){
  104. User::query()->where('id',$form->model()->user_id)->increment('income',$form->model()->amount * 100);
  105. }
  106. });
  107. $form->display('amount');
  108. $form->display('procedure');
  109. $form->display('practical_amount');
  110. $form->display('created_at');
  111. $form->display('updated_at');
  112. });
  113. }
  114. }