1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- <?php
- namespace App\Admin\Actions\Post;
- use App\Model\TextLabel;
- use App\Model\XyZskDisease;
- use Encore\Admin\Actions\Action;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Storage;
- use PHPExcel_IOFactory;
- class ImportExcel extends Action
- {
- protected $selector = '.import-excel';
- public function handle(Request $request)
- {
- $oFile = $request->file('file');
- if(!$oFile){
- return $this->error('请选择上传文件');
- }
- Storage::disk('local')->put('text.csv',file_get_contents($oFile));
- $url = storage_path().'/app/text.csv';
- $file = fopen($url, 'r');
- if(!$file)
- {
- return $this->error('文件打开错误');
- }
- while ($data = fgetcsv($file)) { //每次读取CSV里面的一行内容
- array_walk($data, function(&$item){
- $item = mb_convert_encoding($item, "UTF-8", "GBK");
- });
- $list[] = $data;
- }
- fclose($file);
- foreach ($list as $k=>$v) {
- if($k == 0) continue;
- $data = [
- 'department_1' => $v[0],
- 'department_2' => $v[1],
- 'name' => $v[2],
- 'alias' => $v[3],
- 'clinicalFeature' => $v[4],
- 'diagnosis' => $v[5],
- 'treatment' => $v[6],
- 'regularMedication' => $v[7],
- 'pathogenesis' => $v[8],
- 'inspection' => $v[9],
- 'relevantOperation' => $v[10],
- 'laboratoryInspection' => $v[11],
- 'icd' => $v[12],
- 'etiology' => $v[13],
- 'auxiliaryExamination' => $v[14],
- 'antidiastole' => $v[15],
- 'prognosis' => $v[16],
- 'complicationsOverview' => $v[17],
- 'epidemiology' => $v[18],
- 'precaution' => $v[19],
- 'symptom' => $v[20],
- 'examination' => $v[21]
- ];
- XyZskDisease::query()->insert($data);
- }
- return $this->response()->success('Success message...')->refresh();
- }
- public function form()
- {
- $this->file('file', '请选择文件');
- }
- public function html()
- {
- return <<<HTML
- <a class="btn btn-sm btn-default import-excel">导入EXCEL</a>
- HTML;
- }
- }
|