<?php

namespace App\Admin\Controllers;

use App\Models\UserVip;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class UserVipController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new UserVip(), function (Grid $grid) {
            $grid->model()->where('is_share',1)->where('status',1)
                ->orderBy('id','desc');
            $grid->column('id')->sortable()->width('80px');
            $grid->column('order_id');
            $grid->column('order_fee','订单金额');
            $grid->column('user_id','用户昵称')->display(function () {
                return $this->user->nickname;
            });
            $grid->column('user_id','用户电话')->display(function () {
                return $this->user->phone_num;
            });
            $grid->column('parent_id','上级用户')->display(function () {
                return $this->parent->nickname;
            });
            $grid->column('status','支付状态')
                ->using([0 => '未支付', 1 => '已支付'])->dot([
                0 => 'danger',
                1 => 'success'
            ]);
            $grid->column('pay_at','支付时间');
            $grid->column('created_at');

            $grid->disableViewButton();
            $grid->disableEditButton();
            $grid->disableCreateButton();
            $grid->disableRowSelector();
            $grid->disableDeleteButton();
            $grid->disableActions();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('order','订单ID');
                $filter->like('user.nickname','用户昵称');
                $filter->equal('user.phone_num','用户手机');
                $filter->like('parent.nickname','上级用户');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new UserVip(), function (Show $show) {
            $show->field('id');
            $show->field('order_id');
            $show->field('user_id');
            $show->field('prepay_id');
            $show->field('serial_number');
            $show->field('order_fee');
            $show->field('is_share');
            $show->field('parent_id');
            $show->field('status');
            $show->field('pay_at');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new UserVip(), function (Form $form) {
            $form->display('id');
            $form->text('order_id');
            $form->text('user_id');
            $form->text('prepay_id');
            $form->text('serial_number');
            $form->text('order_fee');
            $form->text('is_share');
            $form->text('parent_id');
            $form->text('status');
            $form->text('pay_at');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
