<?php

namespace App\Admin\Actions\backstage;

use App\Models\Docter;
use App\Models\DocterOrganization;
use App\Models\Serviceapplys;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;

class Pass extends RowAction
{
    public $name = '通过';

    public function handle(Model $model)
    {
//         $model ...
//        dd($model);
        $end_time = strtotime('+1year');
        $authentication_end_time = date('Y-m-d H:i:s',$end_time);
        DocterOrganization::where('id',$model->id)->update(['state'=>1,
                                                            'authentication_time'=>date('Y-m-d H:i:s'),
                                                            'authentication_end_time'=>$authentication_end_time]
                                                            );
        Docter::where('id',$model->docter_id)->update(['is_then'=>1,'office_id'=>$model->offices_id,'qualification_id'=>$model->qualifications_id]);
        //生成默认的图文、电话、门诊的记录
        $service_type_arr = [1,2,3];
        foreach ($service_type_arr as $value)
        {
            $total_arr = [
                'docter_id' => $model->docter_id,
                'service_type' => $value,
                'status' => 3,
                'created_at' =>date('Y-m-d H;i;s'),
                'updated_at' =>date('Y-m-d H;i;s'),
            ];
//            dd($total_arr);
            Serviceapplys::insert($total_arr);
        }
        return $this->response()->success('审核通过')->refresh();
    }

}