<?php

namespace App\Admin\Controllers;

use App\Models\Docter;
use App\Models\Order;
use App\Models\DocterTimes;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class PhoneServiceController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '电话订单数';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Docter());

        $grid->column('id','ID');
        $grid->column('name','医生姓名');
        $grid->column('phone_price','咨询价格');
        $grid->column('step_price','步进价格')->display(function (){
            $step = DocterTimes::where(['docter_id'=>$this->id])->value('step_price');
            return $step;
        });


        $grid->column('orders','总订单数')->display(function (){

            $order_type = Order::where(['docter_id'=>$this->id,'product_type'=>1])->count();
            return $order_type;
        });
        $grid->column('orders_actions','进行中数')->display(function (){
            $action = Order::where(['docter_id'=>$this->id,'product_type'=>1,'order_status'=>3])->count();
            return $action;
        });
        $grid->column('orders_inishs','完成数')->display(function (){
            $finish = Order::where(['docter_id'=>$this->id,'product_type'=>1,'order_status'=>4])->count();
            return $finish;
        });
        $grid->column('orders_anomaly','异常数')->display(function (){
            $anomaly = Order::where(['docter_id'=>$this->id,'product_type'=>1])->whereIn('order_status',[1,2,5])->count();
//            dd($anomaly);
            return $anomaly;
        });

        return $grid;
    }

}
