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

105 lines
3.0 KiB

5 months ago
5 months ago
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. use Illuminate\Support\Str;
  10. class MchAppController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. return Grid::make(new MchApp(), function (Grid $grid) {
  20. $grid->model()->orderBy('id', 'desc');
  21. $grid->column('id')->sortable();
  22. $grid->column('mch_no');
  23. $grid->column('app_id');
  24. $grid->column('alipay_account');
  25. $grid->column('company_name');
  26. $grid->column('account_book_id');
  27. $grid->column('created_at');
  28. $grid->column('updated_at')->sortable();
  29. $grid->enableDialogCreate();
  30. $grid->showQuickEditButton();
  31. $grid->disableEditButton();
  32. $grid->filter(function (Grid\Filter $filter) {
  33. $filter->equal('mch_no')->width(3)->select(Merchant::getAllMerchant());
  34. $filter->equal('app_id')->width(3);
  35. $filter->equal('alipay_account')->width(3);
  36. $filter->like('company_name')->width(3);
  37. $filter->equal('account_book_id')->width(3);
  38. });
  39. });
  40. }
  41. /**
  42. * Make a show builder.
  43. *
  44. * @param mixed $id
  45. *
  46. * @return Show
  47. */
  48. protected function detail($id)
  49. {
  50. return Show::make($id, new MchApp(), function (Show $show) {
  51. $show->field('id');
  52. $show->field('mch_no');
  53. $show->field('app_id');
  54. $show->field('secret_key');
  55. $show->field('alipay_account');
  56. $show->field('company_name');
  57. $show->field('account_book_id');
  58. $show->field('created_at');
  59. $show->field('updated_at');
  60. });
  61. }
  62. /**
  63. * Make a form builder.
  64. *
  65. * @return Form
  66. */
  67. protected function form()
  68. {
  69. return Form::make(new MchApp(), function (Form $form) {
  70. $form->display('id');
  71. if ($form->isCreating()) {
  72. $form->select('mch_no')
  73. ->options(Merchant::getAllMerchant())
  74. ->required();
  75. $form->hidden('app_id');
  76. $form->hidden('secret_key');
  77. } else {
  78. $form->display('mch_no');
  79. $form->display('app_id');
  80. }
  81. $form->text('alipay_account')->required();
  82. $form->text('company_name')->required();
  83. $form->display('created_at');
  84. $form->display('updated_at');
  85. $form->saving(function (Form $form) {
  86. if ($form->isCreating()) {
  87. $form->app_id = uniqid().substr(md5(time()), 0, 11);
  88. $form->secret_key = Str::random(128);
  89. }
  90. });
  91. });
  92. }
  93. }