<?php

namespace App\Admin\Controllers\ServicePacksManagment;

use App\Models\Team;
use App\Models\Order;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Grid;

class OpenPackController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '开通记录';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Order());
        $grid->disableActions();
        $grid->model()->where('product_type','6')->orderBy('id','desc');
        $grid->column('id', __('订单ID'));
        $grid->column('user_id', __('用户ID'));
        $grid->column('user.nickname','用户姓名');
        $grid->column('orderPatient.name', __('患者名称'));
        $grid->column('orderPack.service_pack_id', __('服务包ID'));
        $grid->column('orderPack.pack_name', __('服务包名称'));
        $grid->column('orderPack.pack_price', __('服务包价格'));
        $grid->column('orderPack.team_id', __('所属团队'))->display(function ($model){
            $name = Team::where('id',$model)->value('name');
            return $name;
        });
        $grid->column('created_at', __('创建时间'));

        return $grid;
    }
}
