<?php

namespace App\Imports\Docter;

use App\Models\Office;
use App\Models\Organization;
use App\Models\Qualification;
use Maatwebsite\Excel\Concerns\ToModel;
use phpDocumentor\Reflection\Types\Nullable;

class OrganizationOffice implements ToModel
{
    /**
    * @param array $row
    *
    * @return \Illuminate\Database\Eloquent\Model|null
    */
    public function model(array $row)
    {
        //跳过首行
        if (($row[0] == "姓名")) {
            return null;
        }
        $org_id = null;
        $office_id = null;
        //所属医院
        if ($row[3])
        {
            $org_id = Organization::firstOrCreate([
                'name' => $row[3]
            ],[
                'name' => $row[3],
                'type' => 1,
                'level' => 0,
                'introduce' => '',
                'phone' => '',
                'address' => '',
                'latitude' => 0,
                'longitude' => 0,
            ]);
        }
        //所属科室
        if ($row[4]&&$org_id)
        {
            $office_id = Office::firstOrCreate([
                'org_id' => $org_id['id'],
                'name' => $row[4]
            ]);
        }
        if ($row[5]==null)
        {
            $row[5] ='其它';
        }else{
            Qualification::firstOrCreate([
                'name' => $row[5]
            ]);
        }
    }
}
