123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace App\Admin\Controllers;
- use App\Models\Order;
- use Dcat\Admin\Form;
- use Dcat\Admin\Grid;
- use Dcat\Admin\Show;
- use Dcat\Admin\Http\Controllers\AdminController;
- class OrderController extends AdminController
- {
- /**
- * Make a grid builder.
- *
- * @return Grid
- */
- protected function grid()
- {
- return Grid::make(new Order(), function (Grid $grid) {
- $grid->model()->with(['userData', 'orderData'])->orderByDesc('id');
- $grid->column('id')->sortable();
- $grid->column('userData.name', '昵称');
- $grid->column('userData.mobile', '手机号');
- $grid->column('orderData.title', '商品名称');
- $grid->column('state')->using([0 => '待支付', 1 => '已支付', 2 => '支付失败'])
- ->dot(
- [
- 0 => 'danger',
- 1 => 'success',
- 2 => 'primary',
- ],
- 'danger' // 第二个参数为默认值
- );
- $grid->column('order');
- $grid->column('wx_order');
- $grid->column('amount');
- $grid->column('diamond');
- $grid->column('pay_at', '支付时间');
- $grid->column('created_at');
- $grid->column('updated_at')->sortable();
- $grid->quickSearch(['order', 'wx_order'])->placeholder('搜索...');
- $grid->filter(function (Grid\Filter $filter) {
- $filter->panel();
- $filter->between('created_at')->datetime();
- $filter->equal('state')->select([0 => '待支付', 1 => '已支付', 2 => '支付失败']);
- $filter->where('mobile', function ($query) {
- $query->whereHas('userData', function ($query) {
- $query->where('mobile', 'like', "%{$this->input}%");
- });
- }, '用户手机号');
- });
- $grid->disableViewButton();
- $grid->disableCreateButton();
- $grid->disableEditButton();
- $grid->disableDeleteButton();
- });
- }
- /**
- * Make a show builder.
- *
- * @return Show
- */
- protected function detail($id)
- {
- return Show::make($id, new Order(), function (Show $show) {
- $show->field('id');
- $show->field('user_id');
- $show->field('state');
- $show->field('order');
- $show->field('wx_order');
- $show->field('amount');
- $show->field('diamond');
- $show->field('pay_at');
- $show->field('pay');
- $show->field('isPost');
- $show->field('config_id');
- $show->field('created_at');
- $show->field('updated_at');
- });
- }
- /**
- * Make a form builder.
- *
- * @return Form
- */
- protected function form()
- {
- return Form::make(new Order(), function (Form $form) {
- $form->display('id');
- $form->text('user_id');
- $form->text('state');
- $form->text('order');
- $form->text('wx_order');
- $form->text('amount');
- $form->text('diamond');
- $form->text('pay_at');
- $form->text('pay');
- $form->text('isPost');
- $form->text('config_id');
- $form->display('created_at');
- $form->display('updated_at');
- });
- }
- }
|