|
@@ -16,51 +16,55 @@ class ImportExcel extends Action
|
|
|
{
|
|
|
$oFile = $request->file('file');
|
|
|
if(!$oFile){
|
|
|
- return $this->error('请选择上传文件');
|
|
|
+ return $this->response()->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);
|
|
|
+ try {
|
|
|
+ Storage::disk('local')->put('text.csv', file_get_contents($oFile));
|
|
|
+ $url = storage_path() . '/app/text.csv';
|
|
|
+
|
|
|
+ $file = fopen($url, 'r');
|
|
|
+ if (!$file) {
|
|
|
+ return $this->response()->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);
|
|
|
+ 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()->updateOrInsert(['name' => $v[2]], $data);
|
|
|
+ }
|
|
|
+ }catch (\Exception $e){
|
|
|
+ $this->response()->error('上传失败,确认文件格式或类型!!');
|
|
|
}
|
|
|
|
|
|
return $this->response()->success('Success message...')->refresh();
|