123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\User;
- use App\Models\Withdraw;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class WithdrawController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new Withdraw(), function (Grid $grid) {
- $grid->model()->with('userData')->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('userData.name', '昵称')->sortable();
- $grid->column('userData.avatar', '昵称')->image('', 40, 40);
- $grid->column('userData.mobile', '手机号')->sortable();
- $grid->column('type')->using(Withdraw::$label)
- ->dot(
- [
- 2 => 'primary',
- 1 => 'success',
- 3 => 'danger',
- ],
- 'danger' // 第二个参数为默认值
- );
- $grid->column('bank_name');
- $grid->column('name');
- $grid->column('number');
- $grid->column('state')->using(Withdraw::$state)
- ->dot(
- [
- 0 => 'primary',
- 1 => 'success',
- 2 => 'danger',
- ],
- 'danger' // 第二个参数为默认值
- );
- // $grid->column('user_id');
- $grid->column('amount');
- $grid->column('procedure');
- $grid->column('practical_amount');
- $grid->column('not_desc');
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- $grid->disableDeleteButton();
- $grid->disableCreateButton();
- $grid->disableViewButton();
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->equal('state')->select(Withdraw::$state);
- $filter->between('created_at')->datetime();
- });
- });
- }
- /**
- * Make a show builder.
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new Withdraw(), function (Show $show) {
- $show->field('id');
- $show->field('type');
- $show->field('bank_name');
- $show->field('name');
- $show->field('number');
- $show->field('state');
- $show->field('user_id');
- $show->field('amount');
- $show->field('procedure');
- $show->field('practical_amount');
- $show->field('not_desc');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new Withdraw(), function (Form $form) {
- $state = Withdraw::$state;
- // unset($state[0]);
- $form->display('id');
- $form->hidden('user_id');
- // $form->select('type')->options(Withdraw::$label)->disable();
- $form->select('state')
- ->when(2, function (Form $form) {
- $form->textarea('not_desc');
- })
- ->options($state)->saving(function ($item) use(&$form){
- if ($item == 2){
- User::query()->where('id',$form->model()->user_id)->increment('income',$form->model()->amount * 100);
- }
- });
- $form->display('amount');
- $form->display('procedure');
- $form->display('practical_amount');
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|