12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Imports;
- use App\Repositories\Enums\ModelStatusEnum;
- use App\Repositories\Models\TCM\Drug;
- use App\Repositories\Models\TCM\Prescription;
- use Maatwebsite\Excel\Concerns\OnEachRow;
- use Maatwebsite\Excel\Row;
- use Overtrue\LaravelPinyin\Facades\Pinyin;
- class DrugsImport implements OnEachRow
- {
- public function onRow(Row $row)
- {
- if ($row->getIndex() <= 2) return false;
- if (empty($row[1])) return false;
- $type = Prescription::DRUG_TYPE_YP;
- switch ($row[2]) {
- case '颗粒':
- $type = Prescription::DRUG_TYPE_KL;
- break;
- }
- $letter = Pinyin::abbr($row[1]);
- $initial = substr($letter, 1);
- $data = [
- 'name' => $row[1],
- 'type' => $type,
- 'area' => $row[3],
- 'unit' => $row[4],
- 'letter' => $letter,
- 'initial' => $initial,
- 'admin_id' => login_admin_id(),
- 'status' => ModelStatusEnum::OK,
- ];
- if (Drug::query()->where('name', $row[1])->exists()) return false;
- Drug::create($data);
- return true;
- }
- }
|